[R-sig-Geo] finding the minimum distance from a point to SpatialLines objects

Harry Kim harryk at cal.berkeley.edu
Sun Oct 26 22:53:05 CET 2008

Dear R-sig-geo users,

       I was wondering if there is a pre-written R function that
calculates the minimum distance from a point to  SpatialLines objects.

I have a european railroad shapefile which I read into R:

> class(railroad)
[1] "SpatialLinesDataFrame"
[1] "sp"

> names(railroad)
[1] "LENGTH"    "TYPE"      "LEVEL"     "NAME"      "NATION"

> slotNames(railroad)
[1] "data"        "lines"       "bbox"        "proj4string"

Using this data, I would like to search for the minimum distance from
an arbitrary point to the railroads nearby.
I could write a function that generates points  along the line from
coordinates given for each railroad segment as shown below:

> railroad at lines[[1]]@Lines
An object of class "Line"
Slot "coords":
       [,1]    [,2]
[1,] 8.3613 46.5359
[2,] 8.3603 46.5360
[3,] 8.3590 46.5361
[4,] 8.3578 46.5364
[5,] 8.3567 46.5365
[6,] 8.3555 46.5364
[7,] 8.3538 46.5361
[8,] 8.3524 46.5361

and find the minimum distances from a point to these multiple points.
But I would like to if there is a more intelligent way to calculate
I've looked into the r-sig-geo archive and the only thing I found was
finding the minimum distance using some type of GIS software.

Thank you very much for your help in advance.


More information about the R-sig-Geo mailing list