2013-10-11 2 views
2

범위와 투영 시스템이 다른 두 개의 geotiff 파일에서 2 개의 부 그림을 사용하여 그림을 만들고 싶습니다. Rapideye 범위를 기반으로 플롯을 자르고 싶습니다. 어떻게해야합니까? 다음은 파일의 세부 사항입니다.다른 투영법을 사용하여 래스터를 자르는 방법

SPOT-VGT

class  : RasterLayer 
dimensions : 8961, 8961, 80299521 (nrow, ncol, ncell) 
resolution : 0.008928571, 0.008928571 (x, y) 
extent  : -20, 60.00893, -40.00893, 40 (xmin, xmax, ymin, ymax) 
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
data source : /AFRI_VGT_V1.3.tiff 
names  : g2_BIOPAR_WB.GWWR_201305110000_AFRI_VGT_V1.3 
values  : 0, 255 (min, max) 

RAPIDEYE는

class  : RasterStack 
dimensions : 14600, 14600, 213160000, 5 (nrow, ncol, ncell, nlayers) 
resolution : 5, 5 (x, y) 
extent  : 355500, 428500, 2879500, 2952500 (xmin, xmax, ymin, ymax) 
coord. ref. : +proj=utm +zone=36 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 
names  : /rapideye.tif 
min values :  0,   0,   0,  0,  0 
max values :   65535,  65535, 65535,   65535,  65535 

답변

3

이 가장 우아한 방법이되지 않을 수도 있지만 도움이 될 수 있습니다. 예를 기반으로 느슨하게 두 개의 예제 래스터를 만들었습니다. 그것들은 같은 투사와 범위를 가지고 있습니다.

library(raster) 
r1 <- raster(nrows=500, ncols=500, 
     ext=extent(c(-20, 60.00893, -40.00893, 40)), 
     crs='+proj=longlat +datum=WGS84') 
r1[] <- rnorm(500*500,0,1) 

r2 <- raster(nrows=50, ncols=50, 
     ext=extent(c(355500, 428500, 2879500, 2952500)), 
     crs='+proj=utm +zone=36 +datum=WGS84 +units=m') 
r2[] <- rnorm(50*50,0,1) 

래스터 R2, I 먼저 래스터 R2의 범위에서 spatialPolygon를 생성하고 정도를 이용하여 작물 래스터 R1 할 수 있도록, 두 번째의 돌기를 다각형 변환 그것을 좋은 투영을 할당하고, 세 번째 래스터 r1.

library(rgdal) 
# Make a SpatialPolygon from the extent of r2 
r2extent <- as(extent(r2), 'SpatialPolygons') 
# Assign this SpatialPolygon the good projection 
proj4string(r2extent) <- proj4string(r2) 
# Transform the projection to that of r1 
r2extr1proj <- spTransform(r2extent, CRS(proj4string(r1))) 

마지막으로, R1의 R2에 돌출의 정도를 나타내는 폴리곤 r2extr1proj를 사용하여 래스터 R1을 잘라낼 수있다. 그런 다음 두 래스터를 그립니다.

r1crop <- crop(r1, r2extr1proj) 
layout(matrix(c(1:2), nrow=1)) 
plot(r1crop) 
plot(r2) 
+0

+1 - 최상의 답변! 감사. –