Skip to content

Instantly share code, notes, and snippets.

@mpurbo
Created June 21, 2011 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpurbo/1037518 to your computer and use it in GitHub Desktop.
Save mpurbo/1037518 to your computer and use it in GitHub Desktop.
Correct and transform SRID with PostGIS
-- 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