GeoDataFrame.to_file() raises ValueError: Invalid field type <class 'numpy.int64'>
See original GitHub issueHi,
this is a problem I mentioned on the gis ML without answer so far: http://lists.gispython.org/pipermail/community/2015-April/003382.html
Here again the mwe. The shapefile contains only one entity. If someone ever wants to try it out, the shapefile can be downloaded here:
import geopandas as gpd
ifile = 'Hintereisferner.shp'
gdf = gpd.GeoDataFrame.from_file(ifile)
for index, entity in gdf.iterrows():
# no problem here
gpd.GeoDataFrame(entity).T.to_file('test1.shp')
# This raises an error
entity = gdf.iloc[0]
gpd.GeoDataFrame(entity).T.to_file('test2.shp')
The error:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-1-1d31c9cdd3e2> in <module>()
7
8 entity = gdf.iloc[0]
----> 9 gpd.GeoDataFrame(entity).T.to_file('test2.shp')
/home/mowglie/.pyvirtualenvs/py3.3/lib/python3.3/site-packages/geopandas/geodataframe.py
in to_file(self, filename, driver, **kwargs)
303 schema=schema, **kwargs) as c:
304 for i, row in self.iterrows():
--> 305 c.write(feature(i, row))
306
307 def to_crs(self, crs=None, epsg=None, inplace=False):
/home/mowglie/.pyvirtualenvs/py3.3/lib/python3.3/site-packages/fiona/collection.py
in write(self, record)
323 def write(self, record):
324 """Stages a record for writing to disk."""
--> 325 self.writerecords([record])
326
327 def validate_record(self, record):
/home/mowglie/.pyvirtualenvs/py3.3/lib/python3.3/site-packages/fiona/collection.py
in writerecords(self, records)
317 if self.mode not in ('a', 'w'):
318 raise IOError("collection not open for writing")
--> 319 self.session.writerecs(records, self)
320 self._len = self.session.get_length()
321 self._bounds = self.session.get_extent()
/home/mowglie/.pyvirtualenvs/py3.3/lib/python3.3/site-packages/fiona/ogrext.cpython-33m.so
in fiona.ogrext.WritingSession.writerecs (fiona/ogrext.c:15333)()
/home/mowglie/.pyvirtualenvs/py3.3/lib/python3.3/site-packages/fiona/ogrext.cpython-33m.so
in fiona.ogrext.OGRFeatureBuilder.build (fiona/ogrext.c:5751)()
ValueError: Invalid field type <class 'numpy.int64'>
What’s striking me is that I don’t see any difference between the entity object and the object returned by iloc…
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
geodataframe.to_file Invalid field type <class 'bytes'>
There is a column in your geodataframe with an invalid dtype (data type). It looks like the dtype bytes cannot be handled by...
Read more >ValueError: Invalid field type <class 'shapely.geometry ...
GeoDataFrame and I have done some geoprocessing which may be causing errors at the output. Also, it gives an output but when I...
Read more >geopandas.GeoDataFrame.to_file
The OGR format driver used to write the vector file. If not specified, it attempts to infer it from the file extension. If...
Read more >khongvanminh0811/return-period-of-earthquakes-bengalbasin
Help on class GeoDataFrame in module geopandas.geodataframe: class ... Raises a ValueError if `column` is already contained in the DataFrame, ...
Read more >Source code for oggm.utils._workflow
"""Classes and functions used by the OGGM workflow""" # Builtins import ... PATHS['working_dir']: warnings.warn("Cannot log to file without a valid " "cfg.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

What is actually passed to fiona is the output of
GeoDataFrame.iterfeatures(https://github.com/geopandas/geopandas/blob/master/geopandas/io/file.py#L62).Using your example:
So the problem for fiona is that in the properties numpy scalars are passed instead of native python types.
Here is the fiona issue: https://github.com/Toblerity/Fiona/issues/365
Closing this now, and thanks again for the help @jorisvandenbossche