I want to find an PostGIS algorithm to unite points of two geometries that are "near" to each other.
That is: I want a function, that takes as input two geometries, and returns 1 geometry, that consist of points of first geometry, second geometry, and points that are in specified radius of both geometries.
Currently I am using such function for this (tolerance radius is 2 meters):
SELECT ST_AsText( ST_Buffer( ST_Union( ST_Buffer( ST_GeomFromText( 'POLYGON ((0 0, 0 4.5, -2 4.5, -2 5.5, 0 5.5, 0 10, 1 10, 1 0, 0 0))', 3301 ), 2 ), ST_Buffer( ST_GeomFromText( 'POLYGON ((2 5, 5 8, 5 2, 2 5))', 3301 ), 2 ) ) , -2) );
It works reasonably well to unite points of two geometries, that are near to each other.
However, it has side effects. For example:
Input geometries:
Resulting geometry:
As can be seen from picture, some extra area is added to the "blue" geometry where the obtuse angles are. This is so, because using
ST_Buffer(ST_Buffer(geom, tolerance), -tolerance)
adds extra space to places where there are obtuse angles.
Is there an algorithm that would produce my asked result? Exact nature of how the two geometries are "glued" to each other is not so important. Buffering algorithm leaves smooth curve, but something like this would also be valid result (hand-drawn, I tried to add points that are in distance of 2 meters from both geometries):
If there are many algorithms, the fastest one will best suit my needs. But for comparison, slower algorithms will also be welcome (up-voted), if they excel by some other criteria.