4

I have osm-file and I want to import it to the postgresql via osm2pgsql with custom projection EPSG:20022. I look to the help and found out any keys like -E EPSG: but when I try to do with it I get the data in SRID=4326. Is there a way how to fix it?

Andrey Maraev
  • 413
  • 1
  • 7
  • 20
  • Finally I found this post http://gis.stackexchange.com/questions/39138/how-to-reproject-all-geometries-in-a-postgis-table. It should help me I think. – Andrey Maraev Nov 26 '13 at 09:43

1 Answers1

6

You can find the source code of osm2pgsql here:

https://github.com/openstreetmap/osm2pgsql/blob/master/reprojection.c

and you will find this note in line 67:

/* hard-code the source projection to be lat/lon, since OSM XML always
* has coordinates in degrees. */
    pj_source = pj_init_plus("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs");

    /* hard-code the tile projection to be spherical mercator always.
* theoretically this could be made selectable but not all projections
* lend themselves well to making tiles; non-spherical mercator tiles
* are uncharted waters in OSM. */
    pj_tile = pj_init_plus(Projection_Info[PROJ_SPHERE_MERC].proj4text);

    /* now set the target projection - the only one which is really variable */
    if (proj >= 0 && proj < PROJ_COUNT)

and:

    fprintf (stderr, "Couldn't read EPSG definition (do you have /usr/share/proj/epsg?)\n");

I think it will be much easier for you to import the stuff using lat/long, and do the reprojection afterwards in the database.

The -E parameter seams to be implemented to choose EPSG:4326 or EPSG:900913, but others might not work.

For your postgis database, http://www.postgis.org/docs/ST_Transform.html shows you how to do a transformation. It is as exact as doing it by proj4, because it uses the same methods.

AndreJ
  • 76,698
  • 5
  • 86
  • 162
  • Thanks Andre for your reply. What does it mean? "do the reprojection afterwards in the database". Could you please show an example? – Andrey Maraev Nov 25 '13 at 11:59
  • Also does it mean that -E key is unavailable anymore? What inaccuracy will be after reprojection? – Andrey Maraev Nov 25 '13 at 12:07
  • I guess what Andre means is using a tool to do the projection transformation AFTER you worked with your data and still store it in EPSG:4326. The reprojection can be done using #pro4j or GIS tools like #QGIS.
    I'm not an expert, but IMHO the most OSM tools expect the default projection and will cause problems if there is something else...
    – Mapper Nov 25 '13 at 12:21
  • I extended my answer... – AndreJ Nov 25 '13 at 14:28
  • Andre, is it the same if I use something like: update osm_point set way=transform(way,20022); update osm_line set way=transform(way,20022); update osm_polygon set way=transform(way,20022); update geometry_columns set srid=20022 where f_table_name='osm_point'; update geometry_columns set srid=20022 where f_table_name='osm_line'; update geometry_columns set srid=20022 where f_table_name='osm_polygon'; – Andrey Maraev Nov 25 '13 at 14:46
  • From the doc page: The non ST_ functions not listed in this documentation are deprecated and will be removed in a future release so STOP USING THEM. – AndreJ Nov 25 '13 at 16:03