Skip to content

Commit

Permalink
added support for coords
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielJDufour committed Jun 11, 2023
1 parent 517e02c commit 7a806c7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
9 changes: 6 additions & 3 deletions mpoly.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const getDepth = require("get-depth");
const meta = require("@turf/meta");
const booleanClockwise = require("@turf/boolean-clockwise").default;

Expand Down Expand Up @@ -33,13 +34,15 @@ function each(geom, callback) {
}
});
} else if (Array.isArray(geom)) {
const depth = getDepth(geojson);
const depth = getDepth(geom);
if (depth === 4) {
it.forEach(polygon => {
geom.forEach(polygon => {
callback(polygon);
});
} else if (depth === 3) {
callback(it);
callback(geom);
} else if (depth === 2) {
callback([geom]);
}
}
}
Expand Down
21 changes: 20 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,29 @@ const { Example, GeometryCollection, LineString, MultiPoint, MultiLineString, Mu

test("mpoly.get (arcgis)", ({ eq }) => {
Object.entries(arcgisjsons).forEach(([name, data]) => {
eq(mpoly.get(arcgisjsons[name]), mpoly.get(geojsons[name]));
const results = new Set();
results.add(JSON.stringify(mpoly.get(geojsons[name])));
results.add(JSON.stringify(mpoly.get(JSON.stringify(geojsons[name]))));
results.add(JSON.stringify(mpoly.get(arcgisjsons[name])));
results.add(JSON.stringify(mpoly.get(JSON.stringify(arcgisjsons[name]))));
eq(results.size, 1);
});
});

test("coords", ({ eq }) => {
const coords = [
[100, 0],
[101, 0],
[101, 1],
[100, 1],
[100, 0]
];
const expected = [[coords]];
eq(mpoly.get(coords), expected);
eq(mpoly.get([coords]), expected);
eq(mpoly.get([[coords]]), expected);
});

test("mpoly.get (geojson)", ({ eq }) => {
eq(mpoly.get(Example), [
[
Expand Down

0 comments on commit 7a806c7

Please sign in to comment.