我在R中有几个高分辨率的栅格层,我正在处理。对于我正在运行的一些分析来说,细节级别过高,所以我想通过降低分辨率来加快速度。
坐标系是UTM,所以单位是米。分辨率是30,30 (x,y)。所以看起来这里的分辨率是30m。
有没有人可以建议我如何将分辨率改为120m?我已经阅读了resample()和projectRaster()函数的帮助,但它们似乎需要具有所需分辨率的模板光栅,而我没有。
以下是我的一个栅格层的示例:
alt.utm
类: RasterLayer
尺寸: 4572,2495,11407140 (nrow,ncol,ncell)
分辨率: 30,30 (x,y)
范围: 421661,496511,4402939,4540099 (xmin,xmax,ymin,ymax)
坐标。参考:+proj=utm +zone=13 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
数据源:在内存中
名称:图层
取值: 1485.127,4275.202 (最小,最大)
发布于 2015-08-29 17:11:01
您可以使用aggregate或disaggregate。
library(raster)
#get some sample data
data(meuse.grid)
gridded(meuse.grid) <- ~x+y
meuse.raster <- raster(meuse.grid)
res(meuse.raster)
#[1] 40 40
#aggregate from 40x40 resolution to 120x120 (factor = 3)
meuse.raster.aggregate <- aggregate(meuse.raster, fact=3)
res(meuse.raster.aggregate)
#[1] 120 120
#disaggregate from 40x40 resolution to 10x10 (factor = 4)
meuse.raster.disaggregate <- disaggregate(meuse.raster, fact=4)
res(meuse.raster.disaggregate)
#[1] 10 10
发布于 2018-06-10 09:01:37
我已经尝试了3种不同的方法来放大DEM文件。首先,我像这样使用gdal_translate
:
from CMD:
gdal_translate -tr 0.1 0.1 "C:\dem.tif" "C:\dem_0.1.tif"
在R中:
res(raster('C:\dem_0.1.tif')
[1] 0.1 0.1
然后,我尝试了R中raster
包中的aggregate
和resample
命令:
#
r <- raster("dem.tif")
> res(r)
[1] 0.0002777778 0.0002777778 # original dem resolution
#
r_up_0.1 <- aggregate(r, fact = 0.1/res(r)) # aggregate output
> res(r_up_0.1)
[1] 0.1 0.1
#
s <- raster(nrow = 10, ncol = 10)
extent(s) <- extent(r)
s <- resample(r, s, method = 'bilinear') # resample output
> res(s)
[1] 0.1000278 0.1000278
以下是输出:
这3个输出被提升为res = 0.1x0.1
,它们之间有一些差异,但我打算使用gdal输出。
希望这能有所帮助。
发布于 2015-08-29 04:03:02
这里有一个如何做到这一点的例子。(link to original)
#########################################################################
# SubsampleImageRaster.r
#
# This function demonstrates resampling of raster images to a new
# spatial resolution using the R raster package.
#
# Author: Rick Reeves
# Date created: 6-October- 2010
# Date modified:
# NCEAS
#
#########################################################################
#
SubsampleImageRaster <- function()
{
library(raster)
sOutFile <- ""
resampleFactor <- 4 # For test, subsample incoming image by factor of 10
# Read the mosaic components, stored in a subfolder, into a raster object list.
# Within the same loop, obtain the (geographic) extent of each component.
# Note: these images do not have same spatial extent, so they cant be stored
# in a rasterStack. Instead, use a list of rasterLayers.
setwd("./ForUseCase")
inFiles <- list.files(pattern="*.tif")
nFiles <- length(inFiles)
inputRaster <- raster()
CoarseResampRaster <- raster()
FineResampRaster <- raster()
for (iCtr in 1 : nFiles)
{
message(sprintf("resampling file: %s",inFiles[iCtr]))
inputRaster <- raster(inFiles[iCtr])
# The aggregate() / disaggregate methods resample rasters to COARSER (bigger cells)
# and FINER (smaller cells) resolutions, respectively
CoarseResampRaster <- aggregate(inputRaster,fact=resampleFactor,fun=mean)
sOutFile <- sprintf("CoarseSubsamp%s",inFiles[iCtr])
writeRaster(CoarseResampRaster,filename=sOutFile,format="GTiff",datatype="INT1U",overwrite=TRUE)
FineResampRaster <- disaggregate(inputRaster,fact=resampleFactor,fun=mean)
sOutFile <- sprintf("FineSubsamp%s",inFiles[iCtr])
writeRaster(FineResampRaster,filename=sOutFile,format="GTiff",datatype="INT1U",overwrite=TRUE)
}
message("resample demo")
browser()
# second method: use the resample() method from raster package
# Simple example:
# This code produces a resampled raster, 's',
# with correct resampled values. e.g.;
# s[] prints a vector of resampled cell values.
r <- raster(nrow=3, ncol=3)
r[] <- 1:ncell(r)
s <- raster(nrow=10, ncol=10)
s <- resample(r, s, method='bilinear')
# Useful example:
# Resample a satellite image, stored in a GeoTiff file
# into a NEW raster with 2x spatial resolution in
# both dimensions (four times the number of cells)
# Here is the technique:
# 1) Create a new raster object with the correct 'resampled' number of cells.
# 2) Set the extent (geographic 'bounding box') of the new raster
# to the extent of the original raster
# 3) Generate the resampled raster.
resampleFactor <- .5 # reduce the cell size by 50% and double the number of rows and columns.
inputRaster <- raster("TmB50MosaicImg1.tif")
inCols <- ncol(inputRaster)
inRows <- nrow(inputRaster)
resampledRaster <- raster(ncol=(inCols / resampleFactor), nrow=(inRows / resampleFactor))
extent(resampledRaster) <- extent(inputRaster)
# The resample method will write the resampled raster image to a NEW disk file..
resampledRaster <- resample(inputRaster,resampledRaster,datatype="INT1U",method='bilinear',filename="testOutResamp.tif",overwrite=TRUE)
# Or, use writeRaster method to create the output file.
writeRaster(resampledRaster,filename="ResampleProduct.tif",format="GTiff",datatype="INT1U",overwrite=TRUE)
# end
}
https://stackoverflow.com/questions/32278825
复制相似问题