【发布时间】:2019-05-10 01:54:01
【问题描述】:
R 使用 gdalUtils 包为 gdal 库提供包装器。我想使用 gdal_calc.py 函数进行光栅计算,但是,我没有在包中找到有关此特定函数的信息。我创建了自己的 wrapper 函数,它可以工作,但通常不是 100% 完美,而且只能在 linux 上运行。它也没有原来的灵活(如果有兴趣,请参见下文)。 R 中还有其他实现吗?
f.gdal.calc<-function(path.in.r.1,
#r1.band=1,
path.in.r.2,
# r2.band=1,
path.out.r,
my.fun="A*B",#defaults to multiplication
r.datatype="Float32",
cachemax=2000,
overwrite=FALSE, # caution, can destroy data
printcommand=FALSE,# should the commad be printed prior to execution? Can help debugging
bigtiff=F,
compression=F)
{gdalcommand<-paste("gdal_calc.py ",
"-A ",path.in.r.1,
# " --allBands A ",
#"--A_band=",r1.band,
" -B ",path.in.r.2,
#"--b_band=",r2.band,
" --outfile=",path.out.r,
" --calc=",shQuote(my.fun,type = "cmd"),# supply function as character like "A+B"
" --type ",r.datatype,
ifelse(overwrite==TRUE,paste(" --overwrite"),paste("")),
ifelse(compression==TRUE,paste(" --co COMPRESS=LZW"),paste("")), #should not be enabled when creating bigtiffs
ifelse(bigtiff==TRUE,paste(" --co BIGTIFF=YES"),paste("")),
sep=""
)
if(printcommand==T){print(gdalcommand)}
system(gdalcommand)
}
【问题讨论】:
标签: r geospatial gdal rgdal