def convert_sr(geom: ogr.Geometry, epsg_source: int = 4326, epsg_target: int = 3044) -> ogr.Geometry: """converts reference systems of ogr Geometries Arguments: geom {ogr.Geometry} -- geometry where the RS should be changed Keyword Arguments: epsg_source {int} -- epsg code of current reference system (default: {4326}) epsg_target {int} -- epsg code of target reference system (default: {3044}) Returns: ogr.Geometry -- Geometry with transformed reference system """ source = osr.SpatialReference() source.ImportFromEPSG(epsg_source) target = osr.SpatialReference() target.ImportFromEPSG(epsg_target) transform = osr.CoordinateTransformation(source, target) geom.Transform(transform) return geom
def reproject_geom(geom: ogr.Geometry, source_srid: int, target_srid: int) -> ogr.Geometry: """ Reproject the given geometry from one SR to another. :param geom: The geometry to reproject. :type geom: :py:class:`Geometry` :param source_srid: The source SRID (projection the geometry is in currently). :type source_srid: ``int`` :param target_srid: the target SRID. :type target_srid: ``int`` :return: The reprojected geometry. :rtype: :py:class:'Geometry' """ # Source spatial reference in which the input geometry is projected source = osr.SpatialReference() source.ImportFromEPSG(source_srid) # Target spatial reference to which we want to project target = osr.SpatialReference() target.ImportFromEPSG(target_srid) # Set up the transform. transform = osr.CoordinateTransformation(source, target) # transform it geom.Transform(transform) return geom