[OSM-dev] Mercator projection used by mapnik/osm2pgsql

Jon Burgess jburgess777 at googlemail.com
Wed Sep 12 00:48:54 BST 2007


People have tried to use the PostgreSQL database generated by osm2pgsql
for things other than Mapnik and often have trouble getting the data to
align properly. I think I have uncovered a systemic error in the
projection used by osm2pgsql and the Mapnik osm.xml file. 

It just so happens that these errors cancel each other out so our Mapnik
tiles look just fine. However if you try to interpret the mercator data
in Postgresql you'll probably find it is off by several km compared to
other sources.

I have an interim fix for this but I'm reluctant to deploy it just yet
because it breaks the rendering of the shapefiles used for the coastline
etc. The full fix either requires some changes in the Mapnik code or I
need to reproject the world_boundaries shapefiles. The Mapnik problem is
being worked on and I want to wait for this to be fixed properly.

One the plus side, once I resolve this issue, the osm2pgsql code will
include a correct SRID and add a spatial_geometry definition which will
allow you to more easily reproject the data to any format you like, 

e.g. 

Here is the mercator data for a node in the DB:

test=> select osm_id,name,place,astext(way) from planet_osm_line where osm_id='4066748';
 osm_id  |      name       | place |                        astext
---------+-----------------+-------+-------------------------------------------------------
 4066748 | Basildon Square |       | LINESTRING(-50323.15 6725680.68,-50320.98 6725613.23)
(1 row)


Here is the same data reprojected to SRID:4326 (+proj=latlogn +datum=WGS84)

test=> select osm_id,name,place,astext(Transform(way,4326)) from planet_osm_line where osm_id='4066748';
 osm_id  |      name       | place |                                       astext
---------+-----------------+-------+-------------------------------------------------------------------------------------
 4066748 | Basildon Square |       | LINESTRING(-0.452060547900393 51.7734694813506,-0.452041054458728 51.7730935897849)
(1 row)

Or you can import the data in 4326 latlong format and reproject it to
the Mapnik/Google mercator projection using the SRID:900913 (which the
osm2pgsql code will add.)


	Jon








More information about the dev mailing list