My previous post on improving buffering geography in PostGIS*has three disadvantages:
CREATE OR REPLACE FUNCTION ST_Buffer(g1 geography, radius_of_buffer float, num_seg_quarter_circle integer, local_coord integer)RETURNS geometry AS$BODY$ WITH transformed AS ( SELECT ST_Transform(g1::geometry, local_coord) AS geom),buffered AS ( SELECT ST_Buffer(geom, radius_of_buffer, num_seg_quarter_circle) AS geom FROM transformed),transformed_4326 AS ( SELECT ST_Transform(geom, 4326) AS geom FROM buffered)SELECT * FROM transformed_4326 $BODY$LANGUAGE sql VOLATILE;We can also address point 3. Let’s perform a similar overload for buffer style parameters:
CREATE OR REPLACE FUNCTION ST_Buffer(g1 geography, radius_of_buffer float, buffer_style_parameters text, local_coord integer)RETURNS geometry AS$BODY$ WITH transformed AS ( SELECT ST_Transform(g1::geometry, local_coord) AS geom),buffered AS ( SELECT ST_Buffer(geom, radius_of_buffer, buffer_style_parameters) AS geom FROM transformed),transformed_4326 AS ( SELECT ST_Transform(geom, 4326) AS geom FROM buffered)SELECT * FROM transformed_4326 $BODY$LANGUAGE sql VOLATILE;Finally, we can use our special buffer style parameters with geography:
SELECT 0 AS id, ST_Buffer( ST_GeomFromText( 'LINESTRING(41 -81,41 -82,42 -82)' ), 500000, 'join=mitre mitre_limit=5.0', 3734);*
Example buffer of line with join=mitre mitre_limit=5.0.
This is a hack. Daniel’s note in the previous post still stands — it would be better to do this at a lower level within geography, rather than asking the user to know and employ the best possible local coordinate system.
أكثر...
- It doesn’t do this at a low enough level to automatically use the best available local coordinate system. This leaves it to the user to choose the best available local coordinate system. I should fix this (but I probably won’t just now…).
- It uses a different function name than you otherwise use for buffering. Can we use the same name as ST_Buffer?
- Finally, it won’t let you use all the other parameters that ST_Buffer exposes through the use of buffer style parameters.
CREATE OR REPLACE FUNCTION ST_Buffer(g1 geography, radius_of_buffer float, num_seg_quarter_circle integer, local_coord integer)RETURNS geometry AS$BODY$ WITH transformed AS ( SELECT ST_Transform(g1::geometry, local_coord) AS geom),buffered AS ( SELECT ST_Buffer(geom, radius_of_buffer, num_seg_quarter_circle) AS geom FROM transformed),transformed_4326 AS ( SELECT ST_Transform(geom, 4326) AS geom FROM buffered)SELECT * FROM transformed_4326 $BODY$LANGUAGE sql VOLATILE;We can also address point 3. Let’s perform a similar overload for buffer style parameters:
CREATE OR REPLACE FUNCTION ST_Buffer(g1 geography, radius_of_buffer float, buffer_style_parameters text, local_coord integer)RETURNS geometry AS$BODY$ WITH transformed AS ( SELECT ST_Transform(g1::geometry, local_coord) AS geom),buffered AS ( SELECT ST_Buffer(geom, radius_of_buffer, buffer_style_parameters) AS geom FROM transformed),transformed_4326 AS ( SELECT ST_Transform(geom, 4326) AS geom FROM buffered)SELECT * FROM transformed_4326 $BODY$LANGUAGE sql VOLATILE;Finally, we can use our special buffer style parameters with geography:
SELECT 0 AS id, ST_Buffer( ST_GeomFromText( 'LINESTRING(41 -81,41 -82,42 -82)' ), 500000, 'join=mitre mitre_limit=5.0', 3734);*
This is a hack. Daniel’s note in the previous post still stands — it would be better to do this at a lower level within geography, rather than asking the user to know and employ the best possible local coordinate system.
أكثر...