문제

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 <- 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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top