r - 在 R 中更改分辨率、裁剪和绘制光栅图像
问题描述
我正在使用 landsat-7 图像数据(TIF 文件),您可以从中下载 USGS 地球资源管理器。TIF 文件有 9 个图像,因此我希望能够将图像的每个分辨率更改为 10x10,然后将图像裁剪到我感兴趣的特定区域,然后重新绘制每个图像。这在R中可能吗?我已经包含了我对一个特定图像的尝试的一些实际/伪代码。由于确切的图像太大而无法上传,我已经包含了一个可以下载图像的区域 - 但是,任何图像示例都可以让我通过。
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 keeps running forever until R aborts.
## 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)
这是基于此解决方案
根据裁剪,您可以使用crop
或mask
功能
#load the required shapefile (namely as shp)
grey_cropped <- crop(grey_upscaled, shp)
推荐阅读
- bootstrap-4 - 如何使引导 4 表在整个行中保持宽度?
- python - 无法使用 [OpenCV] cv2.VideoCapture.set() 设置帧宽度和高度
- python-3.x - 尝试使用 Win32com.client.Dispatch() 使用 ProgID "QBXMLRP2Lib.RequestProcessor2" 连接到 Quickbooks 时出现错误
- unit-testing - 排序不是函数;spyOn 不嘲笑
- php - PDO::FETCH_ASSOC 只返回整数的第一位
- python-3.x - python3中的tkSimpleDialog用法
- ios - 在本地网络上执行 GET 请求时出现错误 1009
- angular - 在页面重新加载时重新获取 Firestore 数据
- flutter - AnnotatedRegion 用于更改 statusBarColor
- html - 使用角度将视频从浏览器投射到 Chromecast