如何将分离的多边形分解成一个大的多边形?
How to dissolve separated polygons into a large one?
我有一个可以在 R 中读取的形状文件:
library(rgdal)
shape <- readOGR(dsn = "~/path", layer = "a")
我对覆盖所有多边形的整个区域感兴趣(此处为黑色曲线)。如何溶解所有多边形,即使是像这样分成一个多边形的多边形?
我愿意接受 R 或 Qgis 的解决方案
使用 R 和 sf
包,您可以制作联合(如果需要)shapefile 的凸包。由于您没有包含数据,我使用 sf
包中包含的 nc
数据来说明该方法。
library(dplyr)
library(sf)
library(ggplot2)
# setting up sample data,
# you'll need to use st_read() to read your shapefile, not readOGR()
nc <- st_read(system.file("shape/nc.shp", package="sf"))
#> Reading layer `nc' from data source
#> `.../sf/shape/nc.shp'
#> using driver `ESRI Shapefile'
#> Simple feature collection with 100 features and 14 fields
#> Geometry type: MULTIPOLYGON
#> Dimension: XY
#> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
#> Geodetic CRS: NAD27
nc <- nc[c(1:30, 85:81),] #Use some non-contiguous counties
# make a convex hull of the unioned geometries
nc_hull <- st_convex_hull(st_union(nc))
ggplot() +
geom_sf(data = nc, fill = NA, color = 'red') +
geom_sf(data = nc_hull, fill = NA, color = 'black')
由 reprex package (v2.0.1)
于 2022-03-18 创建
我有一个可以在 R 中读取的形状文件:
library(rgdal)
shape <- readOGR(dsn = "~/path", layer = "a")
我对覆盖所有多边形的整个区域感兴趣(此处为黑色曲线)。如何溶解所有多边形,即使是像这样分成一个多边形的多边形?
我愿意接受 R 或 Qgis 的解决方案
使用 R 和 sf
包,您可以制作联合(如果需要)shapefile 的凸包。由于您没有包含数据,我使用 sf
包中包含的 nc
数据来说明该方法。
library(dplyr)
library(sf)
library(ggplot2)
# setting up sample data,
# you'll need to use st_read() to read your shapefile, not readOGR()
nc <- st_read(system.file("shape/nc.shp", package="sf"))
#> Reading layer `nc' from data source
#> `.../sf/shape/nc.shp'
#> using driver `ESRI Shapefile'
#> Simple feature collection with 100 features and 14 fields
#> Geometry type: MULTIPOLYGON
#> Dimension: XY
#> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
#> Geodetic CRS: NAD27
nc <- nc[c(1:30, 85:81),] #Use some non-contiguous counties
# make a convex hull of the unioned geometries
nc_hull <- st_convex_hull(st_union(nc))
ggplot() +
geom_sf(data = nc, fill = NA, color = 'red') +
geom_sf(data = nc_hull, fill = NA, color = 'black')
由 reprex package (v2.0.1)
于 2022-03-18 创建