Mercurial > hg > ChinaGisRestApi
changeset 233:bdab16f83512
show line and polygon-layer
author | fknauft |
---|---|
date | Mon, 01 Aug 2011 21:35:27 +0200 |
parents | f930ce2583a0 |
children | 6e6e78adb447 |
files | RestDbGisApi.py zpt/KML_schema_table.zpt |
diffstat | 2 files changed, 47 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/RestDbGisApi.py Thu May 12 16:23:04 2011 +0200 +++ b/RestDbGisApi.py Mon Aug 01 21:35:27 2011 +0200 @@ -196,6 +196,11 @@ try: geomstr='select astext(st_simplify(transform(the_geom,4326),0.02)) from "%s"."%s"'%(schema,table) geomdata=self.executeSQL(geomstr) + teststr=geomdata.values()[1][0] + if (teststr == (u'MULTIPOLYGON EMPTY',)): + geomstr='select astext(st_simplify(transform(the_geom,2333),0.02)) from "%s"."%s"'%(schema,table) + geomdata=self.executeSQL(geomstr) + except: try: geomstr='select chgis.astext(chgis.st_simplify(chgis.transform(the_geom,4326),0.02)) from "%s"."%s"'%(schema,table) @@ -203,7 +208,7 @@ except: geomdata=None - if (gisIdField is None) and (latField is None or lonField is None): + if (gisIdField is None) and (latField is None or lonField is None) and geomField=='point': # no fields given - choose automagically sql = 'SELECT field_name FROM public.gis_table_meta_rows WHERE table_name = %s and gis_type = %s' # gis id in metadata first @@ -220,7 +225,7 @@ if len(res['rows']) > 0: lonField = res['rows'][0][0] - if (gisIdField is None) and (latField is None or lonField is None): + if (gisIdField is None) and (latField is None or lonField is None) and geomField=='point': logging.warning("no entry in metadata table for table %s" % table) # still no fields - try field names if 'latitude' in fieldMap and 'longitude' in fieldMap: @@ -244,8 +249,11 @@ # convert data kmlData = [] geom_list = {} - if geomField=='poly' and len(geomdata)>0: + try: + if geomField=='poly' or geomField=='line': geom_list=geomdata.values()[1] + except: + return "no geomdata in RestDbGisApi Line 254" data_list=data['rows'] for k in range (len(data_list)): dataset = data_list[k] @@ -257,7 +265,7 @@ # for dataset in data['rows']: xCoord = 0.0 yCoord = 0.0 - if gisIdIdx is not None: + if gisIdIdx is not None and geomField=='point' : gisID = dataset[gisIdIdx] coords=self.getPointForChGisId(gisID) if coords!=None: @@ -268,14 +276,14 @@ xCoord = dataset[lonIdx] yCoord = dataset[latIdx] - else: + elif geomField=='point' : logging.error("getKMLdata unable to find position") return None - if float(xCoord) == 0.0: + if geomField=='point' : + if float(xCoord) == 0.0: continue - - if float(yCoord) == 0.0: + if float(yCoord) == 0.0: continue kmlPlace = {} @@ -334,7 +342,7 @@ kmlPlace['coord_y'] = str(yCoord) kmlPlace['coord_z'] = '0' kmlData.append(kmlPlace) - if geomField=='poly' and len(geomdata)>0: + if (geomField=='poly' or geomField=='line') and len(geomdata)>0: polys=str(geom_value).split('(') aaa=len(polys) for poly in polys:
--- a/zpt/KML_schema_table.zpt Thu May 12 16:23:04 2011 +0200 +++ b/zpt/KML_schema_table.zpt Mon Aug 01 21:35:27 2011 +0200 @@ -9,7 +9,7 @@ <Document> <Style id="marker_icon_red"> <IconStyle> - <size>"10"</size> + <scale>"10"</scale> <Icon> <href>http://mappit.mpiwg-berlin.mpg.de/mappit/icons/dot_red.png</href> </Icon> @@ -18,7 +18,7 @@ </Style> <Style id="marker_icon_black"> <IconStyle> - <size>"0.2"</size> + <scale>"0.2"</scale> <Icon> <href>http://mappit.mpiwg-berlin.mpg.de/mappit/icons/dot_black.png</href> </Icon> @@ -54,7 +54,7 @@ </Style> <Style id="marker_icon_red_big"> <IconStyle> - <size>"10"</size> + <scale>"10"</scale> <Icon> <href>http://mappit.mpiwg-berlin.mpg.de/mappit/icons/dot_red_big.png</href> </Icon> @@ -63,7 +63,7 @@ </Style> <Style id="marker_icon_black_big"> <IconStyle> - <size>"0.2"</size> + <scale>"0.2"</scale> <Icon> <href>http://mappit.mpiwg-berlin.mpg.de/mappit/icons/dot_black_big.png</href> </Icon> @@ -106,6 +106,24 @@ <color>ff0000ff</color> </PolyStyle> </Style> + <Style id="blue_poly"> + <LineStyle> + <color>0000ffff</color> + <width>2</width> + </LineStyle> + <PolyStyle> + <color>0000ffff</color> + </PolyStyle> + </Style> + <Style id="black_poly"> + <LineStyle> + <color>000000ff</color> + <width>2</width> + </LineStyle> + <PolyStyle> + <color>000000ff</color> + </PolyStyle> + </Style> <Placemark tal:repeat="place data" tal:condition="python:here.trydatahas_key(data,0,'icon')"> <description tal:content="place/description" > ERD-0815: ERD-0815 @@ -119,9 +137,13 @@ <description tal:content="place/description" > ERD-0815: ERD-0815 </description> - <Style> <PolyStyle><color tal:content="place/LineColor">#80800000</color><fill>0.1</fill><outline>1</outline></PolyStyle></Style> - <Polygon><outerBoundaryIs><LinearRing><coordinates tal:content="string:${place/LinearRing}">116.38,39.92,0</coordinates> - </LinearRing></outerBoundaryIs></Polygon> +<!-- <styleUrl tal:content="place/icon" >#red_line</styleUrl> --> + <styleUrl >#red_line</styleUrl> + <LineString> + <extrude>1</extrude> + <tessellate>1</tessellate> + <coordinates tal:content="string:${place/LinearRing}">116.38,39.92,0</coordinates> + </LineString> </Placemark> <Placemark tal:condition="withLine"> <name>Path</name> @@ -136,5 +158,5 @@ </coordinates> </LineString> </Placemark> - </Document> + </Document> </kml>