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.

GeoPandas to_file() saves GeoDataFrame without coordinate system

See original GitHub issue

I have

    GeoPandas 0.2.1 py27_0
    fiona 1.7.0 np110py27_1
    Python 2.7.10

installed in Anaconda 2-4.1.1-Windows-x86 environment. I am able to construct GeoDataFrame by reading input datasets and operate the data yet saving an output dataset does not preserve the coordinate system.

import geopandas as gpd
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
world.to_file(driver='ESRI Shapefile',filename=r'C:\GIS\Temp\world_out.shp')

The world_out.shp does contain the features and the schema of the source shapefile, but coordinate system is undefined (<Unknown>). The world_out.prj file is 0 KB and doesn’t contain anything.

out = gpd.read_file(r'C:\GIS\Temp\world_out.shp')
print out.crs
>>> {}

I have tested to perform this operation using pure Fiona and it works fine, preserving the crs information.

So, it seems as GeoPandas is not able to write crs of the GeoDataFrame into the output dataset when calling the to_file() method. I have tried calling to_file() on GeoDataFrames constructed from various sources and datasets and the coordinate system information was never present in the output dataset.

What am I doing wrong or is it a bug?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:19 (11 by maintainers)

github_iconTop GitHub Comments

3reactions
rutgerhofstecommented, Aug 28, 2017

Does is matter if your GDAL_DATA variable is set correctly, can you try:

import os
if 'GDAL_DATA' not in os.environ:
    os.environ['GDAL_DATA'] = r'/usr/share/gdal/2.1'
from osgeo import gdal,ogr,osr
'GDAL_DATA' in os.environ

and of course change the path to your settings.

Without this variable Fiona/Shapely doesn’t know how to create a proper .prj file based on a projection but rather saves an empty .prj file.

0reactions
jdmcbrcommented, Dec 10, 2017

Since it seems as though a clean environment addresses this issue, will close this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

GeoPandas to_file() saves GeoDataFrame without coordinate ...
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 >
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 >
Reading and Writing Files - GeoPandas
GeoDataFrames can be exported to many different standard formats using the geopandas.GeoDataFrame.to_file() method. For a full list of supported formats, type ...
Read more >
Introduction to GeoPandas
To write a GeoDataFrame back to file use GeoDataFrame.to_file() . The default file format is Shapefile, but you can specify your own with...
Read more >
geopandas.GeoDataFrame.crs
The Coordinate Reference System (CRS) represented as a pyproj. ... CRS.from_user_input() , such as an authority string (eg “EPSG:4326”) or a WKT string....
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