geo-maps
geo-maps copied to clipboard
Devide earth seas in multiple polygons
Hello,
Is it possible to divide the multipolygon of the oceans into several polygons? I want to save the geometries in a MongoDb, but this single object is too big to store. I did not succeed with QGIS.
Hi @kevinries,
I was planning to do it. I was just waiting for a clean way to do it using mapshaper. You can follow the issue here.
Anyway I'll try to work on it as soon as I can.
That's that what I tried with QGIS. But the process took hours an at the end I got an error, because of invalid polygons. I hope, you will find a working solution.
I've got some ts code that does it using turf assuming the polygons are valid:
const removeMultiPoligons = (geojson: FeatureCollection) =>
geojson.features.reduce((acc: Feature[], feat: Feature) => {
const { geometry } = feat;
switch (geometry?.type) {
case "MultiPolygon": {
return [
...acc,
...geometry.coordinates.map((poly) => ({
...feat,
geometry: { type: "Polygon", coordinates: poly } as Geometry,
})),
];
}
default:
return [...acc, feat];
}
}, []);
Currently it won't work for some things however as its meant to work on a feature collection, it should be trivial to make it work for this data though