使用点、线和多边形重叠绘制栅格图应该可以正常工作,如下例所示。
我最好的猜测是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)
![在此处输入图像描述](https://i.stack.imgur.com/Gp8Df.png)