Specifying the desired crs format of a Geopandas object

I use the geopandas to_file() method to read a shapefile into a geodata object. The shape file has a valid .prj file with ESRI WKT style forecast 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]] 

At the same time, the created geodata map has the crs attribute specified as a dictionary, which is difficult for me to work with, compared to the proj4 or epsg lines:

 {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 documents make it clear that the .crs method takes many different forms of crs information (epsg codes, dictionaries, proj4 lines, ...), but it seems that there is no control over the desired format when writing geodata to a shapefile.

Question: Is there a way to specify the desired crs formatting, or any built-in method for switching between different forms of crs attributes?

+5
source share
2 answers

Not sure if I'm missing something here, but you tried to just set crs in the data frame before executing to_file() , as shown below:

 gdf = geopandas.GeoDataFrame(df, geometry='geometry') gdf.crs = {'init' :'epsg:4326'} # or whatever 
0
source

Is there any way to specify the desired crs formatting

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

any built-in method for switching between different crs attribute formatting?

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

Alternatively, you can directly use the pyproj.CRS class to verify the equality of the various CRS inputs.

0
source

Source: https://habr.com/ru/post/1264081/


All Articles