[R-sig-Geo] Building a grid that incorporates distance measurement

Alex Lechner a.lechner at uq.edu.au
Wed Feb 9 12:25:21 CET 2011


Hi Edzer.

Thank you for your reply. After a bit of playing round I am close to a solution.

Thanks

Alex 


-----Original Message-----
From: Edzer Pebesma [mailto:edzer.pebesma at uni-muenster.de] 
Sent: Monday, 7 February 2011 5:36 PM
To: r-sig-geo at r-project.org
Subject: Re: [R-sig-Geo] Building a grid that incorporates distance measurement

Alex,

your comments "does not work" are slightly self-centered - they do
"work" (at least for me), and do what they actually can do.

If you want a regular grid over an irregular polygon, you have to
provide spsample with such a polygon. The meuse data set does not come
with such a polygon - would indeed be nice to have an example. You can
use ?locator to digitize a polygon on-screen.

The "dist" values are obtained by evaluating, for each (observation and
prediction) point the distance to some feature - here the river Meuse.
To compute these, you need the target points, and the feature. The most
neat way would be to use the geometry functions in package rgeos, but a
good approximation would be just use many points of the feature (e.g.
generated by spsample) and then use spDists or spDistsN1.

Hth,

On 02/07/2011 03:31 AM, Alex Lechner wrote:
> Hello,
> 
> I am trying to do some Kriging incorporating a gradient trend in the data (i.e.  krige(log(zinc)~sqrt(dist),...) based on the method described in http://r-spatial.sourceforge.net/gallery/ and Bivand's book. I have been having problems with producing the appropriate grid with a format that incorporates distance. Just to make sure there are no errors in my own data I have utilised the "meuse" dataset and adapted the example in http://r-spatial.sourceforge.net/gallery/.
> 
> In the meuse dataset the grid is loaded with the data(meuse.grid). But I can't find a way that recreates the same data with the original meuse dataset. I have tried the following:
> 
> meuse.grid = spsample(meuse, type = "regular", cellsize = c(50,50))
> gridded(meuse.grid) = TRUE
> 
> and
> 
> meuse.grid <-SpatialPixels(SpatialPoints(makegrid(meuse)))
> gridded(meuse.grid) = TRUE
> 
> Neither of the above methods work when I use a Kriging function that incorporates distance (log(zinc)~sqrt(dist)). However they work if I use ordinary kriging with the function zinc~1. I also noticed that meuse.grid includes distance measurements.
> 
> CODE
> ====================
> 
> library(sp)
> library(gstat)
> 
> data(meuse)
> coordinates(meuse)=~x+y
> 
> #Original Method - only method that works
> data(meuse.grid)
> data_grid<-meuse.grid
> coordinates(data_grid) = ~x+y
> gridded(data_grid) = TRUE
> 
> #Method 2 - does not work
> #data_grid = spsample(meuse, type = "regular", cellsize = c(50,50))
> #gridded(data_grid) = TRUE
> 
> #Method 3 - does not work
> #data_grid<-SpatialPixels(SpatialPoints(makegrid(meuse)))
> #gridded(data_grid) = TRUE
> 
> v.uk = variogram(log(zinc)~sqrt(dist), meuse)
> uk.model = fit.variogram(v.uk, vgm(1, "Exp", 300, 1))
> 
> zn.uk = krige(log(zinc)~sqrt(dist), meuse, data_grid, model = uk.model)
> 
> print(spplot(zn.uk, "var1.pred"))
> 
> =========================
> 
> Thanks for the help,
> 
> Alex Lechner
> 
> Research Fellow
> Centre for Mined Land Rehabilitation
> Sustainable Minerals Institute
> University of Queensland
> 
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> 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