[R-sig-Geo] distance to polygon (and line_
Peter Larson
pslarson2 at gmail.com
Sun Oct 31 22:33:31 CET 2010
OK! That works for the polygons.
Thank you for your help,
Pete
On 2010/10/31 17:06, Robert J. Hijmans wrote:
> But if you would like to do this using longitude/latitude data, you
> could try dist2Lines in 'geosphere'
>
> library(geosphere)
> dist2Line(points, SpatialPolygons)
>
> (this function ONLY works for lon/lat, and NOT for a flat earth
> coordinate system)
>
> Robert
>
> On Sun, Oct 31, 2010 at 1:29 PM, Rolf Turner<r.turner at auckland.ac.nz> wrote:
>> 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
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at stat.math.ethz.ch
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
More information about the R-sig-Geo
mailing list