geo-maps icon indicating copy to clipboard operation
geo-maps copied to clipboard

Devide earth seas in multiple polygons

Open kevinries opened this issue 6 years ago • 3 comments

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.

kevinries avatar Feb 12 '18 09:02 kevinries

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.

simonepri avatar Feb 18 '18 15:02 simonepri

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.

kevinries avatar Feb 20 '18 10:02 kevinries

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

Isaac-Leonard avatar Jan 05 '22 11:01 Isaac-Leonard