h3

Use the H3 cell index to create a bounding box and perform a point in bbox operation


With latitude and longitude, there is the possbility to create a bounding box based on xmax/ymax and xmin/ymin. Having coordinates, I can perform a range search to check, if these coordinates are withing the bounding box. Something like

 xmax >= longitude && xmin <= longitude && ymax >= latitude && ymin <= latitude

If all of this is true, I know, my point falls within the bounding box. I wonder if there is similar possibility, using the index of h3. If I define the xmax/ymax and xmin/ymin with the index of the corresponding cell:

topLeftCorner: 8b2d55c256acfff
bottomRightCorner: 8b2d024758b1fff

Could I then use the way the cell index is constructed to perform a similar range search, like with real coordinates? Something like (pseudo code):

point = 8b2d11c1599bfff
if(point[0:4] === topLeftCorner[0:4] && ....

Solution

  • Answered separately here: https://github.com/uber/h3/issues/722

    The order of the indexes does not support this directly. You might be able to do this using local IJ coordinates - see cellToLocalIJ. Note that there are areas of the world (around pentagons) where this may not work well, but in local areas this should be possible.

    In general, though, I think the simpler option when you want to check for inclusion in a large region is to have a reverse index - e.g. a table, map, or set of the indexes in the region. Determining if a point is in the area is then just a set inclusion check. It might also be simpler or more efficient to actually check a lat/lng bounding box (based on the cell center lat/lng) and then have a second, more expensive check to determine whether the index is in the region.