1

I want to buffer a line in PostGIS. For this purpose I created a line, split it into fixed segments (8m) and run the buffer function.

--CREATE TABLE line(name char(10), geom geometry);
--INSERT INTO line VALUES('line','SRID=32637;LINESTRING(423458.0 6857171.2,  423439.8 6857244.5, 423501.7 6857327.8)');

WITH 
    segmentvertex AS (
        SELECT ST_Segmentize(geom, 8) AS geom
        FROM line)

SELECT ROW_NUMBER() OVER() AS segment_id, st_buffer(geom, 4, 'endcap=flat join=bevel') AS segment_geom

FROM (
SELECT dmp.path,
        ST_MakeLine(dmp.geom, LEAD(dmp.geom) OVER()) AS geom

FROM segmentvertex AS s, 
LATERAL ST_DumpPoints(s.geom) as dmp
)   t

WHERE  geom IS NOT NULL

Somehow I cannot handle the vertexes at the corners of the line which creates bad looking transition zones. On the left hand of the picture I inserted a segment wise buffer based on output of the GRASS v.split tool in QGIS 3.1 which is more looking like expected.

enter image description here

How can I achieve the same result in PostGIS like in QGIS? Im using PostGIS 2.5.1

  • The segments are not of equal size because st_segmentize only adds vertices so that the distance between two vertices does not exceed the given length. By creating a new line between every vertices, you end up with smaller segments that break at every inflection point. Using st_lineSubstring instead (as suggest here will lead to results similar to what is on the left. BUT, in both case, if a segment happens to end on an inflection point, the buffer will look like on the right. – JGH May 15 at 18:42
  • I want to split the line into segments with a fixed width (e.g.8m). So far I know st_segmentize just apply the segmentation based on a proportional value. – DrSnuggles May 18 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.