2

I try to export an shp from Python using geopandas with this:

#Create a output path for the data
out = r"C:\Users\hhh\Desktop\ge.shp"

## Write those rows into a new Shapefile 
df.to_file(out)

and I get this error:

ValueError: Invalid field type <class 'shapely.geometry.polygon.Polygon'>

The type of the df is geopandas.geodataframe.GeoDataFrame and I have done some geoprocessing which may be causing errors at the output. Also, it gives an output but when I open it, it shows nothing and the attribute table is also empty.

I checked this with another case by taking a subset from an shp read in python:

out = r"C:\Users\hhh\Desktop\hid.shp"

selection = data[0:50]

selection.to_file(out)

and it worked.

What can be causing this problem in the first case?

  • Can you show the full traceback? And show a sample of the data? (eg data.head() and data.info()) (or ideally a reproducible example) – joris Jun 14 '18 at 13:40
  • But from the error message: do you have multiple columns with geometry data? Shapefiles can only handle a single geometry column. – joris Jun 14 '18 at 13:42
  • You are correct, I solved it like that but I hadn't inform – user122244 Jun 14 '18 at 13:56
  • @joris you could answer the question – BERA Jun 14 '18 at 16:15
2

Shapefiles have some limitations, including:

  • They cannot have multiple columns with geometry data
  • The geometries cannot contains multiple types (so eg both Points and LineStrings)

In both cases you will get errors when trying to write a GeoDataFrame to a shapefile.

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.