Created
June 21, 2011 09:25
-
-
Save mpurbo/1037518 to your computer and use it in GitHub Desktop.
Correct and transform SRID with PostGIS
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
-- add temporary column for storing geometry with correct SRID | |
select AddGeometryColumn('places', 'geom_4301', 4301, 'GEOMETRY', 2); | |
-- add temporary column for storing geometry with target SRID | |
select AddGeometryColumn('places', 'geom_4326', 4326, 'GEOMETRY', 2); | |
BEGIN; | |
-- set the source temporary column with geometries with corrected SRID | |
UPDATE places SET geom_4301 = 'SRID=4301;POINT('|| ST_X(geom) || ' ' || ST_Y(geom) || ')'; | |
-- transform SRID to target temporary column | |
UPDATE places SET geom_4326 = ST_Transform(geom_4301, 4326); | |
-- move the newly corrected & transformed geometries to the original geometry column | |
UPDATE places p SET geom = geom_4326; | |
COMMIT; | |
-- remove temporary columns | |
select DropGeometryColumn('places', 'geom_4301'); | |
select DropGeometryColumn('places', 'geom_4326'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment