Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/advanced/chapter-12.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ This function:
* Assigns a ``source`` and a ``target`` identifiers to each road link
* It can logically "snap" nearby vertices within a certain tolerance by
assigning the same identifier.
* Creates a vertices table related to it.
* Creates a ways_vertices_pgr table related to it.
* Creates the basic indices.

.. code-block:: sql
Expand Down Expand Up @@ -150,7 +150,7 @@ To verify that there is a basic `Routing Network Topology`:

\d planet_osm_roads

Also a new table containing the vertices information was created:
Also a new table containing the ways_vertices_pgr information was created:

::

Expand Down
28 changes: 14 additions & 14 deletions docs/basic/graphs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ a graph.
Description of the function can be found in `pgr_extractVertices
<https://docs.pgrouting.org/latest/en/pgr_extractVertices.html>`__

Exercise 1: Create a vertices table
Exercise 1: Create a ways_vertices_pgr table
-------------------------------------------------------------------------------

.. rubric:: Problem

Create the vertices table corresponding to the edges in ``ways``.
Create the ways_vertices_pgr table corresponding to the edges in ``ways``.

.. rubric:: Solution

Expand All @@ -167,7 +167,7 @@ Create the vertices table corresponding to the edges in ``ways``.

.. literalinclude:: ../scripts/basic/graphs/create_vertices.txt

Reviewing the description of the vertices table
Reviewing the description of the ways_vertices_pgr table

.. literalinclude:: ../scripts/basic/graphs/graphs.sql
:start-after: vertices_description.txt
Expand All @@ -177,7 +177,7 @@ Reviewing the description of the vertices table

.. literalinclude:: ../scripts/basic/graphs/vertices_description.txt

Inspecting the information on the vertices table
Inspecting the information on the ways_vertices_pgr table

.. literalinclude:: ../scripts/basic/graphs/graphs.sql
:language: sql
Expand All @@ -189,12 +189,12 @@ Inspecting the information on the vertices table
.. literalinclude:: ../scripts/basic/graphs/selected_rows.txt


Exercise 2: Fill up other columns in the vertices table
Exercise 2: Fill up other columns in the ways_vertices_pgr table
-------------------------------------------------------------------------------

.. rubric:: Problem

Fill up geometry information on the vertices table.
Fill up geometry information on the ways_vertices_pgr table.

.. rubric:: Solution

Expand All @@ -211,7 +211,7 @@ Count the number of rows that need to be filled up.
.. rubric:: Update the ``geom`` and ``osm_id`` columns

* The update based on the ``source`` column from ``ways`` table and the ``id``
column of the vertices table.
column of the ways_vertices_pgr table.
* To update ``geom`` column, use the start point of the geometry on the ``ways``
table.
* Use the ``source_osm`` value to fill up ``osm_id`` column.
Expand All @@ -227,7 +227,7 @@ Count the number of rows that need to be filled up.

.. literalinclude:: ../scripts/basic/graphs/fill_columns_2.txt

Not expecting to be done due to the fact that some vertices are dead ends.
Not expecting to be done due to the fact that some ways_vertices_pgr are dead ends.

.. literalinclude:: ../scripts/basic/graphs/graphs.sql
:language: sql
Expand All @@ -241,7 +241,7 @@ Not expecting to be done due to the fact that some vertices are dead ends.
.. rubric:: Continue update the ``geom`` and ``osm_id`` columns

* The update based on the ``target`` column from ``ways`` table and the ``id``
column of the vertices table.
column of the ways_vertices_pgr table.
* To update ``geom`` column, use the end point of the geometry on the ``ways``
table.
* Use the ``target_osm`` value to fill up ``osm_id`` column.
Expand Down Expand Up @@ -305,7 +305,7 @@ Description of the function can be found in `pgr_connectedComponents
<https://docs.pgrouting.org/latest/en/pgr_connectedComponents.html>`__


Exercise 3: Set components on edges and vertices tables
Exercise 3: Set components on edges and ways_vertices_pgr tables
-------------------------------------------------------------------------------

.. rubric:: Problem
Expand All @@ -325,9 +325,9 @@ Create additional columns on the edges tables.

.. literalinclude:: ../scripts/basic/graphs/set_components1.txt

.. rubric:: Use the ``pgr_connectedComponents`` to fill up the vertices table.
.. rubric:: Use the ``pgr_connectedComponents`` to fill up the ways_vertices_pgr table.

- Use the results to store the component numbers on the vertices table.
- Use the results to store the component numbers on the ways_vertices_pgr table.

.. literalinclude:: ../scripts/basic/graphs/graphs.sql
:language: sql
Expand Down Expand Up @@ -358,14 +358,14 @@ Exercise 4: Inspect the components

Answer the following questions:

#. How many components are in the vertices table?
#. How many components are in the ways_vertices_pgr table?
#. How many components are in the edges table?
#. List the 10 components with more edges.
#. Get the component with the maximum number of edges.

.. rubric:: Solution

.. rubric:: 1. How many components are in the vertices table?
.. rubric:: 1. How many components are in the ways_vertices_pgr table?

Count the distinct components.

Expand Down
20 changes: 10 additions & 10 deletions docs/interactions/code/QGISfunctions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -439,17 +439,17 @@ FROM wrk_dijkstra('vehicle_net', 252643343, 302057309);


DROP VIEW IF EXISTS ch8_e1 ; CREATE VIEW ch8_e1 AS
-- Number of vertices in the original graph
-- Number of ways_vertices_pgr in the original graph
SELECT count(*) FROM ways_vertices_pgr;

-- Number of vertices in the vehicles_net graph
-- Number of ways_vertices_pgr in the vehicles_net graph
SELECT count(*) FROM ways_vertices_pgr
WHERE id IN (
SELECT source FROM vehicle_net
UNION
SELECT target FROM vehicle_net);

-- Number of vertices in the little_net graph
-- Number of ways_vertices_pgr in the little_net graph
SELECT count(*) FROM ways_vertices_pgr
WHERE id IN (
SELECT source FROM little_net
Expand All @@ -464,26 +464,26 @@ SELECT osm_id FROM ways_vertices_pgr

-- Closest osm_id in the vehicle_net graph
WITH
vertices AS (
ways_vertices_pgr AS (
SELECT * FROM ways_vertices_pgr
WHERE id IN (
SELECT source FROM vehicle_net
UNION
SELECT target FROM vehicle_net)
)
SELECT osm_id FROM vertices
SELECT osm_id FROM ways_vertices_pgr
ORDER BY the_geom <-> ST_SetSRID(ST_Point(39.291852, -6.811437), 4326) LIMIT 1;

-- Closest osm_id in the little_net graph
WITH
vertices AS (
ways_vertices_pgr AS (
SELECT * FROM ways_vertices_pgr
WHERE id IN (
SELECT source FROM little_net
UNION
SELECT target FROM little_net)
)
SELECT osm_id FROM vertices
SELECT osm_id FROM ways_vertices_pgr
ORDER BY the_geom <-> ST_SetSRID(ST_Point(39.291852, -6.811437), 4326) LIMIT 1;


Expand All @@ -510,7 +510,7 @@ BEGIN
final_query :=
FORMAT( $$
WITH
vertices AS (
ways_vertices_pgr AS (
SELECT * FROM ways_vertices_pgr
WHERE id IN (
SELECT source FROM %1$I
Expand All @@ -522,10 +522,10 @@ BEGIN
FROM wrk_dijkstra(
'%1$I',
-- source
(SELECT osm_id FROM vertices
(SELECT osm_id FROM ways_vertices_pgr
ORDER BY the_geom <-> ST_SetSRID(ST_Point(%2$s, %3$s), 4326) LIMIT 1),
-- target
(SELECT osm_id FROM vertices
(SELECT osm_id FROM ways_vertices_pgr
ORDER BY the_geom <-> ST_SetSRID(ST_Point(%4$s, %5$s), 4326) LIMIT 1))
)
SELECT
Expand Down
20 changes: 10 additions & 10 deletions docs/interactions/code/functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -439,17 +439,17 @@ FROM wrk_dijkstra('vehicle_net', 252643343, 302057309);



-- Number of vertices in the original graph
-- Number of ways_vertices_pgr in the original graph
SELECT count(*) FROM ways_vertices_pgr;

-- Number of vertices in the vehicles_net graph
-- Number of ways_vertices_pgr in the vehicles_net graph
SELECT count(*) FROM ways_vertices_pgr
WHERE id IN (
SELECT source FROM vehicle_net
UNION
SELECT target FROM vehicle_net);

-- Number of vertices in the little_net graph
-- Number of ways_vertices_pgr in the little_net graph
SELECT count(*) FROM ways_vertices_pgr
WHERE id IN (
SELECT source FROM little_net
Expand All @@ -464,26 +464,26 @@ SELECT osm_id FROM ways_vertices_pgr

-- Closest osm_id in the vehicle_net graph
WITH
vertices AS (
ways_vertices_pgr AS (
SELECT * FROM ways_vertices_pgr
WHERE id IN (
SELECT source FROM vehicle_net
UNION
SELECT target FROM vehicle_net)
)
SELECT osm_id FROM vertices
SELECT osm_id FROM ways_vertices_pgr
ORDER BY the_geom <-> ST_SetSRID(ST_Point(39.291852, -6.811437), 4326) LIMIT 1;

-- Closest osm_id in the little_net graph
WITH
vertices AS (
ways_vertices_pgr AS (
SELECT * FROM ways_vertices_pgr
WHERE id IN (
SELECT source FROM little_net
UNION
SELECT target FROM little_net)
)
SELECT osm_id FROM vertices
SELECT osm_id FROM ways_vertices_pgr
ORDER BY the_geom <-> ST_SetSRID(ST_Point(39.291852, -6.811437), 4326) LIMIT 1;


Expand All @@ -510,7 +510,7 @@ BEGIN
final_query :=
FORMAT( $$
WITH
vertices AS (
ways_vertices_pgr AS (
SELECT * FROM ways_vertices_pgr
WHERE id IN (
SELECT source FROM %1$I
Expand All @@ -522,10 +522,10 @@ BEGIN
FROM wrk_dijkstra(
'%1$I',
-- source
(SELECT osm_id FROM vertices
(SELECT osm_id FROM ways_vertices_pgr
ORDER BY the_geom <-> ST_SetSRID(ST_Point(%2$s, %3$s), 4326) LIMIT 1),
-- target
(SELECT osm_id FROM vertices
(SELECT osm_id FROM ways_vertices_pgr
ORDER BY the_geom <-> ST_SetSRID(ST_Point(%4$s, %5$s), 4326) LIMIT 1))
)
SELECT
Expand Down
26 changes: 13 additions & 13 deletions docs/scripts/basic/graphs/graphs.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DROP TABLE IF EXISTS vertices CASCADE;
DROP TABLE IF EXISTS ways_vertices_pgr CASCADE;
DROP VIEW IF EXISTS vehicle_net CASCADE;
DROP VIEW IF EXISTS taxi_net CASCADE;
DROP MATERIALIZED VIEW IF EXISTS walk_net CASCADE;
Expand All @@ -20,37 +20,37 @@ ORDER BY tag_id;
\o create_vertices.txt

SELECT id, in_edges, out_edges, x, y, NULL::BIGINT osm_id, NULL::BIGINT component, geom
INTO vertices
INTO ways_vertices_pgr
FROM pgr_extractVertices(
'SELECT gid AS id, source, target
FROM ways ORDER BY id');

\o vertices_description.txt
\dS+ vertices
\dS+ ways_vertices_pgr
\o selected_rows.txt
SELECT * FROM vertices Limit 10;
SELECT * FROM ways_vertices_pgr Limit 10;

\o fill_columns_1.txt
SELECT count(*) FROM vertices WHERE geom IS NULL;
SELECT count(*) FROM ways_vertices_pgr WHERE geom IS NULL;
\o fill_columns_2.txt
UPDATE vertices SET (geom, osm_id) = (ST_startPoint(the_geom), source_osm)
UPDATE ways_vertices_pgr SET (geom, osm_id) = (ST_startPoint(the_geom), source_osm)
FROM ways WHERE source = id;
\o fill_columns_3.txt
SELECT count(*) FROM vertices WHERE geom IS NULL;
SELECT count(*) FROM ways_vertices_pgr WHERE geom IS NULL;
\o fill_columns_4.txt
UPDATE vertices SET (geom, osm_id) = (ST_endPoint(the_geom), target_osm)
UPDATE ways_vertices_pgr SET (geom, osm_id) = (ST_endPoint(the_geom), target_osm)
FROM ways WHERE geom IS NULL AND target = id;
\o fill_columns_5.txt
SELECT count(*) FROM vertices WHERE geom IS NULL;
SELECT count(*) FROM ways_vertices_pgr WHERE geom IS NULL;
\o fill_columns_6.txt
UPDATE vertices set (x,y) = (ST_X(geom), ST_Y(geom));
UPDATE ways_vertices_pgr set (x,y) = (ST_X(geom), ST_Y(geom));


\o set_components1.txt
ALTER TABLE ways ADD COLUMN component BIGINT;

\o set_components2.txt
UPDATE vertices AS v SET component = c.component
UPDATE ways_vertices_pgr AS v SET component = c.component
FROM (
SELECT seq, component, node
FROM pgr_connectedComponents(
Expand All @@ -60,11 +60,11 @@ WHERE v.id = c.node;
\o set_components3.txt

UPDATE ways SET component = v.component
FROM (SELECT id, component FROM vertices) AS v
FROM (SELECT id, component FROM ways_vertices_pgr) AS v
WHERE source = v.id;

\o see_components1.txt
SELECT count(DISTINCT component) FROM vertices;
SELECT count(DISTINCT component) FROM ways_vertices_pgr;
\o see_components2.txt
SELECT count(DISTINCT component) FROM ways;
\o see_components3.txt
Expand Down
4 changes: 2 additions & 2 deletions docs/scripts/basic/graphs/images.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ INTO costMatrix_png
FROM pgr_dijkstraCostMatrix(
'SELECT * FROM vehicle_net',
ARRAY[@ID_1@, @ID_2@, @ID_3@, @ID_4@, @ID_5@])
JOIN vertices v1 ON (start_vid=v1.id)
JOIN vertices v2 ON (end_vid=v2.id);
JOIN ways_vertices_pgr v1 ON (start_vid=v1.id)
JOIN ways_vertices_pgr v2 ON (end_vid=v2.id);
Loading