更改分辨率,在R中裁剪和绘制栅格图像

问题描述 投票:0回答:1

我正在使用landsat-7图像数据(TIF文件),可以从USGS Earth Explorer中下载这些数据。我希望能够将分辨率更改为10x10,然后将图像裁剪到我感兴趣的特定区域,然后重新绘制图像。在R中这可能吗?我已经包含了一些实际的/伪代码。 W

library(raster)
library(rgdal)
grey <- raster("image") ##loading image
gr.disaggregate <- disaggregate(gr.disaggregate, fact=3) ##turning into 10x10 from 30x30
r.pts <- rasterToPoints(gr.disaggregate, spatial=TRUE) ##This WONT work
## if it did my thought process would be the following
geo.prj <- "+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0" 
r.pts <- spTransform(r.pts, CRS(geo.prj)) 
r.pts@data <- data.frame(r.pts@data, long=coordinates(r.pts)[,1],
                         lat=coordinates(r.pts)[,2])                         
ext <- extent(xmin, xmax, ymin, ymax)
r.pts2 <- crop(r.pts, ext) 
##I would then want to replot the resolution increased/cropped image

非常感谢您的帮助,谢谢!

r statistics geospatial r-raster rgdal
1个回答
0
投票

要放大或缩小(更改分辨率),可以在r内使用aggregatedisaggregate功能例如]

library(raster)

grey <- raster("image") ##loading image
#this function will give you the resolution of your raster
res(grey)

#disaggregate/downscale from 30 x 30 resolution to 10 x 10 (factor = 3)
grey_agg <- disaggregate(grey, fact=3)

##this function will give you the resolution of your raster after changing resolution
res(grey_agg)

这是基于this solution根据裁剪,可以使用cropmask功能

#load the required shapefile (namely as shp)
grey_cropped <- crop(grey_upscaled, shp)
© www.soinside.com 2019 - 2024. All rights reserved.