This is an approach to this problem using that strategy of the 'inner central horizontal edge'. In resume:
- Create buffers of the polygons.
- Intersection of buffers to get overlaping zones.
- Extract intersection coords to create the new medium edge.
- Clip buffers with lines and assign the parcel ID.
Here are the layers to try out.
Here is the code:
library(sf)
library(mapview)
# read data
pol <- st_read('./data/Parcels.gpkg')
mapview(pol)
# make the buffer
polbuf <- st_buffer(pol, 10, 0)
mapview(pol)+mapview(st_buffer(pol, 10, 0), alpha.regions=0.1)
# get intersection points
p_intersect <- gIntersection(as(as_Spatial(polbuf)[1,], "SpatialLines"), as_Spatial(polbuf))
mapview(p_intersect)
# extract intersection coordinates
# adapted from: https://stackoverflow.com/questions/55106950/r-sf-intersect-lines-with-the-borders-of-multipolygons-extract-coordinates-of
line_1 <- st_as_sf(as(as_Spatial(polbuf), "SpatialLines"))
poly_1 <- st_as_sf(as(as_Spatial(polbuf), "SpatialLines"))
pnts <- st_intersection(line_1, st_cast(poly_1, "MULTILINESTRING", group_or_split = FALSE))
# catch points and get unique (as they will be duplicated...)
ps <- unique(pnts[st_geometry_type(pnts)=='MULTIPOINT',])
mapview(ps)+mapview(pol)+mapview(st_buffer(pol, 10, 0), alpha.regions=0.1)
# Create clipping lines with this points
# catched here: https://gis.stackexchange.com/questions/270725/r-sf-package-points-to-multiple-lines-with-st-cast
ls <- st_cast(ps, "LINESTRING")
mapview(ls)+mapview(ps)+mapview(pol)+mapview(st_buffer(pol, 10, 0), alpha.regions=0.1)
# split buffers with lines and consolidate
# cathed here: https://stackoverflow.com/questions/5726297/cut-polygons-using-contour-line-beneath-the-polygon-layers
library(rgeos)
lpi <- gIntersection(as_Spatial(polbuf), as_Spatial(ls))
blpi <- gBuffer(lpi, width = 0.000001)
dpi <- gDifference(as_Spatial(polbuf), blpi)
mapview(dpi)
# Asign parcel to each polygon
polbuf2 <- st_join(st_cast(st_as_sf(dpi), 'POLYGON'), pol)
mapview(pol)+mapview(polbuf2, alpha.regions = 0.2)