我正在ipython Notebook中使用geopandas和shape进行小型工作流,有时从shapefile,有时从postgis(执行更昂贵的处理)中提取一堆地理空间数据。
现在,我使用将该postgis表拖入python中sqlalchemy
,并一路将几何体转换为WKT,得到如下结果:
sql = """
SELECT ST_AsText(ST_Transform(the_geom,4326)) as newgeom,*
FROM public.parcels2010_small limit 5;
"""
parcels = pd.read_sql(sql, engine)
parcels
+----+---------------------------------------------------+---------------------------------------------------+-----------+-------------+
| id | newgeom | the_geom | parcel_id | osm_node_id |
+----+---------------------------------------------------+---------------------------------------------------+-----------+-------------+
| 0 | MULTIPOLYGON(((-122.991093691444 38.4878691106... | 01060000209C0E00000100000001030000000100000097... | 1805792 | 66237 |
+----+---------------------------------------------------+---------------------------------------------------+-----------+-------------+
| 1 | MULTIPOLYGON(((-122.444576448624 37.7346386006... | 01060000209C0E0000010000000103000000010000008A... | 10435 | 123826 |
+----+---------------------------------------------------+---------------------------------------------------+-----------+-------------+
| 2 | MULTIPOLYGON(((-122.796785208193 38.5427593334... | 01060000209C0E0000010000000103000000010000007D... | 1817842 | 313047 |
+----+---------------------------------------------------+---------------------------------------------------+-----------+-------------+
| 3 | MULTIPOLYGON(((-122.695538506163 38.3618570798... | 01060000209C0E0000010000000103000000010000009B... | 1934612 | 63776 |
+----+---------------------------------------------------+---------------------------------------------------+-----------+-------------+
| 4 | MULTIPOLYGON(((-122.223424422869 37.8416019090... | 01060000209C0E00000100000001030000000100000072... | 861785 | 26369 |
+----+---------------------------------------------------+---------------------------------------------------+-----------+-------------+
从shapefile加载时,它看起来很像几何图形,但是它不会转换为形状良好的几何图形。我无法找到规范的方式来执行此操作,要么单独使用匀称,要么使用Descartes
。