Exemple #1
0
def auto_utm_epsg_for_geometry(geometry: BaseGeometry, crs: str = "EPSG:4326") -> int:
    """
    Get EPSG code of best UTM zone for given geometry.
    """
    # Pick a geometry coordinate
    p = geometry.representative_point()
    x = p.x
    y = p.y

    # If needed, convert it to lon/lat (WGS84)
    crs_wgs = 'epsg:4326'
    if crs.lower() != crs_wgs:
        x, y = pyproj.transform(pyproj.Proj(crs),
                                pyproj.Proj(crs_wgs),
                                x, y, always_xy=True)

    # And derive the EPSG code
    return auto_utm_epsg(x, y)