【问题标题】:Adding a Polygon to a SpatialPolygonsDataFrame将多边形添加到 SpatialPolygonsDataFrame
【发布时间】:2020-01-27 14:49:42
【问题描述】:

如何将多边形添加到 SpatialPolygonsDataFrame?

示例:下面的脚本将创建一个 SpatialPolygonsDataFrame。我想添加一个由现有多边形周围的大正方形组成的多边形。

   library(rgdal)
   dsn <- system.file("vectors", package = "rgdal")[1]
   Scotland <- readOGR(dsn=dsn , layer="scot_BNG")
   plot(Scotland)

首选的最终结果:

矩形成为 SpatialPolygonsDataFrame 的一部分很重要。因为我必须对数据框进行一些计算。所以手动添加一个正方形的可视层是不够的。

谢谢!

【问题讨论】:

    标签: r polygon spatial


    【解决方案1】:

    以下代码创建一个包围原始空间多边形的矩形,并将其作为空间多边形添加到原始形状中。

    library(rgdal)
    library(rgeos)
    
    dsn <- system.file("vectors", package = "rgdal")[1]
    Scotland <- readOGR(dsn=dsn , layer="scot_BNG")
    
    # change the width parameter to make the rectangle the desired size
    # this results in an extent object that surrounds the original shape
    eScotland <- extent(gBuffer(Scotland, width = 50000))
    # turn the extent into a Spatial Polygon
    pScotland <- as(eScotland, 'SpatialPolygons')
    crs(pScotland) <- crs(Scotland)
    newScotland <- bind(pScotland, Scotland)
    plot(newScotland)
    

    【讨论】:

      猜你喜欢
      • 2015-06-19
      • 2017-10-16
      • 1970-01-01
      • 2014-12-31
      • 2020-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-17
      相关资源
      最近更新 更多