이것은 my previous similar question의 업데이트입니다. 동일한 작업 만이 sf
프레임 워크 내에서 수행해야합니다.r gis : sf가있는 다각형 사이의 내부 경계 확인
이지도에서 다각형, 빨간색 선 사이의 내부 경계를 식별해야합니다.
는
sp
틀 안에서 나는 Spacedman의
answer @ 포장 자체 작성 기능을 활용하는 데 사용됩니다. 여기에 :
identify_borders <- function(SPolyDF){
require(rgeos)
require(sp)
borders <- gDifference(
as(SPolyDF,"SpatialLines"),
as(gUnaryUnion(SPolyDF),"SpatialLines"),
byid=TRUE)
df <- data.frame(len = sapply(1:length(borders),
function(i) gLength(borders[i, ])))
rownames(df) <- sapply(1:length(borders),
function(i) [email protected][[i]]@ID)
SLDF <- SpatialLinesDataFrame(borders, data = df)
return(SLDF)
}
또는 raster::boundaries()
을 사용할 수 있습니다.
코드는 공간 데이터를 얻을 그것은 rmapshaper
정확하게 원하는 기능을 가지고 있으며, 잘 sf
객체와 함께 작동 밝혀졌다지도
# dev version of ggplot2 for geom_sf()
devtools::install_github("tidyverse/ggplot2")
library(tidyverse)
library(sf)
load(url("https://ikashnitsky.github.io/misc/171211-so-question-identify-borders/geodata.Rdata"))
ggplot() +
geom_sf(data = gd_nuts0) +
geom_sf(data = gd_borders, color = "red") +
coord_sf(datum = NA) +
theme_void()