diff --git a/packages/turf-flip/index.ts b/packages/turf-flip/index.ts index ba53101a27..3dcdb212bc 100644 --- a/packages/turf-flip/index.ts +++ b/packages/turf-flip/index.ts @@ -1,5 +1,5 @@ import { coordEach } from "@turf/meta"; -import { isObject, AllGeoJSON } from "@turf/helpers"; +import { isObject, AllGeoJSON, removeBbox } from "@turf/helpers"; import { clone } from "@turf/clone"; /** @@ -41,6 +41,7 @@ function flip( coord[0] = y; coord[1] = x; }); + removeBbox(geojson); return geojson; } diff --git a/packages/turf-flip/test.ts b/packages/turf-flip/test.ts index e299e81361..cc70a496aa 100644 --- a/packages/turf-flip/test.ts +++ b/packages/turf-flip/test.ts @@ -44,3 +44,15 @@ test("turf-flip - handle input mutation", (t) => { t.deepEqual(geojson, point([40, 120]), "does mutate input"); t.end(); }); + +test("turf-flip - removes stale bbox", (t) => { + const input = point([120, 40], {}, { bbox: [120, 40, 120, 40] }); + const output = flip(input); + + t.equal(output.bbox, undefined, "removes bbox from cloned output"); + t.deepEqual(input.bbox, [120, 40, 120, 40], "preserves cloned input"); + + flip(input, { mutate: true }); + t.equal(input.bbox, undefined, "removes bbox from mutated input"); + t.end(); +}); diff --git a/packages/turf-nearest-neighbor-analysis/test/out/brazil-states-bbox.json b/packages/turf-nearest-neighbor-analysis/test/out/brazil-states-bbox.json index b45d0eb231..7e95793471 100644 --- a/packages/turf-nearest-neighbor-analysis/test/out/brazil-states-bbox.json +++ b/packages/turf-nearest-neighbor-analysis/test/out/brazil-states-bbox.json @@ -820,9 +820,6 @@ }, { "type": "Feature", - "bbox": [ - -73.88208407352717, -33.263575673419844, -34.71777637301956, 5.402352713825728 - ], "properties": { "fill-opacity": 0, "stroke-width": 5, diff --git a/packages/turf-nearest-neighbor-analysis/test/out/random-outlier.json b/packages/turf-nearest-neighbor-analysis/test/out/random-outlier.json index 5425cbb31f..04a2fd6536 100644 --- a/packages/turf-nearest-neighbor-analysis/test/out/random-outlier.json +++ b/packages/turf-nearest-neighbor-analysis/test/out/random-outlier.json @@ -1211,7 +1211,6 @@ }, { "type": "Feature", - "bbox": [-15, 38.10372140158265, -8.900609997813907, 45], "properties": { "fill-opacity": 0, "stroke-width": 5, diff --git a/packages/turf-nearest-neighbor-analysis/test/out/random.json b/packages/turf-nearest-neighbor-analysis/test/out/random.json index ca8b0b8ec9..0414bd44bb 100644 --- a/packages/turf-nearest-neighbor-analysis/test/out/random.json +++ b/packages/turf-nearest-neighbor-analysis/test/out/random.json @@ -1203,9 +1203,6 @@ }, { "type": "Feature", - "bbox": [ - -9.29867379414539, 38.10372140158265, -8.900609997813907, 38.49492542236455 - ], "properties": { "fill-opacity": 0, "stroke-width": 5, diff --git a/packages/turf-nearest-neighbor-analysis/test/out/squares.json b/packages/turf-nearest-neighbor-analysis/test/out/squares.json index e38b42685d..c8c969839b 100644 --- a/packages/turf-nearest-neighbor-analysis/test/out/squares.json +++ b/packages/turf-nearest-neighbor-analysis/test/out/squares.json @@ -1459,9 +1459,6 @@ }, { "type": "Feature", - "bbox": [ - -9.299992605418552, 38.12013592725509, -8.900007394581449, 38.47986407274493 - ], "properties": { "fill-opacity": 0, "stroke-width": 5, diff --git a/packages/turf-projection/index.ts b/packages/turf-projection/index.ts index d07e24ca27..10c9a4212c 100644 --- a/packages/turf-projection/index.ts +++ b/packages/turf-projection/index.ts @@ -1,6 +1,6 @@ import { Position } from "geojson"; import { coordEach } from "@turf/meta"; -import { AllGeoJSON, isNumber } from "@turf/helpers"; +import { AllGeoJSON, isNumber, removeBbox } from "@turf/helpers"; import { clone } from "@turf/clone"; /** @@ -88,6 +88,7 @@ function convert( coord[0] = newCoord[0]; coord[1] = newCoord[1]; }); + removeBbox(geojson); } return geojson; } diff --git a/packages/turf-projection/test.ts b/packages/turf-projection/test.ts index 2a6151c8d3..f0476cc4aa 100644 --- a/packages/turf-projection/test.ts +++ b/packages/turf-projection/test.ts @@ -129,3 +129,46 @@ test("projection -- handle Position", (t) => { t.deepEqual(coord, wgs84, "coord equal same as wgs84"); t.end(); }); + +test("projection -- removes stale bbox", (t) => { + const mercatorInput = point([10, 10], {}, { bbox: [10, 10, 10, 10] }); + const mercatorOutput = toMercator(mercatorInput); + + t.equal( + mercatorOutput.bbox, + undefined, + "toMercator removes bbox from cloned output" + ); + t.deepEqual( + mercatorInput.bbox, + [10, 10, 10, 10], + "toMercator preserves cloned input" + ); + + toMercator(mercatorInput, { mutate: true }); + t.equal( + mercatorInput.bbox, + undefined, + "toMercator removes bbox from mutated input" + ); + + const wgs84Input = point( + [1113194.9, 1118890], + {}, + { bbox: [1113194.9, 1118890, 1113194.9, 1118890] } + ); + const wgs84Output = toWgs84(wgs84Input); + + t.equal( + wgs84Output.bbox, + undefined, + "toWgs84 removes bbox from cloned output" + ); + toWgs84(wgs84Input, { mutate: true }); + t.equal( + wgs84Input.bbox, + undefined, + "toWgs84 removes bbox from mutated input" + ); + t.end(); +}); diff --git a/packages/turf-truncate/index.ts b/packages/turf-truncate/index.ts index fba1490ffd..d1d09024b8 100644 --- a/packages/turf-truncate/index.ts +++ b/packages/turf-truncate/index.ts @@ -1,5 +1,5 @@ import { coordEach } from "@turf/meta"; -import { AllGeoJSON, isObject } from "@turf/helpers"; +import { AllGeoJSON, isObject, removeBbox } from "@turf/helpers"; /** * Takes a GeoJSON Feature or FeatureCollection and truncates the precision of the geometry. @@ -66,6 +66,7 @@ function truncate( coordEach(geojson, function (coords) { truncateCoords(coords, factor, coordinates!); }); + removeBbox(geojson); return geojson; } diff --git a/packages/turf-truncate/test.ts b/packages/turf-truncate/test.ts index 74c920d022..8007c7afbd 100644 --- a/packages/turf-truncate/test.ts +++ b/packages/turf-truncate/test.ts @@ -76,3 +76,23 @@ test("turf-truncate - prevent input mutation", (t) => { t.deepEqual(pt, point([120, 40]), "does mutate input"); t.end(); }); + +test("turf-truncate - removes stale bbox", (t) => { + const input = point( + [120.123, 40.123], + {}, + { bbox: [120.123, 40.123, 120.123, 40.123] } + ); + const output = truncate(input, { precision: 0 }); + + t.equal(output.bbox, undefined, "removes bbox from cloned output"); + t.deepEqual( + input.bbox, + [120.123, 40.123, 120.123, 40.123], + "preserves cloned input" + ); + + truncate(input, { precision: 0, mutate: true }); + t.equal(input.bbox, undefined, "removes bbox from mutated input"); + t.end(); +}); diff --git a/packages/turf-truncate/test/out/point.geojson b/packages/turf-truncate/test/out/point.geojson index 951413affc..92b2724253 100644 --- a/packages/turf-truncate/test/out/point.geojson +++ b/packages/turf-truncate/test/out/point.geojson @@ -4,7 +4,6 @@ "precision": 3 }, "id": 12345, - "bbox": [1, 2, 3, 4], "geometry": { "type": "Point", "coordinates": [-75.7, 45.425]