簡體   English   中英

在 R 中更改分辨率、裁剪和繪制光柵圖像

[英]Changing resolution, cropping and plotting Raster images in 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 中使用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)

這是基於此解決方案
根據裁剪,您可以使用cropmask功能

#load the required shapefile (namely as shp)
grey_cropped <- crop(grey_upscaled, shp)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM