OSM2pgsql, latlong, OpenStreetMap data, uDig = weird projection

Hi guys,

I have an issue trying to import OSM data on PostGIS.
I download an xml file from the CloudMade site.
I use this script to import the file into postgis (on Windows, latlong projection):

./osm2pgsql -U userId -W -H myhost -d maps -p myprefix -S default.style -c -l data.osm.bz2

This works, but when I visualise the spatial data on uDIG (default projection: WGS84) proportions are wrong. The vertical axis is much shorter than it is on regular online maps (e.g. openstreetmap.org, google maps, etc), like here: http://img7.imageshack.us/img7/8279/imagelw.png

So I read somewhere that the OSM data is stored in mercator, and I tried to run the same script with -m option:

./osm2pgsql -U userId -W -H myhost -d maps -p myprefix -S default.style -c -m data.osm.bz2

The command works but then I can’t visualise any data in uDig.
How can I load OSM data with the right SRS and then project it properly?

Cheers,
Mulone

WGS84 is not a projection. With ‘-l’, you store the positions as lat/lon coordinates. That means that you have to select the projection later in your application. I don’t know uDIG but I would say that you have to set the right projection there.

Otherwise, you can create the data already projected in spherical mercator with the ‘-m’ flag (which is the default anyway). But for this, you also have to load as prerequisite in the db the sql script “900913.sql” provided with osm2pgsql. Check the wiki.

Hi,

For the uDig user interface WGS84 means the same as EPSG:4326.

There should be no problem in viewing a map in whatever supported projection with uDig because it can change projections on-the-fly. If you have opened OSM data from PostGIS in native EPSG:4326 projection, just click the projection tab (in the middle underneath the map) and select 900913 (WGS84 / Google Mercator) any other suitable projection from the list and the map will look different.

I tested this with Windows XP, uDig 1.2 Milestone 9 version and PostGIS 8.2. I am not sure if reprojection is done totally on uDig side or if it makes queries to PostGIS with the selected projection. In the latter case also PostGIS must support EPSG:900913 as Pieren told. You can check if with SQL query
select * from spatial_ref_sys where srid=900913;

If definitions for the Google Mercator projection are missing you can find the SQL script from the same place than osm2pgsql utility.

You should see your data also with the other import option that you used. I cannot say why it failed for you. Perhaps the uDig “viewport” was outside the coverage of your data.

Thanks for your replies!
uDig doesn’t seem to support the Google Mercator EPSG:900913. The data on postgis seems ok, the srid is defined.

I can summarise what I’ve done:

I’m trying to render openstreetmap data on a WMS on MapServer.
The system used to work with epsg:4326 but in our project we need a GoogleMaps like projection and we chose epsg:900913.

These are the steps I followed to reimport everything for the new projection:

  1. download osm xml file from Cloudmade (e.g. Italy.osm.bz2)
  2. Run 900913.sql on my PostGIS
  3. import that file into PostGIS with command:

./osm2pgsql -U userid -W -H host -d maps -p myprefix -S default.style -c -m italy.osm.bz2

  1. At this point everything seems ok. The geometry columns have 900913 as SRID.
  2. update MapFile with:

WEB
METADATA
wms_srs “epsg:900913”

PROJECTION
“init=epsg:900913”
END

Then in each layer I put:

PROJECTION “init=epsg:900913” END

and all of the queries have: using srid=900913

  1. load the wms layer into OpenLayers
    with

var wms = new OpenLayers.Layer.WMS(“OpenStreetMap”, mainurl, {

units : ‘m’,
projection:new OpenLayers.Projection(“EPSG:900913”),

Unfortunately all I get is a grey empty image. Looking at the map server log I noticed that it’s full of:

[Mon Mar 15 17:49:44 2010].517000 msPostGISLayerWhichShapes query status: 2
[Mon Mar 15 17:49:44 2010].517000 msPostGISLayerWhichShapes got 0 records in result.
[Mon Mar 15 17:49:44 2010].517000 msPostGISLayerNextShape called.

With the other projection I was getting the records.

Do you have any idea about what could be wrong in my set up? I tried to debug it in several ways but I couldn’t find anything wrong.

Cheers,
Mulone

Hi,

As I wrote, I downloaded uDig 1.2 M9 version and it did give me 900913 support out of the box.

I am always testing WMS first with something that gives me a better control about what is really happening. Usually I send hand written WMS requests directly from a browser.

You can see the requests sent by your OpenLayers application from your Apache access log file. With my Windows installation it is under ms4w\Apache\logs. Check that the BBOX and SRS makes sense. To compare with, some OL application using our server is sending something like this:
/cgi-bin/WMS?LAYERS=my_layer&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&FORMAT=image%2Fpng&TRANSPARENT=true&TILED=true&TILESORIGIN=1229757.5465712,8139734.3664411&SRS=EPSG%3A900913&BBOX=2829757.5465712,8459734.3664411,3149757.5465712,8779734.3664411&WIDTH=256&HEIGHT=256

I suggest also to add DEBUG 5 into LAYER definitions in your mapfile, it will lead to more information logged into your MS_ERRORFILE.

My guess it that there is something wrong with projections and Mapserver just does not find anything from the place defined by SRS and BBOX combination.

UPDATE: we managed to reproject in google mercator the map on OpenLayers with this code:

http://www.copypastecode.com/24724

It looks ok but when I added a transparent Google Maps layer, our geometries are shifted south by about 30km.
Any idea of what might cause this issue?

BTW, we didn’t manage to reproject the geometries directly on MapServer, that kept crashing or generating latlon tiles.

Cheers,
Mulone