geojson2h3
geojson2h3 copied to clipboard
`geojson2h3.featureToH3Set` calculating indexes different from those in the docs
const polygon = {
type: 'Feature',
geometry: {
type: 'Polygon',
coordinates: [[
[-180.00, -90.00],
[-180.00, 90.00],
[ 180.00, 90.00],
[ 180.00, -90.00],
[-180.00, -90.00]
]]
}
};
const hexagons = geojson2h3.featureToH3Set(polygon, 0);
console.log(hexagons.length);
// output → 0, expected 122
// change coords to
coordinates: [[
[-179.00, -89.00],
[-179.00, 89.00],
[ 179.00, 89.00],
[ 179.00, -89.00],
[-179.00, -89.00]
]]
// output → 1, expected 122
console.log(geojson2h3.featureToH3Set(polygon, 2).length);
// ouput → 31, expected 5882
what am I doing wrong?
See my response here - this needs to be better documented, but the H3 polyfill function only works at present with shapes with width < 180 degrees of longitude. We ignore winding order and use the smaller shape where possible, so your -179.00, -89.00 shape gets filled as a narrow rectangle crossing the antimeridian.
Possible options:
- Divide the desired area into two rectangles and fill both
- If you actually want all the cells in the world, use
h3.getRes0Indexes()and then useuncompactto get your desired resolution.