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", "name": "cimengine-build-tools",
"version": "1.4.3", "version": "1.5.0",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "cimengine-build-tools", "name": "cimengine-build-tools",
"version": "1.4.3", "version": "1.5.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@turf/turf": "^6.5.0", "@turf/turf": "^6.5.0",

View file

@ -1,6 +1,6 @@
{ {
"name": "cimengine-build-tools", "name": "cimengine-build-tools",
"version": "1.4.3", "version": "1.5.0",
"description": "Geojson data processing tools for CIMEngine", "description": "Geojson data processing tools for CIMEngine",
"main": "index.js", "main": "index.js",
"scripts": { "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) => { co_features.features = co_features.features.map((val) => {
if (val?.geometry?.type === "Polygon") { if (val?.geometry?.type.endsWith("Polygon")) {
val.properties = {}; val.properties = {};
} else if (val?.geometry?.type === "MultiPolygon") {
console.error("Error: MultiPolygons are not allowed!");
process.exit(1);
} }
return val; return val;