[R-sig-Geo] expand the dist covariate of the prediction-grid meuse.grid (sp package)

Edzer Pebesma edzer.pebesma at uni-muenster.de
Tue May 4 19:33:09 CEST 2010


sp does not do points-to-line distances, but can do point-to-point
distances. In the second section I resampled the river boundary so we
get a closer approximation, because more points. Maybe rgeos can be
expanded do the real point-to-line things (R != GIS?).

library(sp)
data(meuse.riv)
meuse.sr =
SpatialPolygons(list(Polygons(list(Polygon(meuse.riv)),"meuse.riv")))
meuse.sp = as(as(meuse.sr, "SpatialLines"), "SpatialPoints")

# create a grid:
grd = SpatialPixels(SpatialPoints(makegrid(meuse.sr)))
plot(meuse.sr)
grd = spsample(as(meuse.sr, "Spatial"), type='regular', n=10000)
points(coordinates(grd))
d = spDists(grd, meuse.sp)
d0 = apply(d,1,function(x){x[x==min(x)][1]})
g0 = SpatialPixelsDataFrame(as(grd, "SpatialPixels"), data.frame(d0=d0))
spplot(g0, col.regions=bpy.colors())

# for finer discretized
meuse.sp = as(spsample(as(meuse.sr, "SpatialLines"),type="regular",
n=1000),    "SpatialPoints")
d = spDists(grd, meuse.sp)
g0$d1 = apply(d,1,function(x){x[x==min(x)][1]})
pplot(g0, col.regions=rev(bpy.colors()))

Hope this helps,
--
Edzer

On 05/04/2010 09:39 AM, Christoph Hofer wrote:
> Dear list
> 
> 
> I would like to expand the covariate "dist"  of the meuse.grid dataset, of the sp package,
> to the south-east direction. The value of the covariate dist is relative between [0,1].
> Now, it is not clear for me how I shall calculate the distance between
> a new gird point and the river (is it the perpendicular between the river border and the grid point)?
> 
> I appreciate for any tips or hints.
> 
> 
> 
> Christoph
> 
> 
> 
> 
> 
> ETH Zurich
> Christoph Hofer
> Soil and Terrestrial Environmental Physics
> Institute of Terrestrial Ecosystems
> CHN E 50.2
> Universitätstrasse 16
> 8092 Zurich, Switzerland
> phone         (+41) - (0)44 - 633 63 65
> fax               (+41) - (0)44 - 633 11 23
> e-mail: christoph.hofer at env.ethz.ch
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

-- 
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
8333081, Fax: +49 251 8339763  http://ifgi.uni-muenster.de
http://www.52north.org/geostatistics      e.pebesma at wwu.de



More information about the R-sig-Geo mailing list