diff --git a/packages/turf-boolean-contains/index.ts b/packages/turf-boolean-contains/index.ts index 1c5c177e5c..f3b686b83e 100644 --- a/packages/turf-boolean-contains/index.ts +++ b/packages/turf-boolean-contains/index.ts @@ -3,6 +3,7 @@ import { Feature, Geometry, LineString, + MultiLineString, MultiPoint, MultiPolygon, Point, @@ -87,8 +88,18 @@ function booleanContains( } case "MultiPolygon": switch (type2) { + case "Point": + return isPointInMultiPolygon(geom1, geom2); + case "MultiPoint": + return isMultiPointInMultiPolygon(geom1, geom2); + case "LineString": + return isLineInMultiPolygon(geom1, geom2); + case "MultiLineString": + return isMultiLineStringInMultiPolygon(geom1, geom2); case "Polygon": return isPolygonInMultiPolygon(geom1, geom2); + case "MultiPolygon": + return isMultiPolygonInMultiPolygon(geom1, geom2); default: throw new Error("feature2 " + type2 + " geometry not supported"); } @@ -103,6 +114,122 @@ function isPolygonInMultiPolygon(multiPolygon: MultiPolygon, polygon: Polygon) { ); } +/** + * Is Point inside MultiPolygon + * + * @private + * @param {MultiPolygon} multiPolygon MultiPolygon geometry + * @param {Point} point Point geometry + * @returns {boolean} true if point is inside the interior of any polygon in the MultiPolygon + */ +function isPointInMultiPolygon(multiPolygon: MultiPolygon, point: Point) { + return multiPolygon.coordinates.some((coords) => + booleanPointInPolygon( + point, + { type: "Polygon", coordinates: coords }, + { + ignoreBoundary: true, + } + ) + ); +} + +/** + * Is MultiPoint inside MultiPolygon + * + * @private + * @param {MultiPolygon} multiPolygon MultiPolygon geometry + * @param {MultiPoint} multiPoint MultiPoint geometry + * @returns {boolean} true if every point is inside the interior of some polygon in the MultiPolygon + */ +function isMultiPointInMultiPolygon( + multiPolygon: MultiPolygon, + multiPoint: MultiPoint +) { + for (const coord of multiPoint.coordinates) { + const pointInside = multiPolygon.coordinates.some((polyCoords) => + booleanPointInPolygon( + coord, + { type: "Polygon", coordinates: polyCoords }, + { ignoreBoundary: true } + ) + ); + if (!pointInside) { + return false; + } + } + return true; +} + +/** + * Is LineString inside MultiPolygon + * + * @private + * @param {MultiPolygon} multiPolygon MultiPolygon geometry + * @param {LineString} lineString LineString geometry + * @returns {boolean} true if the LineString is fully contained within a single polygon of the MultiPolygon + */ +function isLineInMultiPolygon( + multiPolygon: MultiPolygon, + lineString: LineString +) { + return multiPolygon.coordinates.some((coords) => + isLineInPoly({ type: "Polygon", coordinates: coords }, lineString) + ); +} + +/** + * Is MultiLineString inside MultiPolygon + * + * @private + * @param {MultiPolygon} multiPolygon MultiPolygon geometry + * @param {MultiLineString} multiLineString MultiLineString geometry + * @returns {boolean} true if every LineString is fully contained within some single polygon of the MultiPolygon + */ +function isMultiLineStringInMultiPolygon( + multiPolygon: MultiPolygon, + multiLineString: MultiLineString +) { + for (const lineCoords of multiLineString.coordinates) { + const lineInside = multiPolygon.coordinates.some((polyCoords) => + isLineInPoly( + { type: "Polygon", coordinates: polyCoords }, + { type: "LineString", coordinates: lineCoords } + ) + ); + if (!lineInside) { + return false; + } + } + return true; +} + +/** + * Is MultiPolygon inside MultiPolygon + * + * @private + * @param {MultiPolygon} multiPolygon1 MultiPolygon geometry (container) + * @param {MultiPolygon} multiPolygon2 MultiPolygon geometry (contained) + * @returns {boolean} true if every polygon of multiPolygon2 is fully contained within some single polygon of multiPolygon1 + */ +function isMultiPolygonInMultiPolygon( + multiPolygon1: MultiPolygon, + multiPolygon2: MultiPolygon +) { + for (const poly2Coords of multiPolygon2.coordinates) { + const polyInside = multiPolygon1.coordinates.some((poly1Coords) => + isPolyInPoly( + { type: "Polygon", coordinates: poly1Coords }, + { type: "Polygon", coordinates: poly2Coords } + ) + ); + if (!polyInside) { + return false; + } + } + return true; +} + function isMultiPolyInPoly(polygon: Polygon, multiPolygon: MultiPolygon) { return multiPolygon.coordinates.every((coords) => isPolyInPoly(polygon, { type: "Polygon", coordinates: coords }) diff --git a/packages/turf-boolean-contains/package.json b/packages/turf-boolean-contains/package.json index 26a9d73bc1..998464cba9 100644 --- a/packages/turf-boolean-contains/package.json +++ b/packages/turf-boolean-contains/package.json @@ -6,7 +6,8 @@ "contributors": [ "Rowan Winsemius <@rowanwins>", "Denis Carriere <@DenisCarriere>", - "Samuel Arbibe <@samuelarbibe>" + "Samuel Arbibe <@samuelarbibe>", + "Espen Hovlandsdal <@rexxars>" ], "license": "MIT", "bugs": { diff --git a/packages/turf-boolean-contains/test/false/MultiPolygon/LineString/LineStringOnBoundary.geojson b/packages/turf-boolean-contains/test/false/MultiPolygon/LineString/LineStringOnBoundary.geojson new file mode 100644 index 0000000000..047ffb094d --- /dev/null +++ b/packages/turf-boolean-contains/test/false/MultiPolygon/LineString/LineStringOnBoundary.geojson @@ -0,0 +1,43 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0] + ] + ], + [ + [ + [20, 0], + [30, 0], + [30, 10], + [20, 10], + [20, 0] + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [ + [0, 2], + [0, 8] + ] + } + } + ] +} diff --git a/packages/turf-boolean-contains/test/false/MultiPolygon/LineString/LineStringOutside.geojson b/packages/turf-boolean-contains/test/false/MultiPolygon/LineString/LineStringOutside.geojson new file mode 100644 index 0000000000..3e32532ec0 --- /dev/null +++ b/packages/turf-boolean-contains/test/false/MultiPolygon/LineString/LineStringOutside.geojson @@ -0,0 +1,43 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0] + ] + ], + [ + [ + [20, 0], + [30, 0], + [30, 10], + [20, 10], + [20, 0] + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [ + [12, 5], + [18, 5] + ] + } + } + ] +} diff --git a/packages/turf-boolean-contains/test/false/MultiPolygon/LineString/LineStringSpanningBothPolygons.geojson b/packages/turf-boolean-contains/test/false/MultiPolygon/LineString/LineStringSpanningBothPolygons.geojson new file mode 100644 index 0000000000..55f33ae145 --- /dev/null +++ b/packages/turf-boolean-contains/test/false/MultiPolygon/LineString/LineStringSpanningBothPolygons.geojson @@ -0,0 +1,43 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0] + ] + ], + [ + [ + [20, 0], + [30, 0], + [30, 10], + [20, 10], + [20, 0] + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [ + [5, 5], + [25, 5] + ] + } + } + ] +} diff --git a/packages/turf-boolean-contains/test/false/MultiPolygon/MultiLineString/MultiLineStringOneOutside.geojson b/packages/turf-boolean-contains/test/false/MultiPolygon/MultiLineString/MultiLineStringOneOutside.geojson new file mode 100644 index 0000000000..1193d54967 --- /dev/null +++ b/packages/turf-boolean-contains/test/false/MultiPolygon/MultiLineString/MultiLineStringOneOutside.geojson @@ -0,0 +1,49 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0] + ] + ], + [ + [ + [20, 0], + [30, 0], + [30, 10], + [20, 10], + [20, 0] + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiLineString", + "coordinates": [ + [ + [2, 2], + [8, 8] + ], + [ + [12, 2], + [18, 8] + ] + ] + } + } + ] +} diff --git a/packages/turf-boolean-contains/test/false/MultiPolygon/MultiLineString/MultiLineStringOneSpanningBoth.geojson b/packages/turf-boolean-contains/test/false/MultiPolygon/MultiLineString/MultiLineStringOneSpanningBoth.geojson new file mode 100644 index 0000000000..21fa4d4964 --- /dev/null +++ b/packages/turf-boolean-contains/test/false/MultiPolygon/MultiLineString/MultiLineStringOneSpanningBoth.geojson @@ -0,0 +1,49 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0] + ] + ], + [ + [ + [20, 0], + [30, 0], + [30, 10], + [20, 10], + [20, 0] + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiLineString", + "coordinates": [ + [ + [2, 2], + [8, 8] + ], + [ + [5, 5], + [25, 5] + ] + ] + } + } + ] +} diff --git a/packages/turf-boolean-contains/test/false/MultiPolygon/MultiPoint/MultiPointOneOnBoundary.geojson b/packages/turf-boolean-contains/test/false/MultiPolygon/MultiPoint/MultiPointOneOnBoundary.geojson new file mode 100644 index 0000000000..a875989ded --- /dev/null +++ b/packages/turf-boolean-contains/test/false/MultiPolygon/MultiPoint/MultiPointOneOnBoundary.geojson @@ -0,0 +1,43 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0] + ] + ], + [ + [ + [20, 0], + [30, 0], + [30, 10], + [20, 10], + [20, 0] + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPoint", + "coordinates": [ + [5, 5], + [0, 5] + ] + } + } + ] +} diff --git a/packages/turf-boolean-contains/test/false/MultiPolygon/MultiPoint/MultiPointOneOutside.geojson b/packages/turf-boolean-contains/test/false/MultiPolygon/MultiPoint/MultiPointOneOutside.geojson new file mode 100644 index 0000000000..4138681c9b --- /dev/null +++ b/packages/turf-boolean-contains/test/false/MultiPolygon/MultiPoint/MultiPointOneOutside.geojson @@ -0,0 +1,43 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0] + ] + ], + [ + [ + [20, 0], + [30, 0], + [30, 10], + [20, 10], + [20, 0] + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPoint", + "coordinates": [ + [5, 5], + [15, 5] + ] + } + } + ] +} diff --git a/packages/turf-boolean-contains/test/false/MultiPolygon/MultiPolygon/MultiPolygonOneOutside.geojson b/packages/turf-boolean-contains/test/false/MultiPolygon/MultiPolygon/MultiPolygonOneOutside.geojson new file mode 100644 index 0000000000..3f89b3be3d --- /dev/null +++ b/packages/turf-boolean-contains/test/false/MultiPolygon/MultiPolygon/MultiPolygonOneOutside.geojson @@ -0,0 +1,59 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0] + ] + ], + [ + [ + [20, 0], + [30, 0], + [30, 10], + [20, 10], + [20, 0] + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [2, 2], + [8, 2], + [8, 8], + [2, 8], + [2, 2] + ] + ], + [ + [ + [12, 2], + [18, 2], + [18, 8], + [12, 8], + [12, 2] + ] + ] + ] + } + } + ] +} diff --git a/packages/turf-boolean-contains/test/false/MultiPolygon/MultiPolygon/MultiPolygonSpanningBothPolygons.geojson b/packages/turf-boolean-contains/test/false/MultiPolygon/MultiPolygon/MultiPolygonSpanningBothPolygons.geojson new file mode 100644 index 0000000000..d04a6568be --- /dev/null +++ b/packages/turf-boolean-contains/test/false/MultiPolygon/MultiPolygon/MultiPolygonSpanningBothPolygons.geojson @@ -0,0 +1,50 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0] + ] + ], + [ + [ + [20, 0], + [30, 0], + [30, 10], + [20, 10], + [20, 0] + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [5, 2], + [25, 2], + [25, 8], + [5, 8], + [5, 2] + ] + ] + ] + } + } + ] +} diff --git a/packages/turf-boolean-contains/test/false/MultiPolygon/Point/PointOnBoundary.geojson b/packages/turf-boolean-contains/test/false/MultiPolygon/Point/PointOnBoundary.geojson new file mode 100644 index 0000000000..cd5d7da3c0 --- /dev/null +++ b/packages/turf-boolean-contains/test/false/MultiPolygon/Point/PointOnBoundary.geojson @@ -0,0 +1,40 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0] + ] + ], + [ + [ + [20, 0], + [30, 0], + [30, 10], + [20, 10], + [20, 0] + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [0, 5] + } + } + ] +} diff --git a/packages/turf-boolean-contains/test/false/MultiPolygon/Point/PointOutsideMultiPolygon.geojson b/packages/turf-boolean-contains/test/false/MultiPolygon/Point/PointOutsideMultiPolygon.geojson new file mode 100644 index 0000000000..bb64887ad0 --- /dev/null +++ b/packages/turf-boolean-contains/test/false/MultiPolygon/Point/PointOutsideMultiPolygon.geojson @@ -0,0 +1,40 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0] + ] + ], + [ + [ + [20, 0], + [30, 0], + [30, 10], + [20, 10], + [20, 0] + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [15, 5] + } + } + ] +} diff --git a/packages/turf-boolean-contains/test/true/MultiPolygon/LineString/LineStringInsideMultiPolygon.geojson b/packages/turf-boolean-contains/test/true/MultiPolygon/LineString/LineStringInsideMultiPolygon.geojson new file mode 100644 index 0000000000..26dffa2256 --- /dev/null +++ b/packages/turf-boolean-contains/test/true/MultiPolygon/LineString/LineStringInsideMultiPolygon.geojson @@ -0,0 +1,43 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0] + ] + ], + [ + [ + [20, 0], + [30, 0], + [30, 10], + [20, 10], + [20, 0] + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [ + [2, 2], + [8, 8] + ] + } + } + ] +} diff --git a/packages/turf-boolean-contains/test/true/MultiPolygon/LineString/LineStringInsideSecondPolygon.geojson b/packages/turf-boolean-contains/test/true/MultiPolygon/LineString/LineStringInsideSecondPolygon.geojson new file mode 100644 index 0000000000..f5ce9e11a4 --- /dev/null +++ b/packages/turf-boolean-contains/test/true/MultiPolygon/LineString/LineStringInsideSecondPolygon.geojson @@ -0,0 +1,43 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0] + ] + ], + [ + [ + [20, 0], + [30, 0], + [30, 10], + [20, 10], + [20, 0] + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [ + [22, 2], + [28, 8] + ] + } + } + ] +} diff --git a/packages/turf-boolean-contains/test/true/MultiPolygon/MultiLineString/MultiLineStringAllInSamePolygon.geojson b/packages/turf-boolean-contains/test/true/MultiPolygon/MultiLineString/MultiLineStringAllInSamePolygon.geojson new file mode 100644 index 0000000000..89a8d79d5d --- /dev/null +++ b/packages/turf-boolean-contains/test/true/MultiPolygon/MultiLineString/MultiLineStringAllInSamePolygon.geojson @@ -0,0 +1,49 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0] + ] + ], + [ + [ + [20, 0], + [30, 0], + [30, 10], + [20, 10], + [20, 0] + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiLineString", + "coordinates": [ + [ + [2, 2], + [5, 5] + ], + [ + [5, 5], + [8, 8] + ] + ] + } + } + ] +} diff --git a/packages/turf-boolean-contains/test/true/MultiPolygon/MultiLineString/MultiLineStringInsideMultiPolygon.geojson b/packages/turf-boolean-contains/test/true/MultiPolygon/MultiLineString/MultiLineStringInsideMultiPolygon.geojson new file mode 100644 index 0000000000..d603e53be0 --- /dev/null +++ b/packages/turf-boolean-contains/test/true/MultiPolygon/MultiLineString/MultiLineStringInsideMultiPolygon.geojson @@ -0,0 +1,49 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0] + ] + ], + [ + [ + [20, 0], + [30, 0], + [30, 10], + [20, 10], + [20, 0] + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiLineString", + "coordinates": [ + [ + [2, 2], + [8, 8] + ], + [ + [22, 2], + [28, 8] + ] + ] + } + } + ] +} diff --git a/packages/turf-boolean-contains/test/true/MultiPolygon/MultiPoint/MultiPointAllInSamePolygon.geojson b/packages/turf-boolean-contains/test/true/MultiPolygon/MultiPoint/MultiPointAllInSamePolygon.geojson new file mode 100644 index 0000000000..9fd4ea8cab --- /dev/null +++ b/packages/turf-boolean-contains/test/true/MultiPolygon/MultiPoint/MultiPointAllInSamePolygon.geojson @@ -0,0 +1,44 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0] + ] + ], + [ + [ + [20, 0], + [30, 0], + [30, 10], + [20, 10], + [20, 0] + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPoint", + "coordinates": [ + [2, 2], + [5, 5], + [8, 8] + ] + } + } + ] +} diff --git a/packages/turf-boolean-contains/test/true/MultiPolygon/MultiPoint/MultiPointInsideMultiPolygon.geojson b/packages/turf-boolean-contains/test/true/MultiPolygon/MultiPoint/MultiPointInsideMultiPolygon.geojson new file mode 100644 index 0000000000..8c439e48c3 --- /dev/null +++ b/packages/turf-boolean-contains/test/true/MultiPolygon/MultiPoint/MultiPointInsideMultiPolygon.geojson @@ -0,0 +1,43 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0] + ] + ], + [ + [ + [20, 0], + [30, 0], + [30, 10], + [20, 10], + [20, 0] + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPoint", + "coordinates": [ + [5, 5], + [25, 5] + ] + } + } + ] +} diff --git a/packages/turf-boolean-contains/test/true/MultiPolygon/MultiPolygon/MultiPolygonAllInSamePolygon.geojson b/packages/turf-boolean-contains/test/true/MultiPolygon/MultiPolygon/MultiPolygonAllInSamePolygon.geojson new file mode 100644 index 0000000000..de7348dc25 --- /dev/null +++ b/packages/turf-boolean-contains/test/true/MultiPolygon/MultiPolygon/MultiPolygonAllInSamePolygon.geojson @@ -0,0 +1,59 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0] + ] + ], + [ + [ + [20, 0], + [30, 0], + [30, 10], + [20, 10], + [20, 0] + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [1, 1], + [4, 1], + [4, 4], + [1, 4], + [1, 1] + ] + ], + [ + [ + [5, 5], + [9, 5], + [9, 9], + [5, 9], + [5, 5] + ] + ] + ] + } + } + ] +} diff --git a/packages/turf-boolean-contains/test/true/MultiPolygon/MultiPolygon/MultiPolygonInsideMultiPolygon.geojson b/packages/turf-boolean-contains/test/true/MultiPolygon/MultiPolygon/MultiPolygonInsideMultiPolygon.geojson new file mode 100644 index 0000000000..ccfc5d71b9 --- /dev/null +++ b/packages/turf-boolean-contains/test/true/MultiPolygon/MultiPolygon/MultiPolygonInsideMultiPolygon.geojson @@ -0,0 +1,59 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0] + ] + ], + [ + [ + [20, 0], + [30, 0], + [30, 10], + [20, 10], + [20, 0] + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [2, 2], + [8, 2], + [8, 8], + [2, 8], + [2, 2] + ] + ], + [ + [ + [22, 2], + [28, 2], + [28, 8], + [22, 8], + [22, 2] + ] + ] + ] + } + } + ] +} diff --git a/packages/turf-boolean-contains/test/true/MultiPolygon/Point/PointInsideMultiPolygon.geojson b/packages/turf-boolean-contains/test/true/MultiPolygon/Point/PointInsideMultiPolygon.geojson new file mode 100644 index 0000000000..f080ebb576 --- /dev/null +++ b/packages/turf-boolean-contains/test/true/MultiPolygon/Point/PointInsideMultiPolygon.geojson @@ -0,0 +1,40 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0] + ] + ], + [ + [ + [20, 0], + [30, 0], + [30, 10], + [20, 10], + [20, 0] + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [5, 5] + } + } + ] +} diff --git a/packages/turf-boolean-contains/test/true/MultiPolygon/Point/PointInsideSecondPolygon.geojson b/packages/turf-boolean-contains/test/true/MultiPolygon/Point/PointInsideSecondPolygon.geojson new file mode 100644 index 0000000000..70a7b4b27e --- /dev/null +++ b/packages/turf-boolean-contains/test/true/MultiPolygon/Point/PointInsideSecondPolygon.geojson @@ -0,0 +1,40 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0] + ] + ], + [ + [ + [20, 0], + [30, 0], + [30, 10], + [20, 10], + [20, 0] + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [25, 5] + } + } + ] +}