diff --git a/packages/turf-isolines/index.ts b/packages/turf-isolines/index.ts index 077701467d..6ed03bfd02 100644 --- a/packages/turf-isolines/index.ts +++ b/packages/turf-isolines/index.ts @@ -104,7 +104,7 @@ function createIsoLines( breaksProperties: GeoJsonProperties[] ): Feature[] { const results = []; - for (let i = 1; i < breaks.length; i++) { + for (let i = 0; i < breaks.length; i++) { const threshold = +breaks[i]; // make sure it's a number const properties = { ...commonProperties, ...breaksProperties[i] }; diff --git a/packages/turf-isolines/test.js b/packages/turf-isolines/test.js index d0d545271f..5f9bf4658e 100644 --- a/packages/turf-isolines/test.js +++ b/packages/turf-isolines/test.js @@ -55,6 +55,39 @@ test("isolines", (t) => { t.end(); }); +test("isolines - skipping first break, from issue #2129", (t) => { + const points = pointGrid([0, 10, 20, 30], 100); + for (var i = 0; i < points.features.length; i++) { + points.features[i].properties.temperature = Math.random() * 12; + } + + const breaks = [5, 10]; + + const lines = isolines(points, breaks, { + zProperty: "temperature", + breaksProperties: [ + { name: "break5", stroke: "#F00" }, + { name: "break10", stroke: "#0F0" }, + ], + }); + + lines.features.push( + lineString(getCoords(envelope(points))[0], { + description: "Debug line for testing", + stroke: "#F00", + "stroke-width": 1, + }) + ); + + // Make sure an isoline is created for each break, and that it's + // geometry isn't empty. + t.equal(lines.features[0].properties.name, "break5"); + t.assert(lines.features[0].geometry.coordinates[0].length > 1); + t.equal(lines.features[1].properties.name, "break10"); + t.assert(lines.features[1].geometry.coordinates[0].length > 1); + t.end(); +}); + test("isolines -- throws", (t) => { const points = pointGrid([-70.823364, -33.553984, -70.473175, -33.302986], 5); @@ -92,7 +125,7 @@ test("isolines -- handling properties", (t) => { commonProperties: commonProperties, breaksProperties: breaksProperties, }); - t.equal(lines.features[0].properties.name, "break2"); + t.equal(lines.features[0].properties.name, "break1"); t.equal(lines.features[0].properties.source, "foobar"); t.end(); }); diff --git a/packages/turf-isolines/test/in/bigMatrix.json b/packages/turf-isolines/test/in/bigMatrix.json index a526167eb4..6638fae307 100644 --- a/packages/turf-isolines/test/in/bigMatrix.json +++ b/packages/turf-isolines/test/in/bigMatrix.json @@ -1,7 +1,7 @@ { "origin": [6.5, 46], "cellSize": 10, - "breaks": [0, 0.24, 0.5, 1.5, 2.5, 100], + "breaks": [0.24, 0.5, 1.5, 2.5, 100], "zProperty": "pressure", "commonProperties": { "stroke-width": 4, diff --git a/packages/turf-isolines/test/in/matrix2.json b/packages/turf-isolines/test/in/matrix2.json index 937a5a0175..491a446c38 100644 --- a/packages/turf-isolines/test/in/matrix2.json +++ b/packages/turf-isolines/test/in/matrix2.json @@ -12,7 +12,7 @@ ], "origin": [10.85, 44], "cellSize": 20, - "breaks": [0, 4.5, 9, 13.5, 18], + "breaks": [4.5, 9, 13.5, 18], "commonProperties": { "stroke-width": 3, "stroke": "darkred", diff --git a/packages/turf-isolines/test/in/pointGrid.geojson b/packages/turf-isolines/test/in/pointGrid.geojson index 654238762b..f5536d41ce 100644 --- a/packages/turf-isolines/test/in/pointGrid.geojson +++ b/packages/turf-isolines/test/in/pointGrid.geojson @@ -1,7 +1,7 @@ { "type": "FeatureCollection", "properties": { - "breaks": [0, 20, 40, 80, 160], + "breaks": [20, 40, 80, 160], "breaksProperties": [ { "fill-opacity": 0.5 diff --git a/packages/turf-isolines/test/out/bigMatrix.geojson b/packages/turf-isolines/test/out/bigMatrix.geojson index bd5e9245ec..529690781b 100644 --- a/packages/turf-isolines/test/out/bigMatrix.geojson +++ b/packages/turf-isolines/test/out/bigMatrix.geojson @@ -6,8 +6,8 @@ "properties": { "stroke-width": 4, "fill-opacity": 0.4, - "stroke": "blue", - "fill": "blue", + "stroke": "grey", + "fill": "grey", "pressure": 0.24 }, "geometry": { @@ -265,8 +265,8 @@ "properties": { "stroke-width": 4, "fill-opacity": 0.4, - "stroke": "green", - "fill": "green", + "stroke": "blue", + "fill": "blue", "pressure": 0.5 }, "geometry": { @@ -620,8 +620,8 @@ "properties": { "stroke-width": 4, "fill-opacity": 0.4, - "stroke": "yellow", - "fill": "yellow", + "stroke": "green", + "fill": "green", "pressure": 1.5 }, "geometry": { @@ -964,8 +964,8 @@ "properties": { "stroke-width": 4, "fill-opacity": 0.4, - "stroke": "red", - "fill": "red", + "stroke": "yellow", + "fill": "yellow", "pressure": 2.5 }, "geometry": { @@ -1162,12 +1162,11 @@ "properties": { "stroke-width": 4, "fill-opacity": 0.4, + "stroke": "red", + "fill": "red", "pressure": 100 }, - "geometry": { - "type": "MultiLineString", - "coordinates": [] - } + "geometry": { "type": "MultiLineString", "coordinates": [] } }, { "type": "Feature", diff --git a/packages/turf-isolines/test/out/matrix1.geojson b/packages/turf-isolines/test/out/matrix1.geojson index e245719583..b67dfba6ac 100644 --- a/packages/turf-isolines/test/out/matrix1.geojson +++ b/packages/turf-isolines/test/out/matrix1.geojson @@ -3,9 +3,37 @@ "features": [ { "type": "Feature", - "properties": { - "temperature": 4 - }, + "properties": { "temperature": 2 }, + "geometry": { + "type": "MultiLineString", + "coordinates": [ + [ + [10.863591, 44.279864], + [11.054363, 44.144966], + [11.308726, 44.144966], + [11.56309, 44.144966], + [11.817453, 44.144966], + [12.071816, 44.144966], + [12.262588, 44.279864], + [12.262588, 44.459728], + [12.262588, 44.639592], + [12.262588, 44.819456], + [12.071816, 44.954354], + [11.817453, 44.954354], + [11.56309, 44.954354], + [11.308726, 44.954354], + [11.054363, 44.954354], + [10.863591, 44.819456], + [10.863591, 44.639592], + [10.863591, 44.459728], + [10.863591, 44.279864] + ] + ] + } + }, + { + "type": "Feature", + "properties": { "temperature": 4 }, "geometry": { "type": "MultiLineString", "coordinates": [ @@ -35,9 +63,7 @@ }, { "type": "Feature", - "properties": { - "temperature": 8 - }, + "properties": { "temperature": 8 }, "geometry": { "type": "MultiLineString", "coordinates": [ @@ -59,9 +85,7 @@ }, { "type": "Feature", - "properties": { - "temperature": 12 - }, + "properties": { "temperature": 12 }, "geometry": { "type": "MultiLineString", "coordinates": [ diff --git a/packages/turf-isolines/test/out/matrix2.geojson b/packages/turf-isolines/test/out/matrix2.geojson index 6d9c5ed85e..6e09eb3644 100644 --- a/packages/turf-isolines/test/out/matrix2.geojson +++ b/packages/turf-isolines/test/out/matrix2.geojson @@ -7,7 +7,7 @@ "stroke-width": 3, "stroke": "darkred", "fill": "darkred", - "fill-opacity": 0.5, + "fill-opacity": 0.4, "elevation": 4.5 }, "geometry": { @@ -56,7 +56,7 @@ "stroke-width": 3, "stroke": "darkred", "fill": "darkred", - "fill-opacity": 0.7, + "fill-opacity": 0.5, "elevation": 9 }, "geometry": { @@ -105,7 +105,7 @@ "stroke-width": 3, "stroke": "darkred", "fill": "darkred", - "fill-opacity": 0.8, + "fill-opacity": 0.7, "elevation": 13.5 }, "geometry": { @@ -136,6 +136,7 @@ "stroke-width": 3, "stroke": "darkred", "fill": "darkred", + "fill-opacity": 0.8, "elevation": 18 }, "geometry": { diff --git a/packages/turf-isolines/test/out/pointGrid.geojson b/packages/turf-isolines/test/out/pointGrid.geojson index 9d55c33376..24faca3dcd 100644 --- a/packages/turf-isolines/test/out/pointGrid.geojson +++ b/packages/turf-isolines/test/out/pointGrid.geojson @@ -3,10 +3,7 @@ "features": [ { "type": "Feature", - "properties": { - "fill-opacity": 0.6, - "population": 20 - }, + "properties": { "fill-opacity": 0.5, "population": 20 }, "geometry": { "type": "MultiLineString", "coordinates": [ @@ -66,10 +63,7 @@ }, { "type": "Feature", - "properties": { - "fill-opacity": 0.7, - "population": 40 - }, + "properties": { "fill-opacity": 0.6, "population": 40 }, "geometry": { "type": "MultiLineString", "coordinates": [ @@ -133,10 +127,7 @@ }, { "type": "Feature", - "properties": { - "fill-opacity": 0.8, - "population": 80 - }, + "properties": { "fill-opacity": 0.7, "population": 80 }, "geometry": { "type": "MultiLineString", "coordinates": [ @@ -162,13 +153,8 @@ }, { "type": "Feature", - "properties": { - "population": 160 - }, - "geometry": { - "type": "MultiLineString", - "coordinates": [] - } + "properties": { "fill-opacity": 0.8, "population": 160 }, + "geometry": { "type": "MultiLineString", "coordinates": [] } }, { "type": "Feature",