It's true that my polygons might not contain as many as a 100 000 points and 
that I can probably restrict the polygons used to certain regions. I guess I 
was just looking for an easy and super fast function. Thanks, I will be looking 
into both of your suggestions. And of course, I was talking about a weird year 
type circular polygon. 
 
Francois Rousseu
 
> > Hi useRs
> >
> > I want to measure the distance between several points on a map and the 
> > closest water body, represented by polygons. The method I found uses the 
> > dist2Line function from package geosphere. In my example, I create a 
> > circular polygon made from a 100 000 points and measure the distance 
> > separating it from a given point:
> >
> >  buff<-destPoint( c(-74,46), b=seq(1,365,length.out=100000), d=1000)
> > system.time(dist2Line(c(-75,45), buff))
> >
> > This takes almost 10 seconds on my computer which is way too long for me. 
> > In my case, I need to determine that distance between thousands of points 
> > in a complex lake system.  Is there a faster way to do this in R?
> 
> 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
                                          
        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to