如何基于线条定界创建多边形,如“特征到多边形”

时间:2017-10-04 16:40:11

标签: r

有没有办法根据线条划界创建多边形? 例如,如果我合并了许多不同的shapefile,我会看到新的"多边形"从他们的行的划界创建,但我有兴趣为这些新的多边形创建一个ID。与ArcGIS中的“特征到多边形”功能相同。

enter image description here

1 个答案:

答案 0 :(得分:0)

试试这个:

library(sp)
library(rgdal)
library(rgeos)
library(raster)
library(tmap)

id1 <- readOGR(dsn = "./ID1.kml", "ID1.kml")
id2 <- readOGR(dsn = "./ID2.kml", "ID2.kml")
id3 <- readOGR(dsn = "./ID3.kml", "ID3.kml")

x <- rbind(id1, id2, id3, makeUniqueIDs = TRUE)

plot(x)

id4 <- crop(id1, id2)
id4@data$Name <- "iD4"
id5 <- crop(id1, id3)
id5@data$Name <- "iD5"

id6 <- gDifference(id1, id2)
id6 <- SpatialPolygonsDataFrame(id6, data.frame(Name = "ID6", Description = ""))

id7 <- gDifference(id1, id3)
id7 <- SpatialPolygonsDataFrame(id7, data.frame(Name = "ID7", Description = ""))

x1 <- rbind(id1, id2, id3, id4, id5, id6, id7,  makeUniqueIDs = TRUE)

tm_shape(x1) + tm_polygons(col = "Name")

enter image description here