changeset 37:b356b86773a1

Merge with falks stuff b915bce653725bd0690605119fc9b3123253e560
author casties
date Wed, 01 Sep 2010 18:47:06 +0200
parents 55dbaea75e66 (current diff) b915bce65372 (diff)
children f6d9a3caf986
files RestDbInterface.py
diffstat 1 files changed, 32 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/RestDbInterface.py	Wed Sep 01 13:02:03 2010 +0200
+++ b/RestDbInterface.py	Wed Sep 01 18:47:06 2010 +0200
@@ -565,13 +565,22 @@
                       
         return cnt
     
+
     # Methods for GoogleMaps creation
     def showGoogleMap(self,schema='chgis',table='mpdl',id=[],doc=None):
         logging.debug("showGoogleMap")
         data = self.getDataForGoogleMap(schema,table,id,doc)
+        kmlFileName=self.getKMLname(data=data,table=table)
+        initializeStringForGoogleMaps="""onload=\"initialize(\'http://chinagis.mpiwg-berlin.mpg.de/chinagis/REST/daten/"""+kmlFileName+"""\')\""""#+str(data)
+        initializeStringForGoogleMaps=initializeStringForGoogleMaps.replace("None","0")
+        googleMap_page=self.htmlHead()+str(self.getGoogleMapString(kml=initializeStringForGoogleMaps))
+        return googleMap_page
+
+    def getKmlUrl(self,schema='chgis',table='mpdl',id=[],doc=None):
+        logging.debug("getKmlUrl")
+        data = self.getDataForGoogleMap(schema,table,id,doc)
         kml=self.getKMLname(data=data,table=table)
-        googleMap_page=self.htmlHead()+str(self.getGoogleMapString(kml=kml))
-        return googleMap_page
+        return """http://chinagis.mpiwg-berlin.mpg.de/chinagis/REST/daten/"""+kml
 
     def getDataForGoogleMap(self,schema='chgis',table='mpdl',id=[],doc=None):
         logging.debug("getDataForGoogleMap")
@@ -656,13 +665,11 @@
         #    kml4Marker=str(kml4Marker).replace('&','$$')
         #    kml4Marker=str(kml4Marker).replace(';','__$$__')
         #    kml4Marker=str(kml4Marker).replace('#','__SHARP__')
-            initializeStringForGoogleMaps="""onload=\"initialize(\'http://chinagis.mpiwg-berlin.mpg.de/chinagis/REST/daten/"""+kmlFileName+"""\')\""""#+str(data)
-            initializeStringForGoogleMaps=initializeStringForGoogleMaps.replace("None","0")
             isLoadReady='false'
             while isLoadReady=='false':
               isLoadReady=self.RESTwrite2File(self.daten,kmlFileName,kml4Marker)
 
-        return initializeStringForGoogleMaps
+        return kmlFileName
 
     def getGoogleMapString(self,kml):
         logging.debug("getGoogleMapString")
@@ -671,18 +678,20 @@
     
     def getPoint4GISid(self,gis_id):
         j=0
-        while (True):
-          j=j+1
-          if (j>100):                                         # FJK: just to prevent endless loops
-            break
-          if (gis_id.isdigit()):                              # FJK: regular exit from while-loop
-            break
-          else:
-           gis_id=gis_id.strip('abcdefghijklmnopqrstuvwxyz_') # FJK: to strip all letters 
-           gis_id=gis_id.strip()                              # FJK: to strip all whitespaces
-        resultpoint = [0,0]
-        results = None
-        try:
+        coords=(0,0)
+        if gis_id != None:
+         while (True):
+           j=j+1
+           if (j>100):                                         # FJK: just to prevent endless loops
+             break
+           if (gis_id.isdigit()):                              # FJK: regular exit from while-loop
+             break
+           else:
+             gis_id=gis_id.strip('abcdefghijklmnopqrstuvwxyz_') # FJK: to strip all letters 
+             gis_id=gis_id.strip()                              # FJK: to strip all whitespaces
+         resultpoint = [0,0]
+         results = None
+         try:
             if int(gis_id)>0:
                 SQL="SELECT x_coord,y_coord FROM chgis.chgis_coords WHERE gis_id LIKE cast("+ str(gis_id) +" as text);"
                 results=self.ZSQLSimpleSearch(SQL)
@@ -694,11 +703,13 @@
                     return resultpoint
             else:
                 coords=self.getCoordsFromREST_gisID(joinid)
-                SQL="INSERT INTO  chgis.chgis_coords (gis_id,x_coord,y_coord) VALUES (" +gis_id+ "," +coords[0][1]+ "," +coords[0][0]+ "); ANALYZE chgis.chgis_coords;"
+                SQL="INSERT INTO chgis.chgis_coords (gis_id,x_coord,y_coord) VALUES (" +gis_id+ "," +coords[0][1]+ "," +coords[0][0]+ "); ANALYZE chgis.chgis_coords;"
                 returnstring=self.ZSQLSimpleSearch(SQL)
                 return coords[0]
-        except:
-            error="gis_id not to interpretable:"+str(gis_id)
+         except:
+            return "gis_id not to interpretable:"+str(gis_id)
+        else:
+            return coords[0]
 
     def getCoordsFromREST_gisID(self,gis_id):
         coordlist=[]
@@ -743,7 +754,7 @@
             return "Write successful"
 #        except:
 #            return "Could not write"
-         
+
         
     def manage_editRestDbInterface(self, title=None, connection_id=None,
                      REQUEST=None):