Skip to content
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
25 changes: 25 additions & 0 deletions packages/turf-boolean-valid/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,31 @@ function booleanValid(feature: Feature<any> | Geometry) {
}
}
return true;
case "GeometryCollection":
if (!geom.geometries) {
return false;
}

// To avoid situations where Geometry Collections nested within one another
// could lead to a situation where there is an infinite validation loop,
// we enforce the GeoJSON RFC recommendations
// (https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.8)
// which states that we should not have Nested Geometry Collections
return (
Array.isArray(geom.geometries) &&
geom.geometries.length > 0 &&
geom.geometries.every(
(geometry: Geometry) =>
[
"Point",
"LineString",
"MultiLineString",
"MultiPoint",
"Polygon",
"MultiPolygon",
].includes(geometry.type) && booleanValid(geometry)
)
);
default:
return false;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/turf-boolean-valid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"author": "Turf Authors",
"contributors": [
"Rowan Winsemius <@rowanwins>",
"Denis Carriere <@DenisCarriere>"
"Denis Carriere <@DenisCarriere>",
"Martin Künzi <@ltkum>"
],
"license": "MIT",
"bugs": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "GeometryCollection",
"geometries": [
{
"type": "Point",
"coordinates": [2.8113711933311403]
},
{
"type": "LineString",
"coordinates": [
[1.285400390625, 4.214943141390651],
[0.472412109375, 2.9649843693339677],
[1.900634765625, 2.1857489471296665]
]
}
]
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "GeometryCollection",
"geometries": [
{
"type": "GeometryCollection",
"geometries": [
{
"type": "Point",
"coordinates": [6.7575683593749996, 2.8113711933311403]
},
{
"type": "Point",
"coordinates": [2.7575683593749996, 2.8113711933311403]
}
]
}
]
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "GeometryCollection",
"geometries": [
{
"coordinates": [6.7575683593749996, 2.8113711933311403]
},
{
"type": "LineString",
"coordinates": [
[1.285400390625, 4.214943141390651],
[0.472412109375, 2.9649843693339677],
[1.900634765625, 2.1857489471296665]
]
}
]
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "GeometryCollection",
"geometries": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [2.7575683593749996, 2.8113711933311403]
}
},
{
"type": "Point",
"coordinates": [2.7575683593749996, 2.8113711933311403]
}
]
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "GeometryCollection",
"geometries": [
{
"type": "Point",
"coordinates": [6.7575683593749996, 2.8113711933311403]
},
{
"type": "LineString",
"coordinates": [
[1.285400390625, 4.214943141390651],
[0.472412109375, 2.9649843693339677],
[1.900634765625, 2.1857489471296665]
]
}
]
}
}
]
}