Skip to content

Run antimeridian_split through apply on the polygonal traits - #459

Draft
asinghvi17 wants to merge 1 commit into
mainfrom
agent/antimeridian-split-apply
Draft

Run antimeridian_split through apply on the polygonal traits#459
asinghvi17 wants to merge 1 commit into
mainfrom
agent/antimeridian-split-apply

Conversation

@asinghvi17

Copy link
Copy Markdown
Member

antimeridian_split walked its input with a bespoke _each_polygon helper that
only knew how to handle a bare Polygon or MultiPolygon. This replaces that
with apply on the polygonal trait target:

const _AM_TARGETS = TraitTarget{Union{GI.PolygonTrait, GI.MultiPolygonTrait}}()

apply(WithTrait((trait, g) -> _split_geom(trait, g, λn, pole_spacing)), _AM_TARGETS, work; threaded)

so the split now runs on every polygonal geometry in any nesting apply
understands — features, feature collections, tables, (nested) vectors — and the
structure above the polygons is rebuilt around the results. A bare Polygon
still comes back as a MultiPolygon, as before.

Notes

  • The target is the union, not PolygonTrait alone. A MultiPolygon must
    split part-by-part into one flat piece list; targeting only PolygonTrait
    would rebuild it as a MultiPolygon of MultiPolygons. So there are two
    target methods, _split_geom(::GI.PolygonTrait, …) and
    _split_geom(::GI.MultiPolygonTrait, …), both feeding the unchanged
    _split_polygon!.
  • The ArgumentError guard stays, but shrank. apply never hands a
    LineString to f when the target is polygonal — it descends toward points
    instead — so a bare unsupported geometry still has to be rejected up front.
    _check_split_trait now rejects only geometry traits that aren't polygonal,
    letting nothing/feature traits fall through to apply's own descent.
  • The rotated-pole step stays outside the apply. _rotate_to_pole is
    itself an apply(PointTrait), so it already handles any nesting, and doing it
    once avoids rebuilding the rotation matrix per polygon.
  • New threaded keyword, forwarded to apply.

No change to the split algorithm itself — the arrangement, face selection,
branch fixing and pole-row emission are untouched.

Test plan

test/transformations/antimeridian_split.jl passes in full, including the
Natural Earth cases. New nested inputs testset covers vector input (threaded
and not), a feature collection with properties preserved, and MultiPolygon
input — the last of which was previously untested.

🤖 Generated with Claude Code

Replace the hand-rolled `_each_polygon` walk with `apply` on a
`TraitTarget{Union{PolygonTrait,MultiPolygonTrait}}`, so the split runs on
every polygonal geometry in any nesting `apply` understands (features,
feature collections, tables, vectors) and the structure above is rebuilt.

The target is the union rather than `PolygonTrait` alone because a
`MultiPolygon` must split into one flat piece list, not a `MultiPolygon` of
`MultiPolygon`s. The trait guard stays — `apply` never hands an unsupported
geometry to the target function — but now only rejects non-polygonal
*geometry* traits, letting arrays/features fall through to `apply`.

Adds a `threaded` keyword, and a testset covering vector, feature
collection and `MultiPolygon` inputs.

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.

1 participant