Updating Projections and PostGIS
I imported some data from the MAGIC server at UCONN into PostGIS. Unfortunately it did not recognize the projection in the prj file or shp2pgsql does use the projection information associated with the shapefile. [UPDATE: bitner just helped me see what was right in front of my eyes the whole time – shp2pgsql has a -s flag to specify the SRID. Live and learn] When I imported the data it has a SRID (projection identifier) of -1. I hopped on the IRC channel and the good folks helped me figure out all the places I need to update the information and now for my own benefit I am going to write it out here. My table name is leach (from the leachate data) and the geometry column is titled: the_geom.
So we need to update all of these to the correct projection SRID (in this case CT State Plane NAD 83 Feet) which for PostGIS is SRID 2234. I will defer to another day how you figure out which SRID you need.
Here are the statements to carry it out:
1. Drop the constraint otherwise you can’t do any changes on the leach table:
ALTER TABLE leach DROP CONSTRAINT “enforce_srid_the_geom” RESTRICT;
2. Alter the geometry column to incorporate the new SRID:
UPDATE leach SET the_geom = ST_SetSRID(the_geom, 2234);
3. Reapply the contstraint on the geometry:
ALTER TABLE leach ADD CONSTRAINT “enforce_srid_the_geom” CHECK (SRID(the_geom)=2234);
4. Update the geometry column table to have the right SRID:
UPDATE geometry_columns SET SRID=2234 WHERE f_table_name=’leach’;
And now you should be good to go. Thanks again to bitner and hobu in the IRC channel and this discussion post from the PostGIS-user forum.
As a feature request – perhaps someone could write the pgsql to do all these steps at once and bundle it in the product. [UPDATE 2 – of course after writing this post I come across this method: UpdateGeometrySRID([<schema_name>], <table_name>, <column_name>, <srid>) – which Updates the SRID of all features in a geometry column updating constraints and reference in geometry_columns. /me tries to remove egg from face] Or perhaps the shp2pgsql needs to do a better job importing the projection info if there is a .prj file present – though I suspect this would be a much trickier problem.