Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Is it possible to change the projection used in OSM2PO? I used the following command to generate a SQL file which I loaded into my database:

java -jar osm2po-core-4.2.30-signed.jar prefix=at "filename.osm.pbf.pbf"

This produce the file at_2po_4pgr.sql. I then loaded this file into my postgres database:

psql -U postgres  -d routing -a -f at_2po_4pgr.sql

As this table is based on SRID:4326, I wondered if there was any way of changing it so that I can use a different projection system. The columns in the table are as follows:

  id integer NOT NULL,
  osm_id bigint,
  osm_name character varying,
  osm_source_id bigint,
  osm_target_id bigint,
  clazz integer,
  flags integer,
  source integer,
  target integer,
  km double precision,
  kmh integer,
  cost double precision,
  reverse_cost double precision,
  x1 double precision,
  y1 double precision,
  x2 double precision,
  y2 double precision,
  geom_way geometry(LineString,4326),
  CONSTRAINT pkey_at_2po_4pgr PRIMARY KEY (id)

I know that I can use ST_Transform to convertgeom_way` into a different projection but I was unsure how to update any of the other values as I presumed some were based on the initial projection.

share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

How about

 ST_Transform(geom_way,<new crs>)

Then update x1,y1,x2,y2

 UPDATE table_name SET x1 = X(ST_StartPoint(geom_way))


Same for updating km and the related cost

 UPDATE table_name SET km = ST_Length(geom_way)
share|improve this answer
I'll try it out. I was a bit nervous changing it in case I misunderstood how these values were being calculated but this seems like a good approach. –  djq Oct 10 '12 at 18:28
Hmmm. The major question is, if pgRouting looks up the srs in the spatialRefSys- and geometry-colums-Table or not. If it depends on WGS84, there is nothing to change here because these values are only used for calculating heuristics. –  Carsten Oct 10 '12 at 19:10
While I cannot be absolutely certain without looking into the sources, I certainly wouldn't expect pgRouting to be CRS dependent. –  underdark Oct 10 '12 at 19:42
add comment

osm2po does export EPSG 4326 only.

As geom_way is a pure PosgGIS data type, you can indeed change it using ST_Transform. x1, y1, x2, y2 are hard coded values for pgRouting's aStar. I do not know what will happen if you transform them also.

share|improve this answer
I don't think it's possible to transform x1, y1, x2, y2 as they are not geometric or geographic objects. However, if they are only used for aStar maybe it it does not matter too much. –  djq Oct 10 '12 at 16:34
Yes, they are only used for aStar. Maybe Daniel is following this thread and can give you some more infos. –  Carsten Oct 10 '12 at 16:59
add comment

I've included how I did this using @underdark's suggestion. Perhaps of use to someone else:

CREATE TABLE osm2po_routing_prj AS
  ST_Length(ST_Transform(geom_way, 900913)) as km,
  ST_X(ST_StartPoint(ST_Transform(geom_way, 900913))) as x1,
  ST_Y(ST_StartPoint(ST_Transform(geom_way, 900913))) as y1,
  ST_X(ST_EndPoint(ST_Transform(geom_way, 900913))) as x2,
  ST_Y(ST_EndPoint(ST_Transform(geom_way, 900913))) as y2,
  ST_Transform(geom_way, 900913) as geom_way
FROM osm2po_routing;
share|improve this answer
Just be aware that length measurements in 900913 can be quite wrong. –  underdark Oct 11 '12 at 15:34
True, good point. –  djq Oct 11 '12 at 15:37
Anyway, I think it is not necessary to reproject a length. –  Carsten Oct 11 '12 at 15:46
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.