Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
punkish opened this issue Jan 12, 2022 · 1 comment

Comments

@punkish
Copy link

punkish commented Jan 12, 2022

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
Copy link
Collaborator

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 use uncompact to get your desired resolution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants