1, ALTER TABLE beijing_line ADD COLUMN source integer;
ALTER TABLE beijing_line ADD COLUMN target integer;
ALTER TABLE beijing_line ADD COLUMN length double precision;
UPDATE beijing_line SET length = st_length (THE_GEOM);
PS: Perform the following three-sentence SQL query against the database before executing the createtopology function:
CREATE EXTENSION PostGIS;
CREATE EXTENSION postgis_topology;
CREATE EXTENSION Fuzzystrmatch;
2. Select Pgr_createtopology (' Beijing_line ', 0.001,source:= ' source ', id:= ' gid ', target:= ' target ', the_geom:= ' the_ Geom ');
Select Pgr_createtopology (' Beijing_line ', 0.1,source:= ' source ', id:= ' gid ', target:= ' target ', the_geom:= ' the_geom ');
Setting the tolerance to a larger point may result in better results
3. SELECT * from Pgr_dijkstra ('
SELECT GID as ID,
Source::integer,
Target::integer,
Length::d ouble Precision as cost
From Beijing_line ',
(), false, false);
No query results do the following to try, or there may be no path between two points
Select source from Beijing_line;
Select target from Beijing_line;
Select length from Beijing_line;
4, all the points after the query:
SELECT St_astext (The_geom) from Pgr_dijkstra ('
SELECT GID as ID,
Source::integer,
Target::integer,
Length::d ouble Precision as cost
From Beijing_line ',
+, False, false) as Di
Join Beijing_line PT
on di.id2 = Pt.gid;
5. Write the path in a geometry file:
SELECT seq, id1 as node, id2 as Edge, Cost,the_geom into Dijkstra_res from Pgr_dijkstra ('
SELECT GID as ID,
Source::integer,
Target::integer,
Length::d ouble Precision as cost
From Beij hbs90.cn Ing_line ',
+, False, false) as Di
Join Beijing_line PT
On Di.id2 = pt. senta77.com GID;
Experienced the above steps, if all goes well, should be able to see the results, here no longer. At this point the preliminary preparations have been completed.
Refer to the following blog post ():
postgresql+postgis+pgrouting implementation of Shortest Path query (1)---line data processing and building topology