Skip to content

Commit c04c67b

Browse files
authored
Clean up isobands output for empty bands (#2957)
- Bands that are above the highest data in the grid will no longer incorrectly emit a polygon that contains the entire grid Fixes #2956
1 parent d2b0704 commit c04c67b

File tree

3 files changed

+642
-4
lines changed

3 files changed

+642
-4
lines changed

packages/turf-isobands/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,14 @@ function createContourLines(
160160
const orderedRings = orderByArea(rings);
161161
const polygons = groupNestedRings(orderedRings);
162162

163-
// If we got no polygons, we can infer that the values are either all above or all below the threshold.
164-
// If everything is below, we shold add the entire bounding box as a polygon.
165-
// see https://github.com/Turfjs/turf/issues/1797
166-
if (polygons.length === 0 && matrix[0][0] < upperBand) {
163+
// If we got no polygons, we can infer that the values are either all above, below, or between the thresholds.
164+
// If everything is between, we need a polygon that covers the entire grid
165+
// see https://github.com/Turfjs/turf/issues/1797, https://github.com/Turfjs/turf/issues/2956
166+
if (
167+
polygons.length === 0 &&
168+
matrix[0][0] < upperBand &&
169+
matrix[0][0] >= lowerBand
170+
) {
167171
const dx = matrix[0].length;
168172
const dy = matrix.length;
169173
polygons.push([
@@ -177,6 +181,7 @@ function createContourLines(
177181
]);
178182
}
179183

184+
// this can add an entry where groupedRings is exactly an empty array
180185
contours.push({
181186
groupedRings: polygons,
182187
[property]: lowerBand + "-" + upperBand,

0 commit comments

Comments
 (0)