uber / geojson2h3

Conversion utilities between H3 indexes and GeoJSON
Apache License 2.0
222 stars 22 forks source link

`geojson2h3.featureToH3Set` calculating indexes different from those in the docs #25

Open punkish opened 2 years ago

punkish commented 2 years ago
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?

nrabinowitz commented 2 years ago

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: