[STATSGRASS] Re: Change of spatial support

Rohan Sadler rsadler at cyllene.uwa.edu.au
Wed Apr 5 21:14:42 EDT 2006


# Ulrich
#  Try this in R
library(spgrass6)
library(spatstat)
library(maptools)
G<-gmeta6()

#taking the data as a 1000 x 1000 matrix to rescale to 250 x 250.
# input layer: your.layer
# output layer: grass.out

# function to export R matrix: y is the name of the raster layer you create 
when exporting to GRASS
# somebody may have a more elegant way of doing this
putRast6wrap<-function(y,x){
  x.dim<-dim(x)
  x.bling<-GridTopology(c(0.002,0.002),c(0.004,0.004),c(dim(x)))
  x.bling2<-SpatialGridDataFrame(x.bling,AttributeList(list(c(t(x)[,nrow(x):1]))))
  writeRast6sp(x.bling2,y)
}

mean()   #  aggregation function: (could be another function)

# slowest method

raw.mat<-readCELL6sp("your.raster")
raw.mat<-matrix(raw.mat$your.raster,ncol=250)
out.mat<-matrix(0,ncol=250,nrow=250)

for ( i in 1:250) {
 for (j in 1:250) {
  out.mat[i,j]<-mean(raw.mat[((i*4-3):(i*4)),((j*4-3):(j*4))])
}
cat("I've just done row ",i,"\n")  # keeps track of how slow you are going
}

putRast6wrap("grass.out",out.mat)

# this is off the top of my head so hasn't been tested

# Rohan Sadler
#Ecosystems Research Group M090
#The University of Western Australia
#35 Stirling Hwy, Crawley, 6008
#ph:       +61 8 6488 4257
#fax:      +61 8 6488 7925
#mobile: +61 0433 192 600
#email:    rsadler at cyllene.uwa.edu.au

#Affiliations:
#Bushfire CRC
#School of Mathematics and Statistics, UWA

----- Original Message ----- 
From: <statsgrass-request at grass.itc.it>
To: <statsgrass at grass.itc.it>
Sent: Wednesday, April 05, 2006 6:01 PM
Subject: statsgrass digest, Vol 1 #176 - 1 msg


>
>
> Today's Topics:
>
>   1. Change of spatial support (Ulrich Leopold)
>
> --__--__--
>
> Message: 1
> Date: Wed, 5 Apr 2006 11:32:02 +0200 (CEST)
> From: "Ulrich Leopold" <uleopold at science.uva.nl>
> To: GRASSLIST at baylor.edu, statsgrass at grass.itc.it
> Reply-To: uleopold at science.uva.nl
> Subject: [STATSGRASS] Change of spatial support
>
> Dear list,
>
> I am trying to change the spatial support (grid size) of some floating 
> point
> raster maps from 250x250m to 1000x1000m. It's a kind of upscaling or more
> preciseley aggregation.
>
> All I need to do is to superimpose the larger grid on the smaller grid and
> compute the average and variance for the larger grid from the 4x4 250m 
> cells
> located within one 1000m cell.
>
> I recognise that this is still not possible in GRASS. The GRASS resampling
> methods for change of resolution, such as r.neigbors or g.region are not 
> an
> option as they do not provide a simple averaging method and the 
> aggregation
> error (variance).
>
> I thought maybe r.mapcalc or R with it's grass6 interface could be used. 
> But I
> do not know how to achieve it in terms of code. Any sugegstions?
>
> Ulrich
>
>
>
> --__--__--
>
> _______________________________________________
> statsgrass mailing list
> statsgrass at grass.itc.it
> http://grass.itc.it/mailman/listinfo/statsgrass
>
>
> End of statsgrass Digest
> 





More information about the grass-stats mailing list