-
-
Save richarddunks/7740dc5761a6fd5ee1dbe92d01f08df7 to your computer and use it in GitHub Desktop.
A repost of the great function for reprojecting a shapefile from 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 hidden or 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: utmzone(geometry) | |
DROP FUNCTION utmzone(geometry); | |
Usage: SELECT ST_Transform(the_geom, utmzone(ST_Centroid(the_geom))) FROM sometable; */ | |
CREATE OR REPLACE FUNCTION utmzone(geometry) | |
RETURNS integer AS | |
$BODY$ | |
DECLARE | |
geomgeog geometry; | |
zone int; | |
pref int; | |
BEGIN | |
geomgeog:= ST_Transform($1,4326); | |
IF (ST_Y(geomgeog))>0 THEN | |
pref:=32600; | |
ELSE | |
pref:=32700; | |
END IF; | |
zone:=floor((ST_X(geomgeog)+180)/6)+1; | |
RETURN zone+pref; | |
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