我编写了一个脚本来查询PostGIS数据库,返回一个,如下所示:
ID ... WKT
0 1 ... LINESTRING(1.5047434 42.6319022,1.5053385 42.6...
1 2 ... LINESTRING(1.5206333 42.5291144,1.5206306 42.5...现在,我正尝试用GeoPandas将其写入一个shapefile中,根据他们的文档
我们使用shapely.wkt子模块来解析wkt格式。
from shapely import wkt
df['Coordinates'] = geopandas.GeoSeries.from_wkt(df['Coordinates'])但当我试图做同样的事时,我得到了:
AttributeError: type object 'GeoSeries' has no attribute 'from_wkt'我的GeoPandas:
geopandas 0.8.1 py_0 conda-forge发布于 2021-03-25 04:39:20
使用shapely.wkt.loads创建几何图形列。
import geopandas as gpd
from shapely import wkt
df['geometry'] = df.WKT.apply(wkt.loads)
df.drop('WKT', axis=1, inplace=True) #Drop WKT column
# Geopandas GeoDataFrame
gdf = gpd.GeoDataFrame(df, geometry='geometry')
#Export to shapefile
gdf.to_file('myshapefile.shp')发布于 2021-03-25 12:48:39
geopandas.GeoSeries.from_wkt已在GeoPandas 0.9.0中添加。它在旧版本中不存在,这就是为什么它在0.8.1中不能工作的原因。
https://stackoverflow.com/questions/66786737
复制相似问题