Get adequate projected coordinate system from geographic coordinate system across globe with GeoPandas in Python

coordinate systemgeopandaspython

The Situation

I have a global multiband-raster of 10×10 km resolution at the equator. I need to turn this raster into a GeoDataframe for further processing (where every band would become one column of values). This GeoDataframe is a global grid, also 10×10 km resolution at the equator. I calculate the centroid of every cell/geometry of the GeoDataframe and retrieve the underlying value of the raster with the point_query function from shapely.

The Problem

The global raster is in the geographic coordinate system EPSG:4326. Employing the shapely centroid function is imprecise when used with a geographic coordinate system, mostly close to the poles (if I understood correctly). For the imprecision, I am referring to the following UserWarning raised by GeoPandas:

UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation.

The Question

Is there a way to assign the correct projected coordinate reference system (e.g., UTM) globally to every "group" of grid cells, and therefore not get the GeoPandas UserWarning raised?

What I have tried

The code below retrieves the centroid of every country in latitude and longitude (could also be any arbitrary grid, e.g. of 10×10 degrees), and generates a UTM code. The problem is, that the calculation of this centroid is already imprecise.

        # Take the UTM coordinate system to correctly calculate the area, since epsg4326 is not a planar crs. See https://gis.stackexchange.com/questions/365584/convert-utm-zone-into-epsg-code
        # set coordinate system for area calculation for points
        country_center_x = TM_border.get_borders().centroid.iloc[
            0].x  # get the x coordinate of the center of the country
        country_center_y = TM_border.get_borders().centroid.iloc[
            0].y  # get the y coordinate of the center of country
        specific_utm = utm.from_latlon(latitude=country_center_y,
                                       longitude=country_center_x)
        if country_center_y < 0:  # if point lies south of equator
            self.crs_dict = {'proj': 'utm', 'zone': specific_utm[2], 'south': True}
        else:  # if point lies north of equator
            self.crs_dict = {'proj': 'utm', 'zone': specific_utm[2]}

To Consider

I do not have a feeling for how much off the calculation of the centroids are close to the poles. Mabye it is negligible if the centroid is calculated on a country or 10×10 degree tile base.

Best Answer

With recent (>= 0.9) versions of geopandas, GeoDataFrame has an estimate_utm method that should do just that, automatically.

Related Question