I wrote a script to query a PostGIS database, returning a Pandas dataframe like this:
ID ... WKT
0 1 ... LINESTRING(1.5047434 42.6319022,1.5053385 42.6...
1 2 ... LINESTRING(1.5206333 42.5291144,1.5206306 42.5...
Now I am trying to write this into a shapefile with GeoPandas, according to their documentation:
We use shapely.wkt sub-module to parse wkt format:
from shapely import wkt
df['Coordinates'] = geopandas.GeoSeries.from_wkt(df['Coordinates'])
But when I tried to do the same, I got:
AttributeError: type object 'GeoSeries' has no attribute 'from_wkt'
My GeoPandas:
geopandas 0.8.1 py_0 conda-forge
Use shapely.wkt.loads
to create the geometry column.
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With