postgresql+postgis+pgrouting implementation of Shortest Path query (1)---line data processing and building topology

Source: Internet
Author: User
Tags postgresql postgis

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.