Polygons in a MultiPolygon should be grouped
captain-igloo opened this issue · 4 comments
A MultiPolygon is a group of Polygons, which in turn is a group of rings. But geojson-vt flattens MultiPolygons, so the structure of the output geometry is the same for MultiPolygons and Polygons.
const index = geojsonvt({
features: [{
geometry: {
coordinates: [
[[[170, -40], [172, -40], [172, -38], [170, -38], [170, -40]]],
[[[172.5, -39.5], [173.5, -39.5], [173.5, -38.5], [172.5, -38.5], [172.5, -39.5]]],
],
type: 'MultiPolygon',
},
id: 1,
type: 'Feature',
}, {
geometry: {
coordinates: [
[[170, -40], [172, -40], [172, -38], [170, -38], [170, -40]],
[[170.5, -39.5], [171.5, -39.5], [171.5, -38.5], [170.5, -38.5], [170.5, -39.5]],
],
type: 'Polygon',
},
id: 1,
type: 'Feature',
}],
type: 'FeatureCollection',
}, {
extent: 256,
});
const tile = index.getTile(6, 62, 39);
console.log(JSON.stringify(tile.features[0].geometry));
// [[[57,197],[57,80],[148,80],[148,197],[57,197]],[[171,168],[171,109],[216,109],[216,168],[171,168]]]
console.log(JSON.stringify(tile.features[1].geometry));
// [[[57,197],[57,80],[148,80],[148,197],[57,197]],[[80,168],[125,168],[125,109],[80,109],[80,168]]]
I would expect Polygons in a MultiPolygon to be grouped to match the GeoJSON input, and MultiPolygons to have a different "type" (currently both Polygons and MultiPolygons have type 3).
It is done this way because that's what the Vector Tile Specification requires. See https://github.com/mapbox/vector-tile-spec/tree/master/2.1#4344-polygon-geometry-type
I am right that it would be difficult to properly render a MultiPolygon? Would I have to store the structure (i.e how many polygons and rings) separately and look it up when I want to render it?
@captain-igloo no. Per the spec, you can recreate the structure from the winding order of linear rings.
OK, I'll try that, thanks.