[R-sig-Geo] Generate Spatial Surface

Edzer Pebesma edzer.pebesma at uni-muenster.de
Tue Oct 16 18:51:10 CEST 2012


It would be nice if spsample did this in one pass, but it doesn't. You
can do it by calling it 15 times, and combining, as in:

x = do.call(rbind, lapply(1:15, function(x) spsample(yy, cellsize = 12,
type = "stratified")))
spplot(yy[1], sp.layout = list("sp.points", x))

note that the areas are 12 x 12 cells, where the full grid is 100 x 100
so there might be boundary effects.

On 10/16/2012 05:54 PM, dani jon wrote:
> * Dear Edzer,
> *
> 
> *
> *
> 
> * Thank you for your prompt response.  The code is helpful, not exactly
> what I want. Let me clarify my question. I want first to divide the spatial
> surface into 8x8 girds (a total of 64 grids). Each gird is considered as a
> neighborhood. Then, for each grid, I would like to take a sample of 15
> locations with the corresponding values. So in total I will have 960
> samples with x, y, gridID and value.  *
> 
> * *
> 
> *Thanks for your help.*
> 
> *Dani
> *
> 
> 
> 
> On Tue, Oct 16, 2012 at 11:36 AM, Edzer Pebesma <
> edzer.pebesma at uni-muenster.de> wrote:
> 
>>
>>
>> On 10/16/2012 05:26 PM, dani jon wrote:
>>> Hi All,
>>>
>>>
>>> I am trying to figure out how to simulate a continuous spatial surface
>> with
>>> strong spatial autocorrelation. Then, I would like to divide this spatial
>>> surface into by 8 x 8 grids and take a sample of 15 locations within each
>>> grid and the corresponding values.
>>> For example, here is a sample code adopted from Santiago
>>> Beguería<http://santiago.begueria.es/>.
>>>
>>>
>>> library(gstat)
>>>
>>> xy <- expand.grid(1:100, 1:100)
>>>
>>> names(xy) <- c("x","y")
>>>
>>> g.dummy <- gstat(formula=z~1, locations=~x+y, dummy=T, beta=1,
>>> model=vgm(psill=0.025,model="Exp",range=10), nmax=20)
>>>
>>> # Make four simulations based on the gstat object
>>>
>>> yy <- predict(g.dummy, newdata=xy, nsim=1)
>>>
>>> # show one realization
>>>
>>> gridded(yy) = ~x+y
>>>
>>> spplot(yy[1])
>>> My questions is how to divide this spatial surface into 8x8 girds and
>> then
>>> take a sample of 15 locations and their values? I would greatly
>> appreciate
>>> if anybody can provide some ideas or pointers how to implement these
>>> scenarios in R. Thanks all for your help! Dani
>>
>> does
>>
>> x = spsample(yy, type = "stratified", cellsize = 12)[sample(64,15),]
>> spplot(yy[1], sp.layout = list("sp.points", x))
>>
>> kind of do what you want?
>>
>>>
>>>       [[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
>>
>> _______________________________________________
>> 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