You can set yourself a Python function to to the job using the PyProj library. This will work Shapely geometries, which are usually the one we are working with in the Python GIS domain.
Sample function:
import pyproj
from pyproj import Transformer
import shapely.ops as sp_ops
def transform_geom_to_srid(geom, scrs, tcrs)
""" Transform a geometry to a new target CRS.
Works with pyproj version >= 2.x.x
- geom is a Shapely geometry instance
- scrs is your input CRS EPSG integer (the one of your original data)
- tcrs is your target CRS EPSG integer (the one you want to reproject
your data in, probably 4326 in your case)
"""
project = Transformer.from_crs(
'EPSG:'+str(scrs),
'EPSG:'+str(tcrs),
always_xy=True
)
return sp_ops.transform(project.transform, geom)
Notice: if you use an older version of PyProj, you will have to set your CRS manually including an 'init=' string, e.g. pyproj.Proj('init=EPSG:'+str(scrs))
instead of just writing the 'EPSG:' strings in the [.from_crs()
][10] method.
More information
Shapely is a library for manipulating geometry data in Python.
An other very useful library, especially for data science, is GeoPandas, it heavily relies on Pandas, which you must, I hope, already know. The geometry column of a GeoDataFrame usually contains Shapely geometries for each row if your dataframe.
See also here for PROJ documentation: https://proj.org/
And here for PyProj: https://pyproj4.github.io/pyproj/stable/
EPSG codes are defined in the EPSG registry, which is actually the IOGP today; https://epsg.org/home.html
Transformer.from_crs(crs_from=31370, crs_to=4326)