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.

Access to Fiona's crs_wkt and/or meta attributes when using read_file()

See original GitHub issue

I have a shapefile which I open in geopandas using read_file(). It is in GDA94 mga54 (epsg: 28354). In geopandas it will print the crs attribute as

import geopandas as gpd
source_gdf = gpd.read_file('c:\data\test\boxes_gda94mga54.shp')
print source_gdf.crs
{u'zone': 54, u'ellps': u'GRS80', u'no_defs': True, u'proj': u'utm', u'units': u'm', 'wktext': True, u'south': True}`

When opening in Fiona and printing the coordinate information using the meta attribute it produces

import fiona,pprint
source_fio = fiona.open('c:\data\test\boxes_gda94mga54.shp')
pprint.pprint (source_fio.meta)
{'crs': {u'ellps': u'GRS80',
         u'no_defs': True,
         u'proj': u'utm',
         u'south': True,
         u'units': u'm',
         u'zone': 54},
 'crs_wkt': u'PROJCS["GDA94_MGA_zone_54",GEOGCS["GCS_GDA_1994",DATUM["Geocentric_Datum_of_Australia_1994",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",141],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",10000000],UNIT["Meter",1]]',
 'driver': u'ESRI Shapefile',
 'schema': {'geometry': 'Polygon',
            'properties': OrderedDict([(u'Id', 'int:10'), (u'float_area', 'float:13.11'), (u'double_Len', 'float:19.11'), (u'short_id', 'int:10'), (u'Long_vert', 'int:10'), (u'Date_Creat', 'date'), (u'part_type', 'str:50')])}}

If I then save the file using geopandas to_file() without transforming/re-projecting then look at projection attributes of the saved file using Fiona’s meta again it produces a different crs_wkt result when compared with the above.

source_gdf.to_file('c:\data\test\boxes_gda94mga54_copy.shp',driver="ESRI Shapefile")

new_fio = fiona.open('c:\data\test\boxes_gda94mga54_copy.shp')
pprint.pprint (new_fio.meta)
'crs': {u'ellps': u'GRS80',
         u'no_defs': True,
         u'proj': u'utm',
         u'south': True,
         u'units': u'm',
         u'zone': 54},
 'crs_wkt': u'PROJCS["UTM_Zone_54_Southern_Hemisphere",GEOGCS["GCS_GRS 1980(IUGG, 1980)",DATUM["unknown",SPHEROID["GRS80",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",141],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",10000000],UNIT["Meter",1]]',
 'driver': u'ESRI Shapefile',
 'schema': {'geometry': 'Polygon',
            'properties': OrderedDict([(u'Id', 'int:9'), (u'float_area', 'float:24.15'), (u'double_Len', 'float:24.15'), (u'short_id', 'int:9'), (u'Long_vert', 'int:9'), (u'Date_Creat', 'str:80'), (u'part_type', 'str:80')])}}

Is there a way when using geopandas read_file() to store or access the crs_wkt or meta attribute that could then then be used as a parameter in to_file() to correctly assign the original projection to the output file?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
martinfleiscommented, Apr 19, 2020

This seems to be fixed by using pyproj.CRS under the hood to store CRS information. Roundtrip correctly returns GDA94 / MGA zone 54, not UTM_Zone_54_Southern_Hemisphere anymore.

0reactions
cratcliffcommented, Sep 15, 2017

Thanks @jdmcbr and @jorisvandenbossche for the advice. I have tested the workaround and it does work.

I still think it would be beneficial to have access to a crs_wkt (and maybe epsg as well) as a reference and continue with the proj4 string for conversions. Its easy enough to convert epsg & crs_wkt to proj4 by using GDALs SpatialReference methods which is a dependency of Fiona. This will then provide a more detailed description of the data frames coordinate system to the user when it changes or becomes disconnected from the source.

I am keen to use pandas and geopandas for a project i’m working on which will manipulate and analyze data coming from various sources (shapefiles and csv’s). The analysis will include several datasets and projections to perform multiple geometry operations (buffering, overlays etc) and column calculations, and I will end up with multiple geodataframes so it would be good if the crs_wkt attribute were attached to the data frame rather than managed through separate variables or a custom class.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

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