Etienne,
Sorry for being unclear. The use of matrix() was only to create a toy matrix to illustrate what I wanted to do.

Here is another way of describing it

library(raster)
r  = raster("my.raster.img")   # 6841*15411 pixels
r = order(r)
r = r/max(r[])
but it seems to take forever.

Could it be that order() is not designed to work efficiently on rasters? It is a standard function, and not part of library(raster), which is designed to work efficiently on rasters. There is no raster-specific order().

Cheers
Tord

From: Etienne B. Racine [mailto:etiennebr@gmail.com]
Sent: 16 November 2012 16:51
To: Tord Snäll
Cc: r-sig-geo@r-project.org
Subject: Re: [R-sig-Geo] order large pixel layer

Tord, I'm not sure about the usage you make of order (is it simply to generate a random matrix ?). You can probably adapt it :

rast <- matrix(rnorm(12,mean=0.7,sd=0.1),ncol=4,nrow=3)
rast <- matrix(order(rast),ncol=4,nrow=3)

# cast your matrix to a raster at a certain point
library(raster)
r <- raster(rast)
r <- r / max(r[])

Etienne



2012/11/16 Tord Snäll <Tord.Snall@slu.se<mailto:Tord.Snall@slu.se>>
Dear all,

I would greatly appreciate advice on how to rank and standardize a raster layer with 6841*15411 pixels.



If the raster layer was instead a matrix, this is what I would do:

Say the raster had 12 pixels

rast = matrix(rnorm(12,mean=0.7,sd=0.1),ncol=4,nrow=3)

rast

> rast

          [,1]      [,2]      [,3]      [,4]

[1,] 0.6695254 0.7046706 0.7089812 0.6998835 [2,] 0.6497284 0.6999004 0.6743091 0.8738022 [3,] 0.8441623 0.7493160 0.7420391 0.6824722



Next, order

> matrix(order(rast),ncol=4,nrow=3)

     [,1] [,2] [,3] [,4]

[1,]    2   12    4    6

[2,]    1   10    7    3

[3,]    8    5    9   11



Next standardize in relation to the highest value

> matrix(order(rast),ncol=4,nrow=3)/12



           [,1]      [,2]      [,3]      [,4]

[1,] 0.16666667 1.0000000 0.3333333 0.5000000 [2,] 0.08333333 0.8333333 0.5833333 0.2500000 [3,] 0.66666667 0.4166667 0.7500000 0.9166667



Solutions using R, GRASS or ArcGIS will do as fine!



Best regards,

Tord


        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org<mailto:R-sig-Geo@r-project.org>
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


	[[alternative HTML version deleted]]

