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