【问题标题】:Specific number of points within each polygon of a shape in RR中形状的每个多边形内的特定点数
【发布时间】:2020-12-18 13:05:27
【问题描述】:

我有一个包含大约 400 个不同大小的多边形的 shapefile。我一直在尝试创建一个随机点图层,在 400 个多边形中的每个多边形内具有特定数量的点。

我尝试使用 spsample 函数,但它生成了一个不尊重每个多边形的随机点层(它是整个 shapefile 的一般随机点层)。

举个例子:

Shape file

下载:biogeo.ucdavis.edu/data/diva/adm/USA_adm.zip

它是文件“USA_adm1”

这个 shapefile 包含 52 个多边形。我希望在 52 个多边形的每一个内放置特定数量的随机点。例如,每个州内随机分布 100 个点。

我希望你能帮助我。

谢谢

【问题讨论】:

  • 请提供您的多边形数据样本,否则很难提供帮助。
  • 你好@dvd280 我只是上传数据。

标签: r gis shapes point-in-polygon


【解决方案1】:

来自 sf 包,在 sf 对象上使用 st_sample

library(sf)
library(ggplot2)

# using data included with sf package,
#  it contains 100 polygons
nc <- st_read(system.file("shape/nc.shp", package="sf"))

# st_sample needs a vector telling it how many samples for each polygon
#  here we're using 3 for each polygon
samples_per_polygon <- rep(3, nrow(nc))

samples <- st_sample(nc, samples_per_polygon)


ggplot() + geom_sf(data = nc) + geom_sf(data = samples)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多