Version 1 (modified by 5 years ago) ( diff ) | ,
---|
Variable-Distance Buffer
Source: GIS StackExchange: Varying size buffer along a line with PostGIS
Using the function given below, variable-distance buffers can be generated.
Example
SELECT gid, ST_VariableBufferFromLine(geom,10.0) AS geom FROM mylines
Code
CREATE OR REPLACE FUNCTION ST_VariableBufferFromLine( geom GEOMETRY, Length_BufferSize_Ratio NUMERIC ) RETURNS GEOMETRY AS $BODY$ WITH step1 AS (SELECT ST_DumpPoints(geom) AS dump, ST_Length(geom) AS len, geom), step2 AS (SELECT (dump).path[1], ST_Buffer((dump).geom, GREATEST(ST_LineLocatePoint(geom, (dump).geom)*len/Length_BufferSize_Ratio,0.001)) AS geom FROM step1), step3 AS (SELECT ST_ConvexHull(ST_Union(geom, LEAD(geom) OVER(ORDER BY path))) AS geom FROM step2) SELECT ST_Union(geom) AS geom FROM step3 $BODY$ LANGUAGE SQL;
Note:
See TracWiki
for help on using the wiki.