Stephen Mather: ST_Buffer for those who want really round geographic circles

المشرف العام

Administrator
طاقم الإدارة
A little functionality request from @antoniolocandro on twitter:

ST_buffer for geography has no option for quad_segs, alternative so buffer looks nice not jagged? cc @smathermather

— Antonio Locandro (@antoniolocandro) January 8, 2016



Ask and ye might receive. Let’s build a function that will take your input geography, how far you want to buffer (in local coordinates) number of segments you want in a quarter, and what local coordinate system you want to use for your buffer as an EPSG code.

CREATE OR REPLACE FUNCTION zz_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 geomFROM transformed),transformed_4326 AS (SELECT ST_Transform(geom, 4326) AS geom FROM buffered)SELECT * FROM transformed_4326$BODY$LANGUAGE sql VOLATILECOST 100;Now let’s use this:

SELECT 0 AS id, zz_buffer(ST_GeomFromText ('POINT(-81 41)', 4326) , 15000, 2, 3734)
Image of 8 segment buffer from geography.


Now, we can test which level of smoothness we like best:

SELECT 0 AS id, zz_buffer(ST_GeomFromText ('POINT(-81 41)', 4326) , 15000, generate_series, 3734)FROM generate_series(1,50)
Square, Octagon, etc. generated from new buffer function.


Zoom in of different buffer smoothnesses.





أكثر...
 
أعلى