[R-sig-Geo] distance to polygon (and line_
Rolf Turner
r.turner at auckland.ac.nz
Sun Oct 31 21:29:41 CET 2010
On 1/11/2010, at 7:38 AM, Peter Larson wrote:
> Hello all,
>
> I have a database of point (lat long) data.
> I also have shapefiles of polygon and line data.
>
> I need to find the distances from each of the points to 1) the nearest
> polygon and 2) the nearest line.
>
> Is this possible?
In R all things are possible.
You may have problems with units; the units in which your points are expressed
must be the same as those in which the lines and polygons are expressed.
If you can express everything in terms of two dimensional Euclidean units,
then the facilities of spatstat will allow you to do what you want. Currently
spatstat does not handle great circle distances.
If you express your collection of polygons as a single owin object, say "xxx", then
distfun(xxx)(x,y) will give the distances from to xxx. These will be the
minima of the distances from the points to the individual polygons.
Likewise if you express your collection of lines as a psp object, say "lll",
then distfun(lll)(x,y) will the distance from each point to the nearest line.
In the foregoing "x" represents the vector of x-coordinates of your points,
and y the vector of y-coordinates.
See
vignette("shapefiles")
for instructions on how to turn shapefile data into spatstat style objects.
cheers,
Rolf
More information about the R-sig-Geo
mailing list