Last active
March 7, 2023 03:19
-
-
Save datapolitan/9ef9489eac5686ca3b34 to your computer and use it in GitHub Desktop.
A repost of the code for ST_Buffer_Meters from this great post: http://www.gistutor.com/postgresqlpostgis/6-advanced-postgresqlpostgis-tutorials/58-postgis-buffer-latlong-and-other-projections-using-meters-units-custom-stbuffermeters-function.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Function: ST_Buffer_Meters(geometry, double precision) | |
DROP FUNCTION ST_Buffer_Meters(geometry, double precision); | |
Usage: SELECT ST_Buffer_Meters(the_geom, num_meters) FROM sometable; */ | |
CREATE OR REPLACE FUNCTION ST_Buffer_Meters(geometry, double precision) | |
RETURNS geometry AS | |
$BODY$ | |
DECLARE | |
orig_srid int; | |
utm_srid int; | |
BEGIN | |
orig_srid:= ST_SRID($1); | |
utm_srid:= utmzone(ST_Centroid($1)); | |
RETURN ST_transform(ST_Buffer(ST_transform($1, utm_srid), $2), orig_srid); | |
END; | |
$BODY$ LANGUAGE 'plpgsql' IMMUTABLE | |
COST 100; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment