Changes between Initial Version and Version 1 of UserWikiVariableBuffer


Ignore:
Timestamp:
11/25/19 10:04:50 (5 years ago)
Author:
mdavis
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • UserWikiVariableBuffer

    v1 v1  
     1= Variable-Distance Buffer =
     2
     3Source: [https://gis.stackexchange.com/questions/340968/varying-size-buffer-along-a-line-with-postgis GIS StackExchange: Varying size buffer along a line with PostGIS]
     4
     5Using the function given below, variable-distance buffers can be generated.
     6
     7=== Example ===
     8{{{
     9SELECT gid, ST_VariableBufferFromLine(geom,10.0) AS geom FROM mylines
     10}}}
     11
     12=== Code ===
     13{{{
     14CREATE OR REPLACE FUNCTION ST_VariableBufferFromLine(
     15    geom GEOMETRY,
     16    Length_BufferSize_Ratio NUMERIC
     17)
     18
     19RETURNS GEOMETRY AS
     20
     21$BODY$
     22
     23WITH
     24    step1 AS
     25        (SELECT ST_DumpPoints(geom) AS dump,
     26        ST_Length(geom) AS len,
     27        geom),
     28    step2 AS
     29        (SELECT (dump).path[1],
     30        ST_Buffer((dump).geom, GREATEST(ST_LineLocatePoint(geom, (dump).geom)*len/Length_BufferSize_Ratio,0.001)) AS geom
     31         FROM step1),
     32    step3 AS
     33        (SELECT
     34        ST_ConvexHull(ST_Union(geom, LEAD(geom) OVER(ORDER BY path))) AS geom
     35        FROM step2)
     36SELECT ST_Union(geom) AS geom FROM step3
     37
     38$BODY$
     39
     40LANGUAGE SQL;
     41}}}