From e12d8f54d4591e074cd9056361eb984ef052a0f6 Mon Sep 17 00:00:00 2001 From: Artemy Date: Sun, 26 Nov 2023 15:56:49 +0300 Subject: [PATCH] feat: convert all multipolygons to polygons --- package-lock.json | 4 ++-- package.json | 2 +- tools/GeoBuilder.js | 21 +++++++++++++++++---- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index fbcd9f0..4bc80c9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 9832d6b..631035e 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/tools/GeoBuilder.js b/tools/GeoBuilder.js index b5d6e22..f4fb46e 100644 --- a/tools/GeoBuilder.js +++ b/tools/GeoBuilder.js @@ -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;