2013-12-22 2 views
9

저는 에 새 소식입니다.이 질문은 매우 기본적인 것이지만 나는 그걸로 어려움을 겪고 있으며 해결 된 해결책을 찾지 못했습니다. 같은 영역의 일부 landsat 이미지에서 래스터 벽돌을 만들고 싶습니다. HDF-EOS 형식으로 다운로드되었으며 Modis 재 투영 도구을 사용하여 .tif으로 변환했습니다.다른 범위의 래스터로 래스터 벽돌을 만드는 방법은 무엇입니까?

결과 래스터는 같은 투영법을 갖지만 범위, 해상도 및 원점이 다릅니다. 수동으로 하위 집합의 범위를 정의하고 모든 래스터를 부분 집합

  1. :

    나는 몇 여기 아래에 요약 접근을 시도했다. 그런 다음 서브셋 래스터로 벽돌을 만들려고 시도합니다.

  2. 래스터를 리샘플링하여 동일한 수의 열과 행을 제공합니다. 이상적으로는 래스터 셀을 정렬하고 래스터 벽돌에 넣을 수 있습니다. 이 옵션은 래스터에 값이없는 벽돌을 만들었지 만 비어있었습니다.

범위를 수정해야하는 이유는 무엇입니까? 가져온 landsat 이미지의 값으로 나중에 채울 빈 래스터를 만드는 것이 정확하고 (효율적일 수 있습니까?) 내가 실수를하고있는 곳을 볼 수 있니? 이 관련이 경우 , 내가 rgdal 인 버전 맥 OS X 버전 10.9.1 작업, 그리고 사용하고 0.8-14

은 어떤 도움이 매우 이해할 수있을 것이다!

감사합니다

내가 여기 내가 사용 된 코드를 추가 : 여기

# .tif files have been creating using the Modis Reprojection Tool. Input 
# files used for this Tool was LANDSAT HDF-EOS imagery. 

library(raster) 
library(rgdal) 

setwd()=getwd() 

# Download the files from dropbox: 
dl_from_dropbox <- function(x, key) { 
    require(RCurl) 
    bin <- getBinaryURL(paste0("https://dl.dropboxusercontent.com/s/", key, "/", x), 
         ssl.verifypeer = FALSE) 
    con <- file(x, open = "wb") 
    writeBin(bin, con) 
    close(con) 
    message(noquote(paste(x, "read into", getwd()))) 
} 
dl_from_dropbox("lndsr.LT52210611985245CUB00-vi.NDVI.tif", "qb1bap9rghwivwy") 
dl_from_dropbox("lndsr.LT52210611985309CUB00-vi.NDVI.tif", "sbhcffotirwnnc6") 
dl_from_dropbox("lndsr.LT52210611987283CUB00-vi.NDVI.tif", "2zrkoo00ngigfzm") 



# Create three rasters 
tif1 <- "lndsr.LT52210611985245CUB00-vi.NDVI.tif" 
tif2 <- "lndsr.LT52210611985309CUB00-vi.NDVI.tif" 
tif3 <- "lndsr.LT52210611987283CUB00-vi.NDVI.tif" 

r1 <- raster(tif1, values=TRUE) 
r2 <- raster(tif2, band=1, values=TRUE) 
r3 <- raster(tif3, band=1, values=TRUE) 

### Display their properties 
# projection is identical for the three rasters 
projection(r1) 
# "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0" 
projection(r2) 
projection(r3) 

# Extents are different 
extent(r1) 
# class  : Extent 
# xmin  : -45.85728 
# xmax  : -43.76855 
# ymin  : -2.388705 
# ymax  : -0.5181549 
extent(r2) 
# class  : Extent 
# xmin  : -45.87077 
# xmax  : -43.78204 
# ymin  : -2.388727 
# ymax  : -0.5208711 
extent(r3) 
# class  : Extent 
# xmin  : -45.81952 
# xmax  : -43.7173 
# ymin  : -2.405129 
# ymax  : -0.5154312 

# origin differs for all 
origin(r1) 
# 5.644590e-05 -8.588605e-05 
origin(r2) 
# 0.0001122091 -0.0001045107 
origin(r3) 
# 6.949976e-05 -5.895945e-05 

# resolution differs for r2 
res(r1) 
# 0.0002696872 0.0002696872 
res(r2) 
# 0.0002696875 0.0002696875 
res(r3) 
# 0.0002696872 0.0002696872 


## Try different approaches to create a raster brick 

# a- define a subset extent, and subset all the rasters 
plot(r1, main="layer1 NDVI") 
de <- drawExtent(show=TRUE, col="red") 
de 
# class  : Extent 
# xmin  : -45.36159 
# xmax  : -45.30108 
# ymin  : -2.002435 
# ymax  : -1.949501 
e <- extent(-45.36159,-45.30108,-2.002435,-1.949501) 
# Crop each raster with this extent 
r1c <- crop(r1,e) 
r2c <- crop(r2,e) 
r3c <- crop(r3,e) 
# Make raster brick 
rb_a <- brick(r1c,r2c,r3c) 
# Error in compareRaster(x) : different extent 

# b- Resample each raster 
s <- raster(nrow=6926, ncol=7735) # smallest nrow and ncol among r1,r2 and r3 
r1_res <- resample(r1,s, method="ngb") 
r2_res <- resample(r2,s, method="ngb") 
r3_res <- resample(r3,s, method="ngb") 
# Resampling gives for the three rasters the following message: 
# Warning message: 
# In .local(x, y, ...) : 
# you are resampling y a raster with a much larger cell size, 
# perhaps you should use "aggregate" first 

# Make raster brick 
rb_c <- brick(r1, r2, r3) 
# Error in compareRaster(x) : different extent 
+0

을 당신도 깜빡 생각 로드'라이브러리 (RCurl)'? –

+0

** projectRaster() ** instound ** resample **을 사용하여 시도한 적이 있습니까? b 메서드에서? –

답변

8

을 당신을 도울 수있는 몇 가지 있습니다. .tif 파일에는 몇 가지 힌트가 없습니다. 래스터에서 범위를 확인 했습니까 s? 그것은 세계의 크기입니다. 그 열은 셀이 매우 큽니다. 따라서 리샘플링을하기 전에 래스터에 익스텐트를 추가해야합니다.

# create an extent that includes all your data 
e<-extent(-46, -43, -2, -0.6) 

# create a raster with that extent, and the number of rows and colums to achive a 
# similar resolution as you had before, you might have to do some math here.... 
# as crs, use the same crs as in your rasters before, from the crs slot 
s<-raster(e, nrows=7000, ncols=7800, [email protected]) 

# use this raster to reproject your original raster (since your using the same crs, 
# resample should work fine 
r1<-resample(r1, s, method="ngb") 

해피 홀리데이, 벤

PS 원하는 정도 & 해상도를 찾을 수있는 더 좋은 방법 : 귀하의 정보에서 나는 이런 걸했다

# dummy extent from your rasters, instead use lapply(raster list, extent) 
a<-extent(-45.85728, -43.76855, -2.388705, -0.5181549) 
b<-extent(-45.87077, -43.78204, -2.388727, -0.5208711) 
c<-extent(-45.81952 ,-43.7173 , -2.405129 ,-0.5154312) 
extent_list<-list(a, b, c) 

# make a matrix out of it, each column represents a raster, rows the values 
extent_list<-lapply(extent_list, as.matrix) 
matrix_extent<-matrix(unlist(extent_list), ncol=length(extent_list) 
rownames(matrix_extent)<-c("xmin", "ymin", "xmax", "ymax") 

# create an extent with the extrem values of your extent 
best_extent<-extent(min(matrix_extent[1,]), max(matrix_extent[3,]), 
min(matrix_extent[2,]), max(matrix_extent[4,])) 

# the range of your extent in degrees 
ranges<-apply(as.matrix(best_extent), 1, diff) 
# the resolution of your raster (pick one) or add a desired resolution 
reso<-res(r1) 
# deviding the range by your desired resolution gives you the number of rows and columns 
nrow_ncol<-ranges/reso 

# create your raster with the following 
s<-raster(best_extent, nrows=nrow_ncol[2], ncols=nrow_ncol[1], [email protected]) 
+0

정말 감사합니다. 둘 다 감사드립니다! Ben 코드가 완벽하게 작동했습니다. 광범위한 도움을 주셔서 감사합니다 !! (다른 사용자의 경우, r1 <-resample (r1, s, method = "nbr")에서 가장 가까운 이웃에 사용하는 약어는 "ngb"입니다) Thijs 라이브러리를로드 할 필요가 없습니다. Rcurl)을 사용하여 래스터 브릭을 만듭니다 (볼 수있는 한). 그러나 dropbox에서 파일을 다운로드하는 데 사용되며 download_from_dropbox 함수에 이미 포함되어 있습니다. 좋은 휴가 보내십시오! – user3127517