Mercurial > hg > ChinaGisRestApi
comparison RestDbInterface.py @ 37:b356b86773a1
Merge with falks stuff b915bce653725bd0690605119fc9b3123253e560
author | casties |
---|---|
date | Wed, 01 Sep 2010 18:47:06 +0200 |
parents | 55dbaea75e66 b915bce65372 |
children | f6d9a3caf986 |
comparison
equal
deleted
inserted
replaced
35:55dbaea75e66 | 37:b356b86773a1 |
---|---|
563 logging.debug("importexcel sqlinsert=%s data=%s"%(sqlInsert,data)) | 563 logging.debug("importexcel sqlinsert=%s data=%s"%(sqlInsert,data)) |
564 self.executeSQL(sqlInsert, data, hasResult=False) | 564 self.executeSQL(sqlInsert, data, hasResult=False) |
565 | 565 |
566 return cnt | 566 return cnt |
567 | 567 |
568 | |
568 # Methods for GoogleMaps creation | 569 # Methods for GoogleMaps creation |
569 def showGoogleMap(self,schema='chgis',table='mpdl',id=[],doc=None): | 570 def showGoogleMap(self,schema='chgis',table='mpdl',id=[],doc=None): |
570 logging.debug("showGoogleMap") | 571 logging.debug("showGoogleMap") |
571 data = self.getDataForGoogleMap(schema,table,id,doc) | 572 data = self.getDataForGoogleMap(schema,table,id,doc) |
573 kmlFileName=self.getKMLname(data=data,table=table) | |
574 initializeStringForGoogleMaps="""onload=\"initialize(\'http://chinagis.mpiwg-berlin.mpg.de/chinagis/REST/daten/"""+kmlFileName+"""\')\""""#+str(data) | |
575 initializeStringForGoogleMaps=initializeStringForGoogleMaps.replace("None","0") | |
576 googleMap_page=self.htmlHead()+str(self.getGoogleMapString(kml=initializeStringForGoogleMaps)) | |
577 return googleMap_page | |
578 | |
579 def getKmlUrl(self,schema='chgis',table='mpdl',id=[],doc=None): | |
580 logging.debug("getKmlUrl") | |
581 data = self.getDataForGoogleMap(schema,table,id,doc) | |
572 kml=self.getKMLname(data=data,table=table) | 582 kml=self.getKMLname(data=data,table=table) |
573 googleMap_page=self.htmlHead()+str(self.getGoogleMapString(kml=kml)) | 583 return """http://chinagis.mpiwg-berlin.mpg.de/chinagis/REST/daten/"""+kml |
574 return googleMap_page | |
575 | 584 |
576 def getDataForGoogleMap(self,schema='chgis',table='mpdl',id=[],doc=None): | 585 def getDataForGoogleMap(self,schema='chgis',table='mpdl',id=[],doc=None): |
577 logging.debug("getDataForGoogleMap") | 586 logging.debug("getDataForGoogleMap") |
578 qstr="SELECT * FROM "+schema+"."+table | 587 qstr="SELECT * FROM "+schema+"."+table |
579 try: | 588 try: |
654 kmlFileName="marker"+str(time.time())+".kml" | 663 kmlFileName="marker"+str(time.time())+".kml" |
655 | 664 |
656 # kml4Marker=str(kml4Marker).replace('&','$$') | 665 # kml4Marker=str(kml4Marker).replace('&','$$') |
657 # kml4Marker=str(kml4Marker).replace(';','__$$__') | 666 # kml4Marker=str(kml4Marker).replace(';','__$$__') |
658 # kml4Marker=str(kml4Marker).replace('#','__SHARP__') | 667 # kml4Marker=str(kml4Marker).replace('#','__SHARP__') |
659 initializeStringForGoogleMaps="""onload=\"initialize(\'http://chinagis.mpiwg-berlin.mpg.de/chinagis/REST/daten/"""+kmlFileName+"""\')\""""#+str(data) | |
660 initializeStringForGoogleMaps=initializeStringForGoogleMaps.replace("None","0") | |
661 isLoadReady='false' | 668 isLoadReady='false' |
662 while isLoadReady=='false': | 669 while isLoadReady=='false': |
663 isLoadReady=self.RESTwrite2File(self.daten,kmlFileName,kml4Marker) | 670 isLoadReady=self.RESTwrite2File(self.daten,kmlFileName,kml4Marker) |
664 | 671 |
665 return initializeStringForGoogleMaps | 672 return kmlFileName |
666 | 673 |
667 def getGoogleMapString(self,kml): | 674 def getGoogleMapString(self,kml): |
668 logging.debug("getGoogleMapString") | 675 logging.debug("getGoogleMapString") |
669 printed= '<body %s> '%kml +"""\n <div id="map_canvas" style="width: 98%; height: 95%"> </div> \n </body>" \n </html>""" | 676 printed= '<body %s> '%kml +"""\n <div id="map_canvas" style="width: 98%; height: 95%"> </div> \n </body>" \n </html>""" |
670 return printed | 677 return printed |
671 | 678 |
672 def getPoint4GISid(self,gis_id): | 679 def getPoint4GISid(self,gis_id): |
673 j=0 | 680 j=0 |
674 while (True): | 681 coords=(0,0) |
675 j=j+1 | 682 if gis_id != None: |
676 if (j>100): # FJK: just to prevent endless loops | 683 while (True): |
677 break | 684 j=j+1 |
678 if (gis_id.isdigit()): # FJK: regular exit from while-loop | 685 if (j>100): # FJK: just to prevent endless loops |
679 break | 686 break |
680 else: | 687 if (gis_id.isdigit()): # FJK: regular exit from while-loop |
681 gis_id=gis_id.strip('abcdefghijklmnopqrstuvwxyz_') # FJK: to strip all letters | 688 break |
682 gis_id=gis_id.strip() # FJK: to strip all whitespaces | 689 else: |
683 resultpoint = [0,0] | 690 gis_id=gis_id.strip('abcdefghijklmnopqrstuvwxyz_') # FJK: to strip all letters |
684 results = None | 691 gis_id=gis_id.strip() # FJK: to strip all whitespaces |
685 try: | 692 resultpoint = [0,0] |
693 results = None | |
694 try: | |
686 if int(gis_id)>0: | 695 if int(gis_id)>0: |
687 SQL="SELECT x_coord,y_coord FROM chgis.chgis_coords WHERE gis_id LIKE cast("+ str(gis_id) +" as text);" | 696 SQL="SELECT x_coord,y_coord FROM chgis.chgis_coords WHERE gis_id LIKE cast("+ str(gis_id) +" as text);" |
688 results=self.ZSQLSimpleSearch(SQL) | 697 results=self.ZSQLSimpleSearch(SQL) |
689 #print results | 698 #print results |
690 if results != None: | 699 if results != None: |
692 resultpoint=[getattr(result,str('x_coord')),getattr(result,str('y_coord'))] | 701 resultpoint=[getattr(result,str('x_coord')),getattr(result,str('y_coord'))] |
693 if resultpoint !=[0,0]: | 702 if resultpoint !=[0,0]: |
694 return resultpoint | 703 return resultpoint |
695 else: | 704 else: |
696 coords=self.getCoordsFromREST_gisID(joinid) | 705 coords=self.getCoordsFromREST_gisID(joinid) |
697 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;" | 706 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;" |
698 returnstring=self.ZSQLSimpleSearch(SQL) | 707 returnstring=self.ZSQLSimpleSearch(SQL) |
699 return coords[0] | 708 return coords[0] |
700 except: | 709 except: |
701 error="gis_id not to interpretable:"+str(gis_id) | 710 return "gis_id not to interpretable:"+str(gis_id) |
711 else: | |
712 return coords[0] | |
702 | 713 |
703 def getCoordsFromREST_gisID(self,gis_id): | 714 def getCoordsFromREST_gisID(self,gis_id): |
704 coordlist=[] | 715 coordlist=[] |
705 i=0 | 716 i=0 |
706 while (i<5 and coordlist==[]): | 717 while (i<5 and coordlist==[]): |
741 file4Read=open(name,'r') | 752 file4Read=open(name,'r') |
742 fileInZope=datadir.manage_addFile(id=fileid,file=file4Read) | 753 fileInZope=datadir.manage_addFile(id=fileid,file=file4Read) |
743 return "Write successful" | 754 return "Write successful" |
744 # except: | 755 # except: |
745 # return "Could not write" | 756 # return "Could not write" |
746 | 757 |
747 | 758 |
748 def manage_editRestDbInterface(self, title=None, connection_id=None, | 759 def manage_editRestDbInterface(self, title=None, connection_id=None, |
749 REQUEST=None): | 760 REQUEST=None): |
750 """Change the object""" | 761 """Change the object""" |
751 if title is not None: | 762 if title is not None: |