【问题标题】:Adding a shapefile to raster将 shapefile 添加到栅格
【发布时间】:2018-04-16 16:37:34
【问题描述】:

编辑

x <- raster::getData('worldclim', var='tmin', res = 10)
s <- stack(x$tmin1,x$tmin12)
sp <- as(s, 'SpatialGridDataFrame')

fra <- raster::getData('GADM',country = 'FRA', level = 2)
my.layer <- list("sp.polygons", fra, col = "black")    
spplot(sp, names.attr = c("tmin1","tmin12"), sp.layout = my.layer)

如何在光栅顶部而不是下方绘制fra

【问题讨论】:

    标签: r raster shapefile


    【解决方案1】:

    你可以这样做:

    library(latticeExtra)
    spplot(s, names.attr = c("tmin1","tmin12")) + layer(sp.polygons(fra, lwd = 2))
    

    注意我用的是RasterStacks,不需要创建SpatialGridDataFrame。

    你也可以这样做

    p <- spplot(s, names.attr = c("tmin1","tmin12")) 
    p + layer(sp.polygons(fra, lwd = 2))
    

    如果你加载了ggplot2,这将触发错误:Error: Attempted to create layer with no geom.

    为避免这种情况,请使用 latticeExtra 命名空间前缀。

     p + latticeExtra::layer(sp.polygons(fra, lwd = 2))
    

    【讨论】:

    • 嗯.. 不知道为什么,但我收到此错误Error: Attempted to create layer with no geom
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-15
    相关资源
    最近更新 更多