0

I got the following GeoDataFrame taken from a CSV file and after some slincing and CRS and geometry asignment

    ctf_nom         geometry                                    id      
0   Prunus mahaleb  POINT (429125.795043319 4579664.7564311)    2616    
1   Betula pendula  POINT (425079.292045901 4585098.09043407)   940     
2   Betula pendula  POINT (425088.115045896 4585093.66943407)   940     
3   Abelia triflora POINT (429116.661043325 4579685.93743111)   2002    
4   Abies alba      POINT (428219.962044021 4587346.66843531)   797  

I've converted the geometry from a str trough:

from shapely import wkt

df['geometry'] = df['geometry'].apply(wkt.loads)
df_geo = gpd.GeoDataFrame(df, geometry = 'geometry')

and asigned a crs by :

df_geo.crs = {'init' :'epsg:25831'}
df_geo.crs

when I'm trying to save again the reduced geodataframe by gdf.to_file() function it returns the following attribute error:

out = r'my_path\df_geo.geojson'
df_geo.to_file(out, driver = 'GeoJSON')

It's even the same when I try with shp extension...

AttributeError: 'Series' object has no attribute 'has_z'

How can I solve this?

1

Since it's a calculated geometry, you have to explicitly set it as geometry for the GeoDataFrame.

try using something like this -

geodf.set_geometry(col='geometry', inplace=True)
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.