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.ho...@env.ethz.ch > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo@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.pebe...@wwu.de _______________________________________________ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo