Use PostGIS to Transform Map Data Projection


Not every map data set you come across is WGS84, unfortunately.  For example, I just needed to mix some IGN Spain data (in ETRS89) with some OpenStreetMap data (which was in WGS84). Here’s a quick fix.

Let PostGIS Do The Work

Load the data into PostgreSQL/PostGIS using osm2pgsql and shp2pgsql (or the SPIT plugin in Quantum GIS) or whatever.
Then you can create a new table, for example:

create table my_new_table_in_wgs84 as select gid, st_transform(the_old_table.the_geom, 4326) as the_geom from the_old_table;

Then you need to do a little housekeeping so that PostGIS knows what to look for in that new table’s geometry column:

select populate_geometry_columns('public.my_new_table_in_wgs84'::regclass);