h3 icon indicating copy to clipboard operation
h3 copied to clipboard

Add optimized bboxFill function

Open nrabinowitz opened this issue 5 years ago • 2 comments

Filling a bounding box with hexagons currently requires polyfill, which does an additional point-in-poly check that shouldn't be necessary for bounding boxes. If the use case is common enough, we ought to be able to provide a bboxFill function that would be faster for just filling bboxes. The case that's come up a few times here is getting all of the H3 indexes within a map viewport.

Additionally, bboxFill could handle bounding boxes wider than 180 degrees longitude, a current restriction of polyfill, because we'd have an explicit east/west signal.

nrabinowitz avatar Dec 21 '18 17:12 nrabinowitz

I asked the previously linked question, though this time I'm looking for another use case for this feature. I want to create (static, non-moving) geofences and test if a moving location (position coordinate) is inside a one of the fences.

This requires to create an index for cells which might also wrap around the 180 degree mark. Can you suggest a workaround without this bboxFill implemented?

benstadin avatar Mar 07 '19 00:03 benstadin

bboxFill as described here shouldn't be necessary for anything - it's just an optimization on top of polyfill.

For your use case, which is basically an optimized point-in-polygon check, you can:

  • Use polyfill to get the set of hexes for each geofence. This should be fine unless your geofences themselves have an arc > 180 degrees (i.e. the geofence covers more than half the world in longitude).
  • Store the h3Index : polygon mapping somewhere. A key-value store (e.g. Redis) is nice for this. You'll need to use a resolution fine enough so that you don't care about the margin of error around the polygon edges.
  • When you need to check a point, get the h3 index at the same resolution as your polyfill, and look it up in your mapping. This is generally a super-fast constant-time operation.

Does that fit your use case?

nrabinowitz avatar Mar 07 '19 01:03 nrabinowitz