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 am trying my first pgrouting in a roads shape file i load it in postgresql first, the table has osm_id gid name ref type oneway maxspeed

after i add columns source and target in table

ALTER TABLE roads ADD COLUMN "source" integer;
ALTER TABLE roads ADD COLUMN "target" integer;

After i make the topology with function

SELECT pgr_createTopology('roads', 0.0001, 'geom', 'gid');

make indexis

CREATE INDEX roads_source_idx ON roads("source");
CREATE INDEX roads_target_idx ON roads("target");

Add cost column and count the cost with geom colum use ST_LENGTH method

ALTER TABLE roads ADD COLUMN length double precision;
UPDATE roads SET length = ST_LENGTH(geom);

Add reverse cost colume and count it

ALTER TABLE roads ADD COLUMN reverse_cost double precision;
UPDATE roads SET reverse_cost = length;

last i run the distrack query is running in postgres if i try to run this query in QGIS is not runnig this is the first problem.

SELECT seq, id1 AS node, id2 AS edge, cost FROM pgr_dijkstra('
                SELECT gid AS id,
                         source::integer,
                         target::integer,
                         shape_leng::double precision AS cost
                        FROM roads',
                30, 300, false, false);

after i try to use A* i count the x1 y1 x2 y2 but the colums is empty and i dont know why insert the colums with this queries ALTER TABLE roads ADD COLUMN x1 double precision; ALTER TABLE roads ADD COLUMN y1 double precision; ALTER TABLE roads ADD COLUMN x2 double precision; ALTER TABLE roads ADD COLUMN y2 double precision; after i use this queries to field them but the columns stiil empty after execute

UPDATE roads SET x1 = ST_x(ST_startpoint(geom));
UPDATE roads SET y1 = ST_y(ST_startpoint(geom));
UPDATE roads SET x2 = ST_x(ST_endpoint(geom));
UPDATE roads SET y2 = ST_y(ST_endpoint(geom));

I read in net same versions have problem with startpoint and endpoint and i use the PointN but i still take empty columns

UPDATE roads SET x1 = ST_x(ST_PointN(geom, 1));
UPDATE roads SET y1 = ST_y(ST_PointN(geom, 1));
UPDATE roads SET x2 = ST_x(ST_PointN(geom, ST_NumPoints(geom)));
UPDATE roads SET y2 = ST_y(ST_PointN(geom, ST_NumPoints(geom)));

and the query for A*

SELECT seq, id1 AS node, id2 AS edge, cost FROM pgr_astar('
                SELECT gid AS id,
                         source::integer,
                         target::integer,
                         shape_leng::double precision AS cost,
                         x1, y1, x2, y2
                        FROM roads',
                30, 60, false, false);

how i show the routing in QGIS from postgresql i did it, but i still have problem with A* x1,y1 & x2,y2 after the update is still empty the columns x1 y1 x2 y2?

i try to use this queries but the x2y2 is not filling

UPDATE roads SET x1 = ST_X(ST_StartPoint(ST_geometryN(geom,1)));
UPDATE roads SET y1 = ST_Y(ST_StartPoint(ST_geometryN(geom,1)));
UPDATE roads SET x2 = ST_X(ST_EndPoint(ST_geometryN(geom,ST_NumPoints(geom))));
UPDATE roads SET y2 = ST_Y(ST_EndPoint(ST_geometryN(geom,ST_NumPoints(geom))));

Please if anyone can help me

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Try running the query in a terminal window or pgAdmin3 to see if it works there.

If you want to visualize the routing query in QGIS look at the workshop:

  • Create a database connection and add the “ways” table as a background layer.
  • Add another layer of the “ways” table but select Build query before adding it.

Then type the following into the SQL where clause field:

"gid" IN ( SELECT id2 AS gid FROM pgr_dijkstra('
                SELECT gid AS id,
                         source::integer,
                         target::integer,
                         length::double precision AS cost
                        FROM ways',
                30, 60, false, false) a LEFT JOIN ways b ON (a.id2 = b.gid)
)
share|improve this answer
    
The query is work find in pgAdmin3 is work only distrack but in A* i can fill the colums x1,y1 x2,y2 –  vagelis Oct 5 '14 at 11:38

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.