2

I'm following the instrcutions here step by step;

Since my data is a custom road data that I couldn't find in Open Street Map I've followed these steps;

  • Road data in SHP format transferred to PostgreSQL using Postgis Shapefile Loader.
  • MULTISTRINGLINE data transformed to LINESTRING
  • Topology created for the data using pgr_createtopology function
  • Topology analyzed using pgr_analyzeGraph function
  • Errors found in analyze are fixed using pgr_nodeNetwork function
  • Topology recreated with new data table and analysis have been done similarly to first and second steps.

The problem starts from here; in documentation it says a column named old_id should be added to data table to keep track of original id's. Only segmented edges are added to table using the SQL statement;

insert into edge_table (old_id,dir,cost,reverse_cost,the_geom)
    (with
    segmented as (select old_id,count(*) as i from edge_table_noded group by old_id)
    select  segments.old_id,dir,cost,reverse_cost,segments.the_geom
            from edge_table as edges join edge_table_noded as segments on (edges.id = segments.old_id)
            where edges.id in (select old_id from segmented where i>1) );

When I run the statement above I get this error;

ERROR: column "cost" of relation "path" does not exist

In fact none of the functions I've runned while creating the nodes adds a cost column to data table. Should I add cost manually? If so how can this be done ? Documentation doesn't mention about cost. It sounds like it is automatically generated like the other columns such as source and target.

1 Answer 1

2

I'm not sure, but here's my guess: pgrouting is being agnostic as to what the cost is, since it could be calculated in different ways (is it length? or is it time? does it consider traffic, elevation, etc?).

You'll see in some examples here that the cost is calculated "on-the-fly" in the query that does the actual routing: https://workshop.pgrouting.org/2.5/en/chapters/shortest_path.html#exercise-3-many-pedestrians-departing-from-the-same-location.

My solution to this problem was to use the edge length as the cost and it's negative as the reverse cost:

SELECT * FROM pgr_dijkstra(
'SELECT gid AS id,
     source,
     target,
     ST_Length(the_geom) AS cost,
     -ST_Length(the_geom) AS reverse_cost
    FROM ways',
1253, ARRAY[1060, 1661],
directed := false);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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