GeoPandas Set CRS on Points

Geopandas API got cleaned up, and now works without surprises. Make sure to use the lastest stable version and read the docs.

Setting the CRS on a GeoDataFrame using its EPSG code is as simple as

gdf.set_crs(epsg=4326, inplace=True)

where gdf is a geopandas.geodataframe.GeoDataFrame. Watch out for the explicit inplace!

So in the example above it would be:

import pandas as pd
from shapely.geometry import Point
from geopandas import GeoDataFrame

df = pd.DataFrame({'zip':[19152,19047],
               'Lat':[40.058841,40.202162],
               'Lon':[-75.042164,-74.924594]})

geometry = [Point(xy) for xy in zip(df.Lon, df.Lat)]
gdf = GeoDataFrame(df, geometry=geometry)

gdf.set_crs(epsg=4326, inplace=True)
# ^ comment out to get a "Cannot transform naive geometries" error below

# project to merkator
gdf.to_crs(epsg=3395)

     zip        Lat        Lon                          geometry
0  19152  40.058841 -75.042164  POINT (-8353655.485 4846992.030)
1  19047  40.202162 -74.924594  POINT (-8340567.652 4867777.107)

The answer was here all along:

hg=hg.to_crs(c.crs)

This sets the crs for hg to that of c.


The format for Setting CRS in GeoPandas is now

gdf.crs = "EPSG:4326"

The earlier format is deprecated

ref: https://geopandas.org/projections.html