Skip to content

DOC: describe geometry_area_perimeter size limit concretely#1611

Open
Htet-Kaung-San wants to merge 1 commit into
pyproj4:mainfrom
Htet-Kaung-San:doc/geometry-area-perimeter-limits
Open

DOC: describe geometry_area_perimeter size limit concretely#1611
Htet-Kaung-San wants to merge 1 commit into
pyproj4:mainfrom
Htet-Kaung-San:doc/geometry-area-perimeter-limits

Conversation

@Htet-Kaung-San

Copy link
Copy Markdown

Closes #1592.

The note on Geod.geometry_area_perimeter said only:

There are a few limitations :

  • only works with areas up to half the size of the globe ;
  • certain large polygons may return negative values.

As #1592 points out, that doesn't say what "large" or "certain" mean — whether it's city-sized or continent-sized, and whether shape, poles or the antimeridian are involved.

Both bullets turn out to be the same rule. The area is reduced modulo the total area of the ellipsoid into (-A/2, A/2], so a region covering more than half the ellipsoid is reported as the negated area of its complement:

from pyproj import Geod
from shapely.geometry import Polygon

geod = Geod(ellps="WGS84")
nearly_global = Polygon([(-179, -89), (179, -89), (179, 89), (-179, 89)])
print(geod.geometry_area_perimeter(nearly_global)[0])
# -2833262901265.9062

That polygon is wound counter-clockwise and encloses 99.4% of the globe, but comes back as roughly -0.56% — the thin strip left outside it, negated.

So the answers to the two questions in the issue are concrete:

  • "large" means precisely "encloses more than half the ellipsoid" — about 2.55e14 m² on WGS84.
  • "certain" isn't about shape, proximity to a pole, or crossing the antimeridian. Size alone decides it.

I checked the (-A/2, A/2] bound holds across a grid of boxes spanning ±10° to ±179.9° longitude and ±10° to ±89.9° latitude.

The docstring already carries a separate warning that traversal direction is signed, CCW positive. That's the other reason a result can be negative, and unlike the size limit it applies at any size, so I cross-referenced the two rather than describing them independently.

Changes

  • Replace the vague note with the modulo rule, the WGS84 numbers, and an explicit statement of what does not matter.
  • Cross-reference the traversal-direction warning as the other, size-independent cause.
  • Add doctests for the wraparound and for recovering the enclosed area by adding the total ellipsoid area back.
  • Changelog entry.

Documentation only — no behavior change.

Testing

flake8, ruff and codespell are clean on the changed files, and blacken-docs --skip-errors leaves them unchanged. The docstring's doctests pass (14 examples, 0 failures), including the two new ones. The 99.4% figure is 99.4445% before rounding, so it isn't sitting on a rounding boundary.

The note said only that the function "only works with areas up to half
the size of the globe" and that "certain large polygons may return
negative values", which does not say what "large" or "certain" mean.

Both are the same rule: the area is reduced modulo the total area of the
ellipsoid into (-A/2, A/2]. A region covering more than half the
ellipsoid therefore comes back as the negated area of its complement --
a polygon enclosing 99% of the globe returns about -1%, not +99%. So
"large" means precisely "more than half the ellipsoid" (about 2.55e14
m^2 on WGS84), and shape, proximity to a pole and crossing the
antimeridian do not matter on their own.

Also cross-reference the existing traversal-direction warning, since
that is the other, size-independent reason a result can be negative.

Adds a doctest for the wraparound and for recovering the enclosed area.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

geometry_area_perimeter limitations not documented properly

1 participant