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 '0.9.0' does not read correctly the CRS in Python 3.7

See original GitHub issue

I have this polygon as a GeoJSON file:

{
"type": "FeatureCollection",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::32614" } },
"features": [
{ "type": "Feature", "properties": { }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 385692.315535633417312, 2665734.629486501216888 ], [ 385752.565762493002694, 2665907.707511680666357 ], [ 385973.504760747193359, 2665845.335410861764103 ], [ 385920.972954970493447, 2665669.763593637850136 ], [ 385692.315535633417312, 2665734.629486501216888 ] ] ], [ [ [ 385733.187279019562993, 2665913.178351240698248 ], [ 385672.945492088387255, 2665740.124590761493891 ], [ 385462.083911215595435, 2665799.946275424677879 ], [ 385510.970917687052861, 2665975.915454667527229 ], [ 385733.187279019562993, 2665913.178351240698248 ] ] ], [ [ [ 385491.626872348948382, 2665981.376948713324964 ], [ 385442.7467252817587, 2665805.432456693146378 ], [ 385198.318574909644667, 2665874.781979747582227 ], [ 385254.933825746877119, 2666048.206011556554586 ], [ 385491.626872348948382, 2665981.376948713324964 ] ] ], [ [ [ 385235.574371829337906, 2666053.67226471286267 ], [ 385178.967076495871879, 2665880.272615892346948 ], [ 384942.6304983261507, 2665947.331439384259284 ], [ 385002.294641724787652, 2666119.542462015058845 ], [ 385235.574371829337906, 2666053.67226471286267 ] ] ], [ [ [ 384982.918213087075856, 2666125.013909137807786 ], [ 384923.262473451148253, 2665952.827161924447864 ], [ 384712.73012637719512, 2666012.568419008050114 ], [ 384763.264541121840011, 2666187.041012389585376 ], [ 384982.918213087075856, 2666125.013909137807786 ] ] ] ] } }
]
}

As you can see the EPSG:32614.

When I read this file with GeoPandas on Python 3.6 (geopandas version ‘0.8.1’) I get the correct CRS:

df = gpd.read_file(p)
df.crs
>>>
   <Projected CRS: EPSG:32614>
Name: WGS 84 / UTM zone 14N
Axis Info [cartesian]:
- E[east]: Easting (metre)
- N[north]: Northing (metre)
Area of Use:
- name: World - N hemisphere - 102°W to 96°W - by country
- bounds: (-102.0, 0.0, -96.0, 84.0)
Coordinate Operation:
- name: UTM zone 14N
- method: Transverse Mercator
Datum: World Geodetic System 1984
- Ellipsoid: WGS 84
- Prime Meridian: Greenwich

However, in Python 3.7 (geopandas version ‘0.9.0’) I get the wrong CRS:

df = gpd.read_file(p)
df.crs
>>>
<Geographic 2D CRS: EPSG:4326>
    Name: WGS 84
    Axis Info [ellipsoidal]:
    - Lat[north]: Geodetic latitude (degree)
    - Lon[east]: Geodetic longitude (degree)
    Area of Use:
    - name: World.
    - bounds: (-180.0, -90.0, 180.0, 90.0)
    Datum: World Geodetic System 1984
    - Ellipsoid: WGS 84
    - Prime Meridian: Greenwich

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
johnflavincommented, Apr 4, 2021

@ran-pelta It appears the packages you have installed into your 3.7 environment can’t work together consistently. This is likely because of the mixed conda/pip installation. The best practice (by which I mean “easiest way to get a working set of dependencies”) is to install everything using conda from the conda-forge channel. See the installation instructions at https://geopandas.org/getting_started.html

The reason for this is that the various python package dependencies of geopandas (like fiona, pyproj, shapely, etc.) rely on C or C++ libraries (GEOS, GDAL, PROJ). When you use conda, it installs those C libraries into a common location and all the python packages point to them in a consistent way. When you install from wheels, they will typically have the C dependencies they need bundled inside. That can lead to interoperability issues if the bundled library versions are different than or incompatible with the requirements of some of the other packages in the dependency ecosystem. It is possible to make a consistent environment with all wheels, or maybe using pip and building from source, though it is more difficult than with all conda packages. And a mixed environment installed partially using conda and partially using pip is all but guaranteed to have compatibility issues. (Note that this doesn’t apply to everything in the python world, as a huge number of packages don’t need any C libraries and will happily work with mixed conda/pip environments. The geospatial stack required by geopandas is more delicate in that regard than most other environments.)

With regard to CRS in GeoJSON:

CRS information is not officially part of the GeoJSON spec anymore. The Coordinate Reference System section of the spec says

The coordinate reference system for all GeoJSON coordinates is a geographic coordinate reference system, using the World Geodetic System 1984 (WGS 84) datum, with longitude and latitude units of decimal degrees.

But saying it is “not permitted” is not correct. They know CRS information is often included, and that’s ok.

However, where all involved parties have a prior arrangement, alternative coordinate reference systems can be used without risk of data being misinterpreted.

1reaction
akrherzcommented, Mar 17, 2021

Try gpd.show_versions() (plural)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Changelog — GeoPandas 0.12.2+0.gefcb367.dirty ...
Combining GeoSeries/GeoDataFrames with pandas.concat will no longer silently override CRS information if not all inputs have the same CRS (#2056).
Read more >
Installation — GeoPandas 0.12.2+0.gefcb367.dirty ...
To install GeoPandas and all its dependencies, we recommend to use the conda package manager. This can be obtained by installing the Anaconda...
Read more >
Managing Projections — GeoPandas 0.12.2+0.gefcb367.dirty ...
A CRS tells Python how those coordinates relate to places on the Earth. ... will not be possible and exported files may not...
Read more >
Introduction to GeoPandas
CRS tells GeoPandas where the coordinates of geometries are located on the Earth. In some cases, CRS is geographic, which means that coordinates...
Read more >
Introduction to GeoPandas
Concepts#. GeoPandas, as the name suggests, extends the popular data science library pandas by adding support for geospatial data. If you are not...
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