I want to create non-overlapping polygon layer from center line by applying the buffer to line layer in postgis. I am able to create polygon layer but how to avoid or resolve overlapped polygons.
select gid,st_multi(ST_union(ST_BUFFER(geom,10,'endcap=flat join=round'))) from roads group by gid
Using this query I am able to create polygon which is overlap at intersection
Due to 10 meter buffer distance polygon overlaps how to avoid or resolve this
I need expected output as non overlapping polygon with "gid" attribute. Any suggestion will always welcome. Thanks,Amit
Best Answer
If you don't have primary-secondary attribution to help you, you can still implement some basic logic to decide who's on the losing end of
ST_Difference
. For example, at a T-shaped intersection, you might specify that the road that passes through the intersection will retain its buffer, while the road that ends at the intersection will have its buffer clipped.To start, it would be helpful to have a function to express the "passes through tee" relationship. We can say that
A
passes through theA-B
tee if:A
intersectsB
A
andB
is an endpoint ofB
A
andB
is not an endpoint ofA
Turning this logic into a function:
However,
endpoints
isn't a PostGIS function, so we need to write it:Note that the
ST_Dump
subquery allows the function to work onMultiLineString
geometries.To apply these functions to our roads, we can first save the buffered geometries in a temporary table:
Then, to pull out the clipped buffers:
Some example output from this query is below:
A couple of notes on the above:
gid
to pick a winner.COALESCE
function substitutesPOLYGON EMPTY
for a null value, so that we get our original geometry back if there is nothing to clip against.buffered_geom
forgeom
in theST_Intersects
call.