多边形坐标数据框列表

时间:2019-07-19 07:51:43

标签: r dplyr polygon lapply

如何从簇边界坐标列表中创建多个多边形shapefile?

我有聚类点(xy坐标和点聚类值)

1 484913.2 282596.3 72

2 484913.2 282596.3 72

3 484913.2 282596.3 72

4 484913.2 282596.3 72

我创建点簇。点通过其聚类值选择。比我创建群集边框(凸包)。之后,我生成带有群集边界坐标的数据框。

    points <= st_as_sf(points, coords = c("x", "y"))
    split_soil <- split(points, points$cl)
    data <- lapply(split_soil, concaveman)
    data <- do.call('rbind', data)
    st_is_valid(data, reason = TRUE)

结果(每个群集边界坐标)-

1 list(c(484920.259, 484920.236, 484920.123, 484919.918, 484919.9...))

2 list(c(484868.886, 484868.876, 484868.865, 484869.077, 484869.078...))

3 list(c(484906.151, 484905.946, 484905.829, 484906.004, 484905.983..))

但是从这一刻开始,我遇到了问题。进一步集思广益-我尝试过的代码和方法。也许有人可以提供帮助(对不起,缺乏制作可复制数据的技能)。

    dt <- data %>%
      group_by(row.names()) %>%
      do(poly=select(., x, y) %>%Polygon()) %>%
      rowwise() %>%
      do(polys=Polygons(list(.$poly),.$row.names)) %>%
      {SpatialPolygons(.$polys)}
  

row.names.default()中的错误:缺少参数“ x”,没有默认值

来源:https://gis.stackexchange.com/questions/18311/instantiating-spatial-polygon-without-using-a-shapefile-in-r

    p <- lapply(data, Polygon)
    names(p) = seq_along(data)
    ps <- lapply(seq_along(p), function(i) Polygons(list(p[[i]]), ID = 
    names(p)[i] ))
    p2 <- SpatialPolygons(ps)
    sps_df <- SpatialPolygonsDataFrame(p2, data.frame(x = rep(NA, length(p)), 
    row.names = names(p)))

    rgdal::writeOGR(obj = sps_df,
                dsn = "border",
                layer = "border",
                driver = "ESRI Shapefile",
                overwrite_layer = TRUE)

来源:Creating spatialpolygons dataframe from list of polygons

  • 我相信此.shp导出部分可以。

主要任务:创建多个多边形shapefile,其中一个shapefile功能说明了一个群集边界多边形。

0 个答案:

没有答案