Add DimensionalData extension for polygonize#429
Merged
Conversation
Adds `GeometryOpsDimensionalDataExt`, which polygonizes any `AbstractDimArray` (e.g. a `DimArray` or `Raster`) using its `X`/`Y` lookup values via interval bounds, rather than the raw integer axes. Falls back to treating `Points` sampling as `Intervals` (with a warning), and preserves the array's crs. Rebased onto current `main`: drops the now-redundant Julia 1.9->1.10 bump, and adapts `Project.toml` to the current `[weakdeps]`/`[extensions]`/`[compat]` layout. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
`_pixel_edges` indexed its 1-based pixel-bound vectors (`xs`/`ys`) with the array's native axes, throwing a `BoundsError` for arrays with offset axes (e.g. `OffsetArray`). Index `A` by its native axes but the bound vectors positionally instead. Register `test/methods/polygonize.jl` in `runtests.jl` (it was never wired in, so `polygonize` — and the new DimensionalData extension — had no CI coverage). Make the file deterministic (seed the RNG) and fix a `@test_nowarn multipolygon = polygonize(A)` binding-scope error on Julia 1.12. Two assertions are marked `@test_broken`: `polygonize`'s ring tracing is coordinate-magnitude-dependent, so rescaling/translating the coordinates changes the decomposition. That is a separate pre-existing bug. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
`_pixel_edges` compared the row index against the first/last *column* index (and vice versa) in the S/W neighbour guards. When an array's two axes start at different offsets those guards no longer short-circuit at the boundary, so polygonizing e.g. `OffsetArrays.Origin(-100, -50)(...)` with edge pixels threw a `BoundsError`. Name the boundary indices by row/column so each guard matches its axis. No-op for 1-based (and equal-offset) arrays. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Freshens and rebases #178 (originally by @rafaqz) onto current
main, adds aDimensionalDataextension forpolygonize, and wires thepolygonizetests into CI (fixing the bugs that surfaced).What it does
Adds
GeometryOpsDimensionalDataExt, which polygonizes anyAbstractDimArray(e.g. aDimArrayorRaster) using itsX/Ylookup coordinate values (via interval bounds) rather than the raw integer axes.Pointssampling is treated asIntervals(with a warning); the array's crs is preserved.polygonizenow runs in CItest/methods/polygonize.jlwas never registered inruntests.jl(onmaintoo), sopolygonizehad no CI coverage. It's now wired in. Getting it green required fixing several pre-existing issues:Real source bugs in
_pixel_edges(offset-array handling):xs/ys) with the array's native axes →BoundsErroron anyOffsetArray. Now indexesAby native axes and the bound vectors positionally.BoundsErrorfor arrays whose two axes start at different offsets (e.g.Origin(-100, -50)) with edge pixels. Fixed by naming the boundary indices by row/column. No-op for 1-based arrays.Test-harness fixes:
@test_nowarn multipolygon = polygonize(A)no longer leaks the binding on Julia 1.12 → changed tomultipolygon = @test_nowarn polygonize(A).Fixes to the original #178
DD.AbstractDimArrayaspolygonize's data argument — aMethodError. Now passes the arrayA.evilin its crs assertion.Known pre-existing bug (NOT fixed here) — flagged via
@test_brokenpolygonize's ring tracing is coordinate-magnitude-dependent: the same boolean pattern produces a different polygon decomposition depending on the coordinate values (e.g.polygonize(1:100, …)vspolygonize(1001:1100, …)give different polygon counts; simple shapes get a redundant collinear vertex at a coordinate-hash-dependent start point; some coordinate ranges even hit aKeyError). Two assertions that assume translation/scale invariance are marked@test_brokenwith comments pointing here. This is a separate ring-tracing bug worth its own issue/PR.Verification
Full test suite passes (
Pkg.test(), exit 0). ThePolygonizetestset runs in-suite: 74 pass / 2 broken (the documented@test_broken), 0 fail/error.Closes #178.
🤖 Generated with Claude Code