What algorithm to use to correct (average) the borderline between 2 polygons? All I know is that they have their own borderlines very close to each other. Sometimes they may overlap, otherwise not.

enter image description here

As in the image it's visible the common line is fatter than outside borders so it's not ok.

I'd require some average line or just common border - make them adjacent. Those differences are very small so averaging is ok.


Given p1 and p2 as SpatialPolygons I tried the following:

sf_p1 = sf::st_as_sf(p1)
sf_p2 = sf::st_as_sf(p2)
sf_u = sf::st_union(sf_p1, sf_p2)
d = gDistance(p1, p2)

The plot remains the same. d takes 3.03 so I guess there's a little gap between them. I'd probably use buffers? But how?

  • Often in these cases the easiest solution is to find a version of your dataset where the boundaries are overlapping. Failing that you need to build the topology and eliminate the duplicate arcs and then rebuild the polygons. I think the spbabel function might be useful here but without your data I can't be sure. Can you share? Also if its only two polygons you could do the topology ops "by hand" by subsetting the polygons.... – Spacedman Jul 16 at 22:50
  • I've flagged this as a duplicate with a solution that requires running an external utility which currently isn't implemented as an R package. – Spacedman Jul 17 at 8:48

Browse other questions tagged or ask your own question.