DOC: describe geometry_area_perimeter size limit concretely - #1611
DOC: describe geometry_area_perimeter size limit concretely#1611Htet-Kaung-San wants to merge 2 commits into
Conversation
|
Gentle nudge on this one — it's a docs-only change and the workflow is sitting at "action_required" (the first-time-contributor gate), so it hasn't run since I pushed the fixup. Two things to save a review round:
Happy to rebase or adjust wording if you'd prefer. |
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>
test_doctest_wrapper asserts an exact number of expected doctest failures, which is 6 when shapely is missing because the examples in Geod.geometry_length and Geod.geometry_area_perimeter cannot build their geometries. The examples added here are shapely-based too, so the count rose to 10 and the assertion failed on every environment without shapely -- the Docker python 3.12, 3.13 and 3.14 jobs. The 3.11 job has shapely, expects 0 failures, and passed, which confirms the examples themselves are correct. Drop the ellipsoid-area arithmetic, which was a lot of docstring for one point, and keep the sign demonstration. That takes the addition from four failures to two, so the missing-shapely count becomes 8. Verified against a source build with PROJ 9.8.1: with shapely absent the wrapper passes at 8, with shapely present it passes at 0, and unmodified main still passes at 6. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
0db4de4 to
d4c28ed
Compare
|
I just rebased your branch (be careful pulling locally, may need |
djhoese
left a comment
There was a problem hiding this comment.
This looks reasonable to me. We'll wait for CI. Thanks!
Note: I won't pretend to fully understand the details here so if another maintainer wants to comment on this it would be appreciated.
| .. note:: | There are a few limitations : | ||
| | - only works with areas up to half the size of the globe ; | ||
| | - certain large polygons may return negative values. | ||
| .. note:: The area is reduced modulo the total area of the ellipsoid, |
There was a problem hiding this comment.
I think this reads very difficult (at least for the non-native speaker that I am), what does "reduced modulo" mean?
| -1% of the total area, not +99%. Size is the only reason a | ||
| correctly oriented polygon comes back negative, and "large" | ||
| means precisely "more than half the ellipsoid" -- shape, |
There was a problem hiding this comment.
I think there is no need to refer to "large" and explaining what it means, since the actual text using that word has now been removed (this now rather makes it confusing)
| ... ]) | ||
| ... ) | ||
| >>> geod.geometry_area_perimeter(nearly_global)[0] < 0 | ||
| True |
There was a problem hiding this comment.
This is not actually a "nearly global" polygon in practice, because for geodesic edges, it takes the shortest path on the sphere, so this is actually connecting -179 to 179 crossing the anti-meridian, i.e. an edge of 2 degrees long, and not 358 degrees long. As a consequence of that interpretation, this polygon is actually oriented clock-wise (although shapely, which is not using geodesic logic, will indicate this is CCW), and that is the reason this is giving a negative result
Closes #1592.
The note on
Geod.geometry_area_perimetersaid only: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: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:
2.55e14m² on WGS84.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
Documentation only — no behavior change.
Testing
flake8,ruffandcodespellare clean on the changed files, andblacken-docs --skip-errorsleaves them unchanged. The docstring's doctests pass (14 examples, 0 failures), including the two new ones. The99.4%figure is99.4445%before rounding, so it isn't sitting on a rounding boundary.