As the column 'kmh' shows speed limits wrong for my city, and I didn't want to modify the configuration file of osm2po for each type of road, is there a way to change the cost function? I wish:

cost= length

and not

cost= length/kmh


As you tagged your question with pgrouting I assume you want to use osm2po to generate the PostgreSQL tables. So why don't you update your database table after import?

UPDATE <table> SET cost = ST_Length(geom_way);

And if you prefer the length in unit meter, then you can transform the geometry into some Mercator projection:

UPDATE <table> SET cost = ST_Length(ST_Transform(geom_way,3857));
  • No, it is not possible because the query to calculate the shortest path between two point (pg routing) uses cost and reverse_cost. If I modify only the cost column the query will not be correct. Also I can't change the column reverse_cost in the same way! – Robert Feb 7 '13 at 18:06

or just

UPDATE <table> SET cost = km

and don't forget to set the reverse_cost if needed.

  • If I set also the reverse_cost in this way I have no information if a street is one-way or not!! – Robert Feb 8 '13 at 13:52
  • Ok. I solved it. I didn't know that I can used the if condition in sql. Thanks – Robert Feb 8 '13 at 14:11
  • Why "if"? Just UPDATE <table> SET reverse_cost=km WHERE reverse_cost < 1000000 – Carsten Feb 10 '13 at 8:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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