tammoippen / geohash-hilbert

Geohash a lng/lat coordinate using hilbert space filling curves.
MIT License
89 stars 20 forks source link

`neighbours` incorrect near poles #5

Closed evanfields closed 5 years ago

evanfields commented 5 years ago

It looks like neighbours is incorrect at the poles: it gives the north neighbour of the north pole as the south pole. Here's an example:

In [22]: ghh.encode(0, 89.5, precision=3, bits_per_char=2)
Out[22]: '211'

In [24]: ghh.neighbours("211", bits_per_char=2)
Out[24]:
{'north': '322',
 'north-east': '323',
 'north-west': '011',
 'east': '212',
 'west': '122',
 'south': '210',
 'south-east': '213',
 'south-west': '123'}

In [25]: ghh.decode("322", bits_per_char=2)
Out[25]: (22.5, -78.75)

I guess the notion of neighboring cells is not super well defined at the poles (since all points (longitude, 90) are the same), but I would suggest that a cell which contains the north pole has no north, northwest, or northeast neighbor; likewise for the south pole and south neighbors.

If this seems good I can open a PR.

tammoippen commented 5 years ago

Hey, @evanfields

That is a good catch. You are correct, the current behavior is not optimal. I would welcome a pull request! Thx, Tammo

tammoippen commented 5 years ago

Closed by #6. Released in v1.3.0.