Fortunately, we already did this kind of operation before and now we are going to adapt it to our data model.
We will transform the coordinates of the geometries only when they are needed. To perform the transformation, we will create a new utility function, as follows:
Open
geo_functions.py
in ourutils
folder and create a new function:def transform_geometry(geom, src_epsg=4326, dst_epsg=3395): """Transforms a single wkb geometry. :param geom: wkb geom. :param src_epsg: EPSG code for the source geometry. :param dst_epsg: EPSG code for the destination geometry. """ ogr_geom = ogr.CreateGeometryFromWkb(geom) ogr_transformation = create_transform(src_epsg, dst_epsg) ogr_geom.Transform(ogr_transformation) return ogr_geom.ExportToWkb()
It takes as arguments geometries in the WKB format, its EPSG code, and the EPSG code for the desired coordinate system for the output. It performs the transformation and returns...