Skip to content

geopandas 1.1.2 fails at u_coord.get_resolution for EPSG 4087 #1351

Open

Description

@emanuel-schmid

Problem

climada.util.test.test_coordinates.TestRasterMeta.test_get_resolution_meters_pass fails on windows:

 Name            Version  Build                Channel     Subdir
------------------------------------------------------------------
 folium          0.20.0   pyhd8ed1ab_0         conda-forge noarch
 geopandas       1.1.4    pyhd8ed1ab_0         conda-forge noarch
 geopandas-base  1.1.4    pyha770c72_0         conda-forge noarch
 mapclassify     2.10.0   pyhd8ed1ab_1         conda-forge noarch
 matplotlib-base 3.10.9   py312h0ebf65c_0      conda-forge win-64
 pyogrio         0.12.1   py312h3f2e00f_0      conda-forge win-64
 pyproj          3.7.2    py312h589cc8f_5      conda-forge win-64
 python          3.12.14  hb12b558_3_cpython   conda-forge win-64
 xyzservices     2026.3.0 pyhd8ed1ab_0         conda-forge noarch

note: atm (2026-11-06) geopandas 1.2 is not available from conda-forge for windows

Cause

There is apparently a bug in geopandas 1.1.4 or one of its dependencies.
The transformation from epsg 4326 to epsg 4087 is supposed to keep equal distances equal. A difference of one degree should result in a distance of 111319.5 meters, no matter where. But for latitudes, it doesn't.

Demo

import geopandas as gpd
import pandas as pd

gdf = gpd.GeoDataFrame(
    geometry=gpd.points_from_xy([0] * 90, list(range(90))),
    crs="EPSG:4326",
)
df = pd.DataFrame({"lat": gdf.to_crs("EPSG:4087").geometry.y})
df['nxt'] = list(df.lat[1:]) + [None]
df['dist'] = df.nxt - df.lat
df.dist.plot()
Image

this should be a horizontal line around 111319

Now what?

The bug is apparently already fixed for geopandas 1.2 (at least for Linux).
For windows users: be aware of the small (though significant) discrepancy and update the environment once geoppandas 1.2 is availble.
If this is a concern, perhaps downgrading geopandas might help. (I do currently not know which versions below 1.1.2 are not affected. Sorry.)

Activity

  1. peanutfun commented on Nov 10, 2026

    @peanutfun
    Member

    Do you have a reference for the bug? I still see it on Ubuntu, Python 3.12/3.13, GeoPandas v1.2: https://github.com/CLIMADA-project/climada_python/actions/runs/42808263740/job/129802888617?pr=1286

  2. peanutfun commented on Nov 10, 2026

    @peanutfun
    Member

    @emanuel-schmid Are you sure this is unexpected? Both of these CRSs are based on WGS84, which implements a spheroid as Earth reference shape, meaning that different latitudes are indeed expected to differ in their distance: https://en.wikipedia.org/wiki/World_Geodetic_System#WGS84 Constant distances would be expected for fixed latitudes and differing longitudes

  3. peanutfun commented on Nov 10, 2026

    @peanutfun
    Member

    Meanwhile, degree_to_km explicitly works under the assumption of a spherical earth:

    def degree_to_km(degree):

  4. emanuel-schmid commented on Nov 10, 2026

    @emanuel-schmid
    CollaboratorAuthor

    @peanutfun it's sure unexpected to me 😁

    The expected behavior was:

    Image

    as for python 3.11, geopandas 1.2 and its dependencies

     Name            Version  Build                Channel     Subdir  
    ────────────────────────────────────────────────────────────────────
     folium          0.20.0   pyhd8ed1ab_0         conda-forge noarch  
     geopandas       1.2.0    pyhd8ed1ab_0         conda-forge noarch  
     geopandas-base  1.2.0    pyha770c72_0         conda-forge noarch  
     mapclassify     2.10.0   pyhd8ed1ab_1         conda-forge noarch  
     matplotlib-base 3.10.9   py311h0f3be63_0      conda-forge linux-64
     pyogrio         0.12.1   py311h422ce6a_0      conda-forge linux-64
     pyproj          3.7.2    py311h400b93a_3      conda-forge linux-64
     python          3.11.18  h5f976f7_0_cpython   conda-forge linux-64
     xyzservices     2026.9.1 pyhd8ed1ab_0         conda-forge noarch  
    

    So, perhaps the "bug" (if it is one) does not disappear but emerge...

  5. emanuel-schmid commented on Nov 10, 2026

    @emanuel-schmid
    CollaboratorAuthor

    turns out that the proj library underneath changed between 3.7.1 and 9.8.1.

    from pyproj import Transformer
    
    transformer = Transformer.from_crs("EPSG:4326", "EPSG:4087", always_xy=True)
    _x, y = transformer.transform(0., 1.)
    
    print(y)

    up to proj 3.7 this prints 111319.49079327357
    starting from proj 3.8 110574.38855779878

  6. emanuel-schmid commented on Nov 10, 2026

    @emanuel-schmid
    CollaboratorAuthor

    I suppose they had their reasons but to me, it's kind of hard to grasp.
    Wasn't the 4087 projection meant to strictly assign the same amount of meters to 1°?
    I mean, for the longitudes, they don't mind the shape of earth at all. Why for latitudes?
    And even so - the other way around would seem to make more sense: 1° at the equator has more meters than 1° at the pole.

    🤦 I think I got it: the angle is not defined by the direction to the center of the earth but by an "orthogonal to the horizon" - right? Than it all makes sense!

  7. emanuel-schmid commented on Nov 10, 2026

    @emanuel-schmid
    CollaboratorAuthor

    As they think it's correct this way, we'll update the test.
    see OSGeo/PROJ#4860

  8. peanutfun commented on Nov 11, 2026

    @peanutfun
    Member

    Always honour your ellipsoids! OSGeo/PROJ#4860 (comment)

  9. peanutfun commented on Nov 25, 2026

    @peanutfun
    Member

    The only instance where we use degree_to_km is when using the approx method for nearest neighbor matching of coordinates:

    "approx": _nearest_neighbor_approx,

    This is not the default setting and I doubt anyone is using it. Shall we just remove the approx option for coordinate matching and the degree_to_km function? I don't see a purpose in it. After the PROJ update, the test fixed in #1359 also does not make sense anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions