Skip to content
Prev 11809 / 29559 Next

Distance from a point to the closest polygon

On Wed, May 25, 2011 at 6:34 PM, Francois Rousseu
<francoisrousseu at hotmail.com> wrote:
Do your lakes really have 100,000 coordinates defining them? (And do
circles really have 365 degrees in them?).

 Trying:

 buff<-destPoint( c(-74,46), b=seq(1,360,length.out=N), d=100)

shows that the time to do dist2Line is about linear with the
complexity of the polygon, here N. If your lakes are that finely
digitized, then can you thin their boundaries? Can you pre-test
against the bounding boxes of the lakes to reduce the number of
point-line segment tests? Note that I don't think the nearest lake
will always be the one with the nearest bbox, but you do know the max
possible distance to that lake is the distance to the furthest corner
of the bbox. Any lakes whose nearest bbox corner is _further_ than
that distance can be eliminated.

 Beyond that you are possibly looking into spatial indexing and maybe
loading it into a PostGIS database with this kind of optimised spatial
indexing searches.

 And rgeos of course.

 Random thoughts.

Barry