Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/turf-flip/index.ts
Original file line number Diff line number Diff line change
@@ -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";

/**
Expand Down Expand Up @@ -41,6 +41,7 @@ function flip<T extends AllGeoJSON>(
coord[0] = y;
coord[1] = x;
});
removeBbox(geojson);
return geojson;
}

Expand Down
12 changes: 12 additions & 0 deletions packages/turf-flip/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Original file line number Diff line number Diff line change
Expand Up @@ -820,9 +820,6 @@
},
{
"type": "Feature",
"bbox": [
-73.88208407352717, -33.263575673419844, -34.71777637301956, 5.402352713825728
],
"properties": {
"fill-opacity": 0,
"stroke-width": 5,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,6 @@
},
{
"type": "Feature",
"bbox": [-15, 38.10372140158265, -8.900609997813907, 45],
"properties": {
"fill-opacity": 0,
"stroke-width": 5,
Expand Down
3 changes: 0 additions & 3 deletions packages/turf-nearest-neighbor-analysis/test/out/random.json
Original file line number Diff line number Diff line change
Expand Up @@ -1203,9 +1203,6 @@
},
{
"type": "Feature",
"bbox": [
-9.29867379414539, 38.10372140158265, -8.900609997813907, 38.49492542236455
],
"properties": {
"fill-opacity": 0,
"stroke-width": 5,
Expand Down
3 changes: 0 additions & 3 deletions packages/turf-nearest-neighbor-analysis/test/out/squares.json
Original file line number Diff line number Diff line change
Expand Up @@ -1459,9 +1459,6 @@
},
{
"type": "Feature",
"bbox": [
-9.299992605418552, 38.12013592725509, -8.900007394581449, 38.47986407274493
],
"properties": {
"fill-opacity": 0,
"stroke-width": 5,
Expand Down
3 changes: 2 additions & 1 deletion packages/turf-projection/index.ts
Original file line number Diff line number Diff line change
@@ -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";

/**
Expand Down Expand Up @@ -88,6 +88,7 @@ function convert(
coord[0] = newCoord[0];
coord[1] = newCoord[1];
});
removeBbox(geojson);
}
return geojson;
}
Expand Down
43 changes: 43 additions & 0 deletions packages/turf-projection/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
3 changes: 2 additions & 1 deletion packages/turf-truncate/index.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -66,6 +66,7 @@ function truncate<T extends AllGeoJSON>(
coordEach(geojson, function (coords) {
truncateCoords(coords, factor, coordinates!);
});
removeBbox(geojson);
return geojson;
}

Expand Down
20 changes: 20 additions & 0 deletions packages/turf-truncate/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
1 change: 0 additions & 1 deletion packages/turf-truncate/test/out/point.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"precision": 3
},
"id": 12345,
"bbox": [1, 2, 3, 4],
"geometry": {
"type": "Point",
"coordinates": [-75.7, 45.425]
Expand Down
Loading