The primary answer to Adding GeoPandas Dataframe to PostGIS table? requires entering the geodataframe
geometry
column's integer SRID.
Getting the CRS attribute using the crs
attribute like so
import geopandas as gpd
file_path = 'my_geodata.shp'
gdf = gpd.read_file(file_path)
geom_srid = gdf.geometry.crs['init']
gives a string like 'epsg:32616'
.
The integer value can be extracted using regex:
geom_srid_num = re.search(r'\d+$', geom_srid)
But I'm not sure if the SRID is written in this format all the time, and if this method is reliable. Is there a more appropriate way to retrieve the integer SRID for a geodataframe
geometry
column?