polygon-lookup icon indicating copy to clipboard operation
polygon-lookup copied to clipboard

Nearest polygon

Open jfoclpf opened this issue 3 years ago • 1 comments

When a certain point does not fit within any known polygon, is there a way to calculate or output the nearest polygon and the distance thereto?

jfoclpf avatar Aug 14 '22 13:08 jfoclpf

Hi @jfoclpf, no, not with the current API.

It is however possible to achieve something like this using the rbush library we are using under-the-hood. The data model is an R-Tree so you should be able to provide an input bounding-box instead of an input point.

There are a few things to note:

  • There is no way to know the minimum size bounding box you'll need to input to ensure a hit
  • The algorithm is different from the Ray Casting algo used to test a CONTAINS relationship, although its basically the same thing (ie. find the closest edge and then find the closest point on the edge).
  • Passing a bounding box which intersects many polygons will require doing work on every matching polygon, which has the potential to be considerably slower than the existing point-in-polygon API.

missinglink avatar Aug 15 '22 13:08 missinglink