I imported data from a map extracted from OpenStreetMap. With osm2pgrouting I imported it into PostgreSQL, to be worked with pgRouting and PostGIS. Command used:
osm2pgrouting -f DIRECTORY/map.osm -d DATABASE -p 5432 -U postgres -W PASSWD-c mapconfig.xml --addnodes --attributes -- clean
He created the following table structure:
I am using the
pgr_dijkstra function to calculate a minimum cost route between two locations:
SELECT * FROM pgr_dijkstra('
SELECT gid as id, source, target, ST_Length(the_geom::GEOGRAPHY) AS cost,
ST_LENGTH(the_geom::GEOGRAPHY) AS reverse_cost
24212, 5521, directed := true
) as di
ON di.edge = ways.gid
order by seq;
It is working perfectly when I use
directed: = false. But when I put
directed: = true pgRouting is returning the same result. This is wrong because even with
directed: = true he is considering my unidirectional streets as bidirectional. The image below represents some return lines from my query:
oneway = YES and
one_way = 1 is a one-way street that the function should not be returning.
oneway = UNKNOWN and
one_way = 0 is my two-way street. The image below shows this one-way street that is being considered as a route path, which is wrong, is in the opposite direction of traffic. In the drawing it can be a bit confusing, but the street "Florestano de Macedo" is unidirectional, as shown by the return in the database. The figure is a bit confused because it is a street that passes next to a highway, and on the other side of the highway there is another street. But this problem occurs for any route with
directed: = true.
What am I doing wrong? Do I have to prepare/change my data in any way for these cases? Is my query wrong? PgRouting workshops only say to use directed as true or false, they do not mention data preparation for this.