Thursday, 11 August 2016

coordinate system - Changing SRID of existing data in PostGIS?


While importing my shapefile data to PostGIS, I did not select the proper Projection.


How do I now change the SRID of the data, without transforming the Coordinates?



Answer




There is a single line function which does this for you. Just use the following SQL query:


select UpdateGeometrySRID('Schema Name', 'mytable', 'the_geom', newSRID) ;

But, if you are like me, you would be interested in the low level, miniature steps. Logically speaking, the above function is equivalent to the following four step process:




  1. In the geometry_columns table, update the SRID to the required value.




  2. Drop the contraint on the table, by using the following SQL statement



    ALTER TABLE mytable DROP CONSTRAINT enforce_srid_the_geom;




  3. Update the SRID'd of the geometry by using the following SQL statement


    UPDATE mytable SET the_geom = ST_SetSRID(the_geom, newSRID);




  4. Add the contraint back by using the following SQL statement


    ALTER TABLE mytable


    ADD CONSTRAINT enforce_srid_the_geom CHECK (st_srid(the_geom) = (newSRID));





No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...