5

I use geopandas's to_file() method to read a shapefile into a geopandas object. The shapefile has a valid .prj file with a ESRI WKT style projection information:

PROJCS["Slovenia_1996_Slovene_National_Grid",GEOGCS["GCS_Slovenia 1996",DATUM["D_Slovenia_Geodetic_Datum_1996",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",15],PARAMETER["scale_factor",0.9999],PARAMETER["false_easting",500000],PARAMETER["false_northing",-5000000],UNIT["Meter",1]]

With this, a created geodataframe has a crs attribute set as a dictionary, which I find it hard to work with, compared to proj4 string or epsg codes:

{u'lon_0': 15, u'k': 0.9999, u'ellps': u'GRS80', u'y_0': -5000000, u'no_defs': True, u'proj': u'tmerc', u'x_0': 500000, u'units': u'm', u'lat_0': 0}

Geopandas projection docs make it clear that .crs method accepts many different forms of crs information (epsg codes, dictionaries, proj4 strings,...), but it seems that there there is no control about the desired format when writing geopandas to shapefile.

Question: Is there any way to specifiy the desired crs formatting or any built-in method to switch between the diffent formattings of crs attribute?

Marjan Moderc
  • 2,747
  • 23
  • 44
  • Why is the `dict` hard to work with? Do you need to export the reference system? – Logan Byers Feb 10 '17 at 15:45
  • I need a bullet-proof way of comparing the crs equality of different geospatial datasources (rasters, shapefiles,...) , so I do it by checking the epsg codes. That's why I would like to normalize all the crs formattings to a single epsg code which will be easier to crosscheck. However, I am somehow digging closer by checking out the pyproj module, which is being used by geopandas for transformation purposes... – Marjan Moderc Feb 10 '17 at 16:12

2 Answers2

0

Not sure if I'm missing something here, but have you tried just setting the crs in the dataframe before doing to_file() like below:

gdf = geopandas.GeoDataFrame(df, geometry='geometry')

gdf.crs = {'init' :'epsg:4326'} # or whatever
Grizzly2501
  • 113
  • 1
  • 3
  • 10
  • Hi Grizzly! Thanks for the tuning in, but the thing is that I don't always know the epsg of the dataset I work with, even though it is correctly georeferenced. Thats the whole point of the question. I want to be able to implicitly convert all the crs formats into epsg if possible, so I can compare crs-es of two different datasets confidently... – Marjan Moderc Apr 10 '19 at 06:30
  • Hmm, seems I don't understand the issue well enough then. Apologies – Grizzly2501 Apr 10 '19 at 07:08
0

Is there any way to specifiy the desired crs formatting

The shapefile prj file has to be in the WKT format. See: https://gis.stackexchange.com/questions/114835/is-there-a-standard-for-the-specification-of-prj-files#114851

any built-in method to switch between the diffent formattings of crs attribute?

Geopandas uses pyproj as a dependency. If you use pyproj 2+, you can use the pyproj.CRS class to convert formats. See: https://pyproj4.github.io/pyproj/stable/examples.html

Additionally, you can use the pyproj.CRS class directly to check for equality of different CRS inputs.

snowman2
  • 646
  • 4
  • 11