开发者

open raster in R! and some statistical operation

I would like to open raster files (in ASCII or TIFF format), aggregate their cells and after this operation count correlation between values in this new raster file and another one. Unfortunately I do not know what is wrong in my commands - I get an error message:

x <-开发者_如何学C GDAL.open('~/Pulpit/dods/karol/TVDI 113_121/TVDI_kamp_evi_TRANSF.asc') 

CPL ERROR 4: `~/Pulpit/dods/karol/TVDI 113_121/TVDI_kamp_evi_TRANSF.asc' does not exist in the file system, and is not recognised as a supported dataset name.

Error in .local(.Object, ...) : `~/Pulpit/dods/karol/TVDI 113_121/TVDI_kamp_evi_TRANSF.asc' does not exist in the file system, and is not recognised as a supported dataset name.


If you are having trouble getting the filenames, you might do this:

my_asc_files = dir("../somepath", pattern="*.asc", recursive=T, full.names=T)
files_I_want = my_asc_files[c(1,12,32,33)]

Then you can load your files like this

library(raster)
my_rasters = lapply(files_I_want, raster)

Then you may do this:

pairs(my_rasters) 

and this:

for(i in 1:length(my_rasters)) 
  for(j in i:length(my_rasters))   
    if(i != j) {
      df = na.omit(data.frame(values(my_rasters[[i]]), values(my_rasters[[j]])))
      cor(df[,1], df[,2])
    }

Although you will run into problems if the rasters are so large that you cannot hold two in memory at the same time. Without a better question it will be hard to give you better advice.


To read (open) a raster, one way is to use readGDAL:

library(rgdal)
r <- readGDAL("~/myhome/thisdir/IhaveaFile.asc")

This is my personal preference, and the only reason to otherwise use GDAL.open or raster is if my machine doesn't have the RAM (+abit) to deal with the data set in question.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜