我正在使用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内使用aggregate
或disaggregate
功能例如]
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根据裁剪,可以使用
crop
或mask
功能
#load the required shapefile (namely as shp)
grey_cropped <- crop(grey_upscaled, shp)