Add contour line extraction via marching squares (#964)#974
Merged
brendancol merged 7 commits intomasterfrom Mar 5, 2026
Merged
Add contour line extraction via marching squares (#964)#974brendancol merged 7 commits intomasterfrom
brendancol merged 7 commits intomasterfrom
Conversation
New xrspatial.contour module with contours() function that extracts isolines from 2D rasters. Supports numpy, cupy, dask+numpy, and dask+cupy backends. Includes segment stitching into polylines and optional GeoDataFrame output.
Corrected edge assignments in the marching squares lookup table. Previous table had wrong edges for most cases (e.g. case 1 used top edge instead of bottom edge). Added comprehensive test suite covering correctness, NaN handling, edge cases, backend equivalence, GeoDataFrame output, accessor integration, and closed-ring detection.
Matplotlib-based interactive app for exploring contour lines on procedural terrain. Supports click-to-add levels, scroll density control, filled contours, hillshade toggle, contour labels, index contours, and colour scheme cycling.
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.
Summary
contours()function for extracting isolines from 2D rasters using marching squares@ngjitkernel), Dask+NumPy (chunked viada.overlap), CuPy and Dask+CuPy (CPU fallback, same approach aspolygonize)polygonizeChanges
xrspatial/contour.py-- marching squares kernel, four backend functions, segment stitcher, publiccontours()APIxrspatial/tests/test_contour.py-- 22 tests: correctness, NaN handling, edge cases, backend equivalence, GeoDataFrame output, accessor integrationexamples/user_guide/22_Contour_Lines.ipynb-- user guide notebook with terrain generation, contour extraction, hillshade overlay__init__.py,accessor.py-- exports and.xrs.contours()accessordocs/source/reference/utilities.rst-- API docs entryREADME.md-- feature matrix rowTest plan
pytest xrspatial/tests/test_contour.py-- 21 passed, 1 skipped (skimage reference test, skimage not installed)Closes #964