feat: convert all multipolygons to polygons

This commit is contained in:
Artemy 2023-11-26 15:56:49 +03:00
parent 0153fbd617
commit e12d8f54d4
3 changed files with 20 additions and 7 deletions

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "cimengine-build-tools",
"version": "1.4.3",
"version": "1.5.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "cimengine-build-tools",
"version": "1.4.3",
"version": "1.5.0",
"license": "MIT",
"dependencies": {
"@turf/turf": "^6.5.0",

View file

@ -1,6 +1,6 @@
{
"name": "cimengine-build-tools",
"version": "1.4.3",
"version": "1.5.0",
"description": "Geojson data processing tools for CIMEngine",
"main": "index.js",
"scripts": {

View file

@ -42,12 +42,25 @@ for (country of layers) {
)
);
co_features.features = co_features.features.flatMap((val) => {
if (val?.geometry?.type === "MultiPolygon") {
return val.geometry.coordinates.map((coordinateSet) => {
return {
...val,
geometry: {
type: "Polygon",
coordinates: coordinateSet,
},
};
});
} else {
return val;
}
});
co_features.features = co_features.features.map((val) => {
if (val?.geometry?.type === "Polygon") {
if (val?.geometry?.type.endsWith("Polygon")) {
val.properties = {};
} else if (val?.geometry?.type === "MultiPolygon") {
console.error("Error: MultiPolygons are not allowed!");
process.exit(1);
}
return val;