Geopandas: gpd.to_file(): Z dimension not saved with ESRI driver

Created on 14 Nov 2017  路  6Comments  路  Source: geopandas/geopandas

Issue

The Z dimension of geometries is not preserved when using gpd.to_file() using the ESRI driver.

Example

import geopandas as gpd
from shapely.geometry import Point

point = Point(0, 0, 500)
gdf = gpd.GeoDataFrame(geometry=[point])
print(gdf)
          geometry
0  POINT Z (0 0 500)



md5-c8646c095092cb1a3ce47b0c1609ee3c



FID geometry
0 0 POINT (0 0)
```

Expected Behavior

I'd expect the Z dimension to be included.

bug

All 6 comments

@mattayes Thanks for the clear bug report! It looks like geopandas isn't correctly inferring a "3D Point" geometry schema. Are you interested in making a PR on this? If not, I can take a shot in the next week or two.

@jdmcbr I'm interested, though I'm not quite sure what needs to change right now. Do you have a good idea? I'm happy to start investigating.

To further investigate, could you open the written file with another program? Just to know whether the bug is in the writing of the file, or in the reading it afterwards? (or if you have an existing 3D shapefile, to try to read that)

@mattayes @jorisvandenbossche I'm sorry, I should have provided a little more detail in my previous message. In confirming this was a geopandas issue and not a fiona issue, I saw that this was occurring during a write. For a 3D point file written with fiona, geopandas correctly read it back in.

I suppose the error is in inferring the schema (https://github.com/geopandas/geopandas/blob/master/geopandas/io/file.py#L111), in that it needs special casing for 3D data.

If you manually specify the schema, it seems to work:

In [167]: point = Point(0, 0, 500)
     ...: gdf = gpd.GeoDataFrame({'a': [1]}, geometry=[point])

In [168]: gdf
   a           geometry
0  1  POINT Z (0 0 500)

In [170]: gpd.io.file.infer_schema(gdf)
Out[170]: {'geometry': 'Point', 'properties': OrderedDict([('a', 'int')])}

In [175]: schema = {'geometry': '3D Point', 'properties': {'a': 'int'}}

In [176]: gdf.to_file("__test3D.shp", schema=schema)

In [177]: gpd.read_file("__test3D.shp")
   a           geometry
0  1  POINT Z (0 0 500)

Although I don't fully understand how it works, as here (https://github.com/Toblerity/Fiona/issues/465) is stated that '3D Point' should now be an alias for 'Point'

Was this page helpful?
0 / 5 - 0 ratings