osm2pgsql issue


Well im not an expert user of all this GIS/OSM stuff so i would like some help :slight_smile:
I am trying to convert an OSM file with osm2pgsql.
I have my PostGIS setup and all , and already using it with some other files.
I want to convert the OSM i have to import it in the PostGIS and i always get thsi error

i run the command like this \osm2pgsql>osm2pgsql.exe -E 900913 -d gisdb xxxx.osm

I tried this small tutorial at the start of this page ( http://blog.geoserver.org/2009/01/30/geoserver-and-openstreetmap/ )

Any hints that could help me out?

Thank you


Looks like PostGIS is missing definitions for epsg:900913 projection. Do this:

INSERT INTO spatial_ref_sys (srid, auth_name, auth_srid, srtext, proj4text)
VALUES (900913, ‘spatialreference.org’, 900913,
‘PROJCS[“unnamed”,GEOGCS[“unnamed ellipse”,DATUM[“unknown”,
EXTENSION[“PROJ4”,“+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0
+lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs”]]’,
‘+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0
+k=1.0 +units=m +nadgrids=@null +wktext +no_defs’);

There is another manual at http://trac.osgeo.org/mapserver/wiki/RenderingOsmData.
I know I should say that Mapnik is the standard for rendering OSM data but there is plenty of space for other alternatives too.

Hi there thanx for the reply

Well i tried the following but i dont know if its correct way to do it

\osm2pgsql>osm2pgsql.exe -E 4326 -d gisdb xxxx.osm (where 4326 is the SRS i want to use)

It accepted it and entered the .osm to my PostGID Database but im not sure if its correct

The projection i want to use is this one.

GEOGCS[“Geographic Coordinate System”,DATUM[“WGS84”,SPHEROID[“WGS84”,6378137,298.257223560493]],PRIMEM[“Greenwich”,0],UNIT[“degree”,0.0174532925199433]]

Any ideas?
Thank you


It looks correct. I am using mostly an old Windows binary that does not have -E option. Instead is has option -l that is doing the same and imports data to EPSG:4326.

Ok then 1 last thing shall i edit the spl script in the osm2pgsql folder and add
GEOGCS[“Geographic Coordinate System”,DATUM[“WGS84”,SPHEROID[“WGS84”,6378137,298.257223560493]],PRIMEM[“Greenwich”,0],UNIT[“degree”,0.0174532925199433]]


Sorry, I don’t know. My guess is that there is no need to edit anything, just run with -E 4326 option.


I have the same problem, and i have inserted the record in the spatial_ref_sys table, but I continue getting the message:
$ osm2pgsql -E 900913 -d osm -U test planet.osm
osm2pgsql SVN version 0.69-exported
Couldn’t read EPSG definition (do you have /usr/share/proj/epsg?)

I can do it with epsg 4326 OK:
$ osm2pgsql -E 4326 -d osm -U test planet.osm

But the features don’t look like in the correct position when displayed on Geoserver/openlayers (and unable to display the line/roads layers).

Any idea?



It is some problem with paths. The final solution would be to add a suitable Windows environmental parameter with SET command before running osm2pgsql, I got once even imstructions for that. A simple way is just to run osm2pgsql.exe with defaults and do the update inside PostGIS. For example I am running these commands from psql prompt after import:
update osm_point set way=transform(way,3067);
update osm_line set way=transform(way,3067);
update osm_polygon set way=transform(way,3067);
update geometry_columns set srid=3067 where f_table_name=‘osm_point’;
update geometry_columns set srid=3067 where f_table_name=‘osm_line’;
update geometry_columns set srid=3067 where f_table_name=‘osm_polygon’;

The problem I had with osm2pgsql.exe and the suggested solution is described here:

Thank you for your reply.

I have imported the osm data by not specifying the epsg code (the default sr is 900913):

osm2pgsql  -d test -U postgres  -s -v planet.osm 

It would be ideal if the coordinate system could be converted to some other SRs (e.g. 4326). I tried the approach you provided:

update qrt.planet_osm_point set way=transform(way,4326);

but got the following error:

ERROR: AddToPROJ4SRSCache: couldn't parse proj4 string: '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs': squared eccentricity < 0

I have created the SR definition from osm2pgsql/900913.sql:

INSERT INTO spatial_ref_sys (srid, auth_name, auth_srid, srtext, proj4text)VALUES (900913,'EPSG',900913,'PROJCS["WGS84 / Simple Mercator",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS_1984", 6378137.0, 298.257223563]],PRIMEM["Greenwich", 0.0],UNIT["degree", 0.017453292519943295],AXIS["Longitude", EAST],AXIS["Latitude", NORTH]],PROJECTION["Mercator_1SP_Google"],PARAMETER["latitude_of_origin", 0.0],PARAMETER["central_meridian", 0.0],PARAMETER["scale_factor", 1.0],PARAMETER["false_easting", 0.0],PARAMETER["false_northing", 0.0],UNIT["m", 1.0],AXIS["x", EAST],AXIS["y", NORTH],AUTHORITY["EPSG","900913"]]','+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs');

Not sure whats wrong with the convert function on my database. I am using PostGIS1.4.2 with PostgreSQL 8.4.4 and Proj4.6.1-3 on Fedora12.



the error has gone after installing proj-nad:

yum install proj-nad.x86_64