Changes between Version 1 and Version 2 of UserWikiVariableBuffer
- Timestamp:
- 11/25/19 10:43:50 (5 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
UserWikiVariableBuffer
v1 v2 3 3 Source: [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 4 5 Using the function given below, variable-distance buffers can be generated. 5 The function below generates variable-distance buffers. 6 It operates by creating the union of a series of segment buffers . 7 Each segment buffer is the convex hull of the buffers of the segment start and end points, 8 with 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.** 6 11 7 12 === Example === 8 13 {{{ 9 SELECT gid, ST_VariableBufferFromLine(geom,10.0) AS geom FROM mylines14 SELECT ST_VariableBufferFromLine( 'LINESTRING( 0 0, 100 0)' , 10 ); 10 15 }}} 11 16 … … 14 19 CREATE OR REPLACE FUNCTION ST_VariableBufferFromLine( 15 20 geom GEOMETRY, 16 Length_BufferSize_RatioNUMERIC21 end_dist NUMERIC 17 22 ) 18 19 23 RETURNS GEOMETRY AS 20 21 24 $BODY$ 22 25 23 26 WITH 24 27 step1 AS 25 (SELECT ST_DumpPoints(geom) AS dump, 26 ST_Length(geom) AS len, 28 (SELECT ST_DumpPoints(geom) AS dump, 27 29 geom), 28 30 step2 AS 29 31 (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), 32 35 step3 AS 33 36 (SELECT 34 ST_ConvexHull(ST_Union(geom, LEAD(geom) OVER(ORDER BY path))) AS geom37 ST_ConvexHull(ST_Union(geom, LEAD(geom) OVER(ORDER BY path))) AS geom 35 38 FROM step2) 36 39 SELECT ST_Union(geom) AS geom FROM step3 37 40 38 41 $BODY$ 39 40 42 LANGUAGE SQL; 41 43 }}}