Ben*_*min 11 r raster r-maptools rgdal
如何在shapefile对象后面绘制"栅格"对象?两者都可以自己绘制,但是这些点不会覆盖栅格:
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)
Run Code Online (Sandbox Code Playgroud)
Jos*_*ien 18
使用点,线和多边形过度绘制栅格图应该可以正常工作,如下例所示.
我最好的猜测是,Spatial*
您尝试在栅格顶部绘制的对象落在绘制区域之外.您是否检查过两个raster
和Spatial*
对象是否在同一个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)
Run Code Online (Sandbox Code Playgroud)