[R-sig-Geo] Pixel calculation using extract() in geoTiff raster: faster and free of computer lock in R

ASANTOS @lex@ndre@@nto@br @ending from y@hoo@com@br
Sun Nov 18 14:10:06 CET 2018


Dear R-sig-geo Members,

     I've like to use R and raster package (extract() function) for 
pixel calculations (SD, Skewness and Kurtosis in 1  unit radius of a 
buffer) in a geoTiff raster, but my original geoTiff image has 
6244(nrow), 8721(ncol) and 54453924 (ncell) dimensions. This image size 
causes slow computation process or computer lock, for example in my code 
below:

### <code r>
#Packages
library(raster)
library(moments) #Measures of Skewness and Kurtosis

## Create artificial raster for my geoTiff simulation - dimensions  of 
my original geoTiff: 6244, 8721, 54453924  (nrow, ncol, ncell)
r <- raster(nc=8721, nr=6244)
r <- setValues(r, round(runif(ncell(r))* 255))

#Extract all pixel coordinates in raster
coord_r<-coordinates(r)

#Extract standard deviation, skewness and kurtosis
Buffer<-1
SD<-function (x, na.rm = TRUE)
{
if (is.matrix(x))
     apply(x, 2, sd, na.rm = na.rm)
else if (is.vector(x))
     sqrt(var(x, na.rm = na.rm))
else if (is.data.frame(x))
     sapply(x, sd, na.rm = na.rm)
else sqrt(var(as.vector(x), na.rm = na.rm))
}
desv_pad_R<-extract(r, coord_r, buffer = Buffer, fun = SD)
str(desv_pad_R)
sk_R <-extract(r,coord_r,buffer=Buffer, fun=skewness, na.rm = TRUE)
str(sk_R)
k_R <-extract(r,coord_r,buffer=Buffer, fun=kurtosis, na.rm = TRUE)
str(k_R)
# <END code>

     There are different approaches (eg. integration with SAGA GIS or 
GRASS, convert image to ASCII) for my problem?

Thanks in advanced,

Alexandre

-- 
======================================================================
Alexandre dos Santos
Proteção Florestal
IFMT - Instituto Federal de Educação, Ciência e Tecnologia de Mato Grosso
Campus Cáceres
Caixa Postal 244
Avenida dos Ramires, s/n
Bairro: Distrito Industrial
Cáceres - MT                      CEP: 78.200-000
Fone: (+55) 65 99686-6970 (VIVO) (+55) 65 3221-2674 (FIXO)

         alexandre.santos using cas.ifmt.edu.br
Lattes: http://lattes.cnpq.br/1360403201088680
OrcID: orcid.org/0000-0001-8232-6722
Researchgate: www.researchgate.net/profile/Alexandre_Santos10
LinkedIn: br.linkedin.com/in/alexandre-dos-santos-87961635
Mendeley:www.mendeley.com/profiles/alexandre-dos-santos6/



More information about the R-sig-Geo mailing list