[R-sig-Geo] distance calculation; meuse.grid

Adrian Baddeley adrian at maths.uwa.edu.au
Mon Jul 3 12:30:08 CEST 2006


karl.sommer at dpi.vic.gov.au writes:

> I was wondering if there is a way in "R" or "sp" to calculate shortest
> distance from a given object such as a river, similar to the data example
> "meuse.grid"  under the gstat package.

In package 'spatstat' there is a function distmap() 
designed for this purpose. 

The object (the river) may be either

	  - a list of line segments (line segment pattern object, class "psp")

	  - a list of x,y coordinate points (point pattern object, class "ppp")

or
	  - a binary pixel image (window object, class "owin", type "mask")

The return value is a pixel image; the brightness value of each pixel
gives the shortest distance from that pixel to the target object. 

You can display the pixel image, extract the values at chosen locations
using the subset operator "[ ]", or extract the entire pixel array
using "as.matrix".

Adrian Baddeley




More information about the R-sig-Geo mailing list