Skip to content

@turf/isobands and @turf/isolines check pointGrid input is actually gridded already#2927

Merged
mfedderly merged 3 commits intomasterfrom
mf/iso-check-matrix-dimensions
Aug 31, 2025
Merged

@turf/isobands and @turf/isolines check pointGrid input is actually gridded already#2927
mfedderly merged 3 commits intomasterfrom
mf/iso-check-matrix-dimensions

Conversation

@mfedderly
Copy link
Collaborator

We were seeing some issues filed around these methods not working as expected. After looking at the data it appears that the pointGrid input is not always evenly spaced gridded points. When this happens gridToMatrix() results in an unusable result. The matrix is either not large enough to ever make any cells for marchingsquares, or of inconsistent dimensions due to not reusing the same latitudes across points (even just a slight discrepancy in the values will cause an issue).

This adds explicit checks for this condition, and slightly clarifies the docs on what we're expecting to be passed in. I'm open to improvements in the wording here for clarity.

Fixes #2509, #2081

*
* @function
* @param {FeatureCollection<Point>} pointGrid input points - must be square or rectangular
* @param {FeatureCollection<Point>} pointGrid input points - must be square or rectangular and already gridded
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a clearer way to express this? Maybe cribbing from the comment where we actually do the check:

must be square or rectangular, and already gridded. That is, have consistent x and y dimensions, and be at least 2x2 in size.


// Isoline methods
const matrix = gridToMatrix(pointGrid, { zProperty: zProperty, flip: true });

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do really need to find a way to share common code internally 😅

@mfedderly mfedderly merged commit 3c31d5e into master Aug 31, 2025
3 checks passed
@mfedderly mfedderly deleted the mf/iso-check-matrix-dimensions branch August 31, 2025 17:31
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.

@turf/isobands-In some cases, calculations can lead to dead cycles

2 participants