uber / h3-py

Python bindings for H3, a hierarchical hexagonal geospatial indexing system
https://uber.github.io/h3-py
Apache License 2.0
833 stars 132 forks source link

h3.polyfill fails for very-southerly (not pole-crossing) polygons #202

Open mutability opened 3 years ago

mutability commented 3 years ago

polyfill fails to return any cells for what I believe is a well-formed polygon near the south pole. This originally turned up trying to polyfill Antarctica (using a polygon that avoided the pole itself) but it also happens with much simpler polygons.

I've seen mention elsewhere that polyfill won't work with polygons enclosing the poles, but these polygons avoid the pole. The problem first turns up somewhere south of around 82S.

Testcase:

#!/usr/bin/env python3

import h3

print(h3.versions())

good = {
    'type': 'Polygon',
    'coordinates': [ [
        [-120, -74],
        [0, -74],
        [120, -74],
        [120, -82],
        [0, -82],
        [-120, -82],
        [-120, -74]
    ] ]
}

print('good', len(h3.polyfill(good, 5, geo_json_conformant=True)), 'cells')

bad = {
    'type': 'Polygon',
    'coordinates': [ [
        [-120, -74],
        [0, -74],
        [120, -74],
        [120, -84],
        [0, -84],
        [-120, -84],
        [-120, -74]
    ] ]
}

print('bad', len(h3.polyfill(bad, 5, geo_json_conformant=True)), 'cells')

Results on my system:

$ ./testcase.py 
{'c': '3.7.1', 'python': '3.7.3'}
good 17728 cells
bad 0 cells
mutability commented 3 years ago

So far this looks like a problem in the underlying h3 library where polygonToCells returns E_FAILED. I'll put together a C testcase and report an issue against the library; but it would be useful for errors like E_FAILED to be propagated to python.

dfellis commented 3 years ago

So far this looks like a problem in the underlying h3 library where polygonToCells returns E_FAILED. I'll put together a C testcase and report an issue against the library; but it would be useful for errors like E_FAILED to be propagated to python.

Btw, the name change to polygonToCells is because the C library is currently being worked on for a 4.0 major release, changing the API so we can return error cases like that, but it's not ready yet. This library is still pointed at version 3.7.1 of the C library that doesn't have error reporting for polygon filling.