2012-02-14 6 views
10

셰이프 파일 개체 뒤에 "래스터"개체를 플로팅하려면 어떻게해야합니까? 점, 선셰이프 파일 뒤에 래스터 플로팅

require(rgdal) 
require(maptools) 
require(raster) 

myproj = "+proj=utm +zone=12 +north +ellps=WGS84 +units=m" 
shp = readShapeSpatial(fn.shp, proj4string = CRS(myproj)) 
ras = raster(fn.tif) 

plot(ras) 
plot(shp, bg="transparent", add=TRUE) 

답변

17

overploting을 래스터 플롯을, 다음의 예와 같이, 다각형, 그냥 잘 작동합니다 : 자신의 두 플롯 미세하지만 포인트는 래스터 이상 플롯되지 않습니다.

래스터 상단에 플롯하려고하는 Spatial* 개체가 플롯되는 영역 밖에 위치하는 것이 가장 좋습니다. rasterSpatial* 개체가 모두 동일한 CRS에 있고 경계 상자가 겹치는 (있다고 가정 할 때) 것을 확인 했습니까? (예 : bbox(shp)bbox(ras)을 시도하고 결과를 비교하십시오).

library(rgdal) 
library(raster) 
# Create a raster 
ras <- raster(ncols=36, nrows=18) 
ras[] <- runif(ncell(ras)) 
# Create a SpatialPoints object 
shpPts <- spsample(Spatial(bbox=bbox(ras)), 20, type="random") 
# Create a SpatialPolygons object 
p1 <- rbind(c(-10,0), c(140,60), c(160,0), c(140,-55), c(-10,0)) 
shpPolys <- SpatialPolygons(list(Polygons(list(Polygon(p1)), 1))) 

# Plot them, one layer after another 
plot(ras) 
plot(shpPts, pch=16, col="red", add=TRUE) 
plot(shpPolys, col="yellow", add=TRUE) 

enter image description here

+0

좋은 호출은, 내 래스터가 잘못 위치했다. 이것이 제대로 작동하는지 확인해 주셔서 감사합니다. – Benjamin