question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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)
gdf.to_file('./foo')
# Try to read file back
gdf2 = gpd.read_file('./foo')
print(gdf2)
   FID     geometry
0    0  POINT (0 0)

Expected Behavior

I’d expect the Z dimension to be included.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jorisvandenbosschecommented, Nov 14, 2017

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’

1reaction
jorisvandenbosschecommented, Nov 14, 2017

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)
Read more comments on GitHub >

github_iconTop Results From Across the Web

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 >
python - GeoPandas to_file() saves GeoDataFrame without ...
I am able to construct GeoDataFrame by reading input datasets and operate the data yet saving an output dataset does not preserve the...
Read more >
ArcGIS (Desktop, Engine, Server)
NIM075668 - Cannot save stops to feature class when using 3D network dataset. NIM075690 - Import XML fails with "geometry cannot have Z...
Read more >
Vector layers (geopandas) - shapely - Michael Dorman
A GeoSeries , which holds the geometries in a special “geometry” column. Zero or more Series , which represent the non-spatial attributes. Since ......
Read more >
14.2. Creating Layers
Define the Geometry type. If not a geometryless layer, you can specify whether it should Include Z dimension and/or Include M values. Specify ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found