0

At first I'm pretty new to routing in general and need to use it for my bachelor thesis so I am pretty time limited to learn it. If there is anymore Information I can give to find the Problem or if you just have a idea please inform me. Thanks!

I have a problem with the routing methods offered from the postgis extension pgrouting where the results are far away from being a shortest path.

I'm using a docker container containing postgis with the extension of pgrouting: https://hub.docker.com/r/pgrouting/pgrouting/

My Graph is created with osm2po on a "Niedersachsen" map from Geofabrik.de.

I just followed the tutorials given from osm2po quickstart to create a graph and put it into my database.

My Table is build as:

CREATE TABLE hh_2po_4pgr(id integer, osm_id bigint, osm_name character varying, osm_meta 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);
SELECT AddGeometryColumn('hh_2po_4pgr', 'geom_way', 4326, 'LINESTRING', 2);

The only thing i configured was setting my cost and reverse_cost to the distance. But without this change the issue stays the same. Also i did pgr_anaalyzeGraph which gave me back a OK which normally indicates that the graph should be configured fine.

When i now fire up a query like this:

SELECT * FROM pgr_astar('SELECT id, source, target, cost, x1, y1, x2, y2 FROM hh_2po_4pgr', 232516, 213104, FALSE, 2);

It gives me seemingly random routes that are either empty or way to long. The Id's I'm testing are pretty near to each other and all connected through streets. In this case it should be a route of a few hundret meters but I get a route with over 1000 Segments and almost 100km.

note: I also tryed other functions like pgr_djjkstra.

  • try specifying the `reverse_cost` in the `pgr_astar` edge sql. – JGH Oct 22 '21 at 16:23
  • Thanks for your response. I tryed it out and it seems to change nothing. Possibly because reverse_cost contains the same values as cost? – Sören Mehlhop Oct 25 '21 at 08:13
  • Double check that the graph is properly built then (ex: source/target really use the id, not osm_id etc), by following a few paths by hand. – JGH Oct 25 '21 at 13:03
  • Regarding the cost, no, some functions consider the absence of the reverse_cost in the query as "do not use the segment in reverse direction", which often means using a very convoluted path to join two nearby points – JGH Oct 25 '21 at 13:04
  • Ok so i checked my cost and reverse_cost colums and all values seem to be alright. Im using the real Ids and when I check the source and target Id's I get Streets that are nearby. So the Ids also seem to be correct. Is there anything else that can go wrong while building the graph? I recently tryed working with a .gph File and the osm2po built-in Routing and that worked just fine. I just took the .sql file created by the same process. – Sören Mehlhop Oct 25 '21 at 15:04

1 Answers1

0

Solution:

SELECT source FROM hh_2po_4pgr ORDER BY geom_way <-> ST_SetSRID(ST_Point(:pointX, :pointY),4326);

SELECT target FROM hh_2po_4pgr ORDER BY geom_way <-> ST_SetSRID(ST_Point(:pointX, :pointY),4326);

Use these SELECT Statements to get the right Id's to use in your pgrouting function.

If anyone has issues on pgrouting pls pn me. If I look at my Stackoverflow messages I will try helping you. Seems like the documentations and tutorials are kind of irritating.