Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@turf/boolean-contains - support for multipolygon inside polygon #2357

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions packages/turf-boolean-contains/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ export default function booleanContains(
return isPolyInPoly(geom1, geom2);
case "MultiPoint":
return isMultiPointInPoly(geom1, geom2);
case "MultiPolygon":
return isMultiPolyInPoly(geom1, geom2);
default:
throw new Error("feature2 " + type2 + " geometry not supported");
}
Expand All @@ -103,6 +105,15 @@ export function isPolygonInMultiPolygon(
);
}

export function isMultiPolyInPoly(
polygon: Polygon,
multiPolygon: MultiPolygon
) {
return multiPolygon.coordinates.every((coords) =>
isPolyInPoly(polygon, { type: "Polygon", coordinates: coords })
);
}

export function isPointInMultiPoint(multiPoint: MultiPoint, pt: Point) {
let i;
let output = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[5.697231218450497, 39.505906288651715],
[5.697231218450497, 40.50986523812119],
[4.30801420435526, 40.50986523812119],
[4.30801420435526, 39.505906288651715],
[5.697231218450497, 39.505906288651715]
]
]
}
},
{
"type": "Feature",
"properties": null,
"geometry": {
"type": "MultiPolygon",
"coordinates": [
[
[
[3.6968994140625, 39.65645604812829],
[4.622497558593749, 39.65645604812829],
[4.622497558593749, 40.168380093142446],
[3.6968994140625, 40.168380093142446],
[3.6968994140625, 39.65645604812829]
]
],
[
[
[4.73236083984375, 39.69450749856091],
[5.416259765624999, 39.69450749856091],
[5.416259765624999, 40.386304853509046],
[4.73236083984375, 40.386304853509046],
[4.73236083984375, 39.69450749856091]
]
]
]
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[5.860668514226688, 40.60423664824944],
[3.248940527728166, 40.60423664824944],
[3.248940527728166, 39.35441976583036],
[5.860668514226688, 39.35441976583036],
[5.860668514226688, 40.60423664824944]
]
]
}
},
{
"type": "Feature",
"properties": null,
"geometry": {
"type": "MultiPolygon",
"coordinates": [
[
[
[3.6968994140625, 39.65645604812829],
[4.622497558593749, 39.65645604812829],
[4.622497558593749, 40.168380093142446],
[3.6968994140625, 40.168380093142446],
[3.6968994140625, 39.65645604812829]
]
],
[
[
[4.73236083984375, 39.69450749856091],
[5.416259765624999, 39.69450749856091],
[5.416259765624999, 40.386304853509046],
[4.73236083984375, 40.386304853509046],
[4.73236083984375, 39.69450749856091]
]
]
]
}
}
]
}