2

How does GeoPandas save CRS information?

globe = ccrs.Globe(ellipse='sphere', semimajor_axis=6370000, semiminor_axis=6370000)

crs = ccrs.LambertConformal(globe=globe,central_longitude=111, central_latitude=33,
                            standard_parallels=(30, 60))
crs_proj4 = crs.proj4_init

gdf.crs = ccrs.PlateCarree().proj4_init
gdf.to_crs(crs_proj4, inplace=True)
gdf.to_file(r'/Users/sam/Documents/grid_source.shp')

and then

a=gpd.read_file(r'/Users/sam/Documents/grid_source.shp').crs
a==gdf.crs

returns False.

1
  • can you print the outputs of gpd.read_file(r'/Users/sam/Documents/grid_source.shp').crs and gdf.crs
    – Joe Be
    Nov 11 at 9:25
3

IMHO you do not need the inplace=True parameter in your code and also besides re-projecting you also need to set the new crs.

So, the entire code can look like

import geopandas as gpd
import cartopy.crs as ccrs

globe = ccrs.Globe(ellipse='sphere', semimajor_axis=6370000, semiminor_axis=6370000)
crs = ccrs.LambertConformal(globe=globe, central_longitude=111, central_latitude=33, standard_parallels=(30, 60))
crs_proj4 = crs.proj4_init

gdf = gpd.read_file('P:/Test/qgis_test/grid_test.shp')

gdf.crs = ccrs.PlateCarree().proj4_init
gdf.to_crs(crs_proj4)
gdf.crs = crs_proj4

gdf.to_file('P:/Test/qgis_test/grid_test2.shp')

So, after reading the output from the above code

gdf2 = gpd.read_file('P:/Test/qgis_test/grid_test2.shp')
print(gdf2.crs)

you may get the following output

PROJCS["unknown",GEOGCS["GCS_unknown",DATUM["D_unknown",SPHEROID["unknown",6370000,0]],PRIMEM["Greenwich",0],UNIT["Degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["latitude_of_origin",33],PARAMETER["central_meridian",111],PARAMETER["standard_parallel_1",30],PARAMETER["standard_parallel_2",60],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH]]

References:

4
  • 1
    Small comment on your code: it is currently not keeping the reprojected data. You need to re-assign it: gdf = gdf.to_crs(crs_proj4) (and not set the crs afterwards)
    – joris
    Nov 11 at 14:57
  • Please feel free to adjust it 🙂
    – Taras
    Nov 11 at 14:58
  • 1
    gdf.to_crs(crs_proj4, inplace=True) may means gdf = gdf.to_crs(crs_proj4), and Thanks for helping! It did't influece my own work but I need to exchange someting with my co-workers.
    – sam han
    Nov 18 at 14:49
  • You are welcome. Please, do not forget about "What should I do when someone answers my question?"
    – Taras
    Nov 19 at 6:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.