Changes between Version 1 and Version 2 of UserWikiVariableBuffer


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

--

Legend:

Unmodified
Added
Removed
Modified
  • UserWikiVariableBuffer

    v1 v2  
    33Source: [https://gis.stackexchange.com/questions/340968/varying-size-buffer-along-a-line-with-postgis GIS StackExchange: Varying size buffer along a line with PostGIS]
    44
    5 Using the function given below, variable-distance buffers can be generated.
     5The function below generates variable-distance buffers.
     6It operates by creating the union of a series of segment buffers .
     7Each segment buffer is the convex hull of the buffers of the segment start and end points,
     8with the buffer distance computed proportionally to the fractional distance along the line.
     9
     10**Note: currently only the end distance can be given.  The start distance is approximately 0.**
    611
    712=== Example ===
    813{{{
    9 SELECT gid, ST_VariableBufferFromLine(geom,10.0) AS geom FROM mylines
     14SELECT ST_VariableBufferFromLine( 'LINESTRING( 0 0, 100 0)' , 10 );
    1015}}}
    1116
     
    1419CREATE OR REPLACE FUNCTION ST_VariableBufferFromLine(
    1520    geom GEOMETRY,
    16     Length_BufferSize_Ratio NUMERIC
     21    end_dist NUMERIC
    1722)
    18 
    1923RETURNS GEOMETRY AS
    20 
    2124$BODY$
    2225
    2326WITH
    2427    step1 AS
    25         (SELECT ST_DumpPoints(geom) AS dump,
    26         ST_Length(geom) AS len,
     28        (SELECT ST_DumpPoints(geom) AS dump, 
    2729        geom),
    2830    step2 AS
    2931        (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            ST_Buffer( (dump).geom,
     33                GREATEST(end_dist * ST_LineLocatePoint(geom, (dump).geom), 0.001)) AS geom
     34        FROM step1),
    3235    step3 AS
    3336        (SELECT
    34         ST_ConvexHull(ST_Union(geom, LEAD(geom) OVER(ORDER BY path))) AS geom
     37            ST_ConvexHull(ST_Union(geom, LEAD(geom) OVER(ORDER BY path))) AS geom
    3538        FROM step2)
    3639SELECT ST_Union(geom) AS geom FROM step3
    3740
    3841$BODY$
    39 
    4042LANGUAGE SQL;
    4143}}}