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.

I add a new column, naming it "reverse_cost", and give it the same data in the shape_leng column.

enter image description here

But as I run the shortest path algorithm in pgadmin, I got an error message.

enter image description here

here's my sql code

SELECT * FROM shortest_path('
            SELECT gid as id,
                     start_id::int4 AS source, 
                     end_id::int4 AS target,
                     shape_leng::double precision as cost
                    FROM network',
            10, 17, true, true);

and here's the error

Error:  Error, reverse_cost is used, but query did't return 'reverse_cost' column

********** Error **********

Error: Error, reverse_cost is used, but query did't return 'reverse_cost' column
SQL status: XX000

As I change the code to this one, everything went well,

SELECT * FROM shortest_path('
            SELECT gid as id,
                     start_id::int4 AS source, 
                     end_id::int4 AS target,
                     shape_leng::double precision as cost
                    FROM network',
            10, 17, false, false);

enter image description here

so I want to know how to use reverse_cost in PostGIS?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

You haven't included the reverse cost in the query that gets the data. Add that column and it should work:

SELECT * FROM shortest_path('
    SELECT gid as id,
        start_id::int4 AS source, 
        end_id::int4 AS target,
        shape_leng::double precision as cost,
        shape_leng::double precision as reverse_cost
        FROM network',
    10, 17, true, true);

Also, you're not even using the cost (nor reverse_cost) columns from your table, but just the shape_leng with an alias. If you want to use the actual columns, change to:

SELECT * FROM shortest_path('
    SELECT gid as id,
        start_id::int4 AS source, 
        end_id::int4 AS target,
        cost::double precision,
        reverse_cost::double precision
        FROM network',
    10, 17, true, true);
share|improve this answer
    
Thank you, I edit your first code above like this: ` SELECT * FROM shortest_path(' SELECT gid as id, start_id::int4 AS source, end_id::int4 AS target, shape_leng::double precision as cost, rcost::double precision as reverse_cost FROM network', 17, 10, true, true);`, but when I copy the second one you posted I got another error. –  Heinz Apr 17 '13 at 14:48
add comment

Your Answer

 
discard

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.