0

I have a pandas dataframe with timestamp, latitude and longitude, and I have added the Hilbert Curve index using HilbertCurve from the hilbertcurve package. My dataframe looks like this:

import pandas as pd
df = pd.DataFrame({'time':['2019-10-19 19:23:00', '2019-10-19 19:24:00', '2019-10-19 19:25:00'],\
'lon':[48.80,48.801, 48.8018], \
'lat':[2.13,2.130,2.12], \
'hilbert'=[4578,4577,4521]})
print(df)

I want to find the neighbours of a specific hilbert cell. For example, for cell 4578, I want to find the 8 cells around it, which are east, north-east, north, north-west, west, south-west, south, south-east.

I looked everywhere but I was not lucky enough to find the answer.

Hafsa
  • 1
  • so your points are all on a 2D surface ? – Scott Stensland Sep 22 '20 at 19:00
  • Yes, exactly, that is right ! – Hafsa Sep 23 '20 at 08:14
  • I have used a Hilbert Curve in a project however did not calculate neighbors ... there may be an algo to calc neighbors directly however its easy enough to store into a 2D array the hilbert curve cell index number then on lookup simply look in those 8 directions from the x,y of given cell ... this is the classic tradeoff between space for time ... it takes more space (not much though) to populate this array yet it will be blindly fast on lookups ... naturally this 2D array calc will be specific to the Hilbert Curve size – Scott Stensland Sep 28 '20 at 19:00
  • This is a straightforward idea. Store the Hilbert curve into a 2D array and then add/subtract 1 from cells coordinates (x and y) to get the neighbors. Thank you very much for your response ! – Hafsa Sep 29 '20 at 09:14

0 Answers0