h3-py icon indicating copy to clipboard operation
h3-py copied to clipboard

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

Open mutability opened this issue 2 years ago • 2 comments

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 avatar Oct 05 '21 07:10 mutability

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.

mutability avatar Oct 05 '21 10:10 mutability

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.

dfellis avatar Oct 05 '21 16:10 dfellis