pgr_withPointsDD - Proposed

pgr_withPointsDD - Returns the driving distance from a starting point.

Advertencia

Funciones propuestas para la próxima versión mayor.

  • No están oficialmente en la versión actual.

  • Es probable que oficialmente formen parte del próximo lanzamiento:

    • Las funciones hacen uso de ENTEROS y FLOTANTES

    • Es posible que el nombre no cambie. (Pero todavía puede)

    • Es posible que la firma no cambie. (Pero todavía puede)

    • Es posible que la funcionalidad no cambie. (Pero todavía puede)

    • Se han hecho pruebas con pgTap. Pero tal vez se necesiten más.

    • Es posible que la documentación necesite un refinamiento.

_images/boost-inside.jpeg

Adentro: Boost Graph

Disponibilidad

  • Version 2.2.0

    • Nueva función propuesta

Descripción

Modify the graph to include points and using Dijkstra algorithm, extracts all the nodes and points that have costs less than or equal to the value **distance** from the starting point. The edges extracted will conform the corresponding spanning tree.

Firmas

pgr_withPointsDD(Edges SQL, Points SQL, Root vid, distance
   [, directed] [, driving_side] [, details])
pgr_withPointsDD(Edges SQL, Points SQL, Root vids, distance
   [, directed] [, driving_side] [, details] [, equicost])
RETURNS SET OF (seq, [start_vid,] node, edge, cost, agg_cost)

Vértice único

pgr_withPointsDD(Edges SQL, Points SQL, Root vid, distance
   [, directed] [, driving_side] [, details])
RETURNS SET OF (seq, node, edge, cost, agg_cost)
Ejemplo:

Right side driving topology, from point \(1\) within a distance of \(3.3\) with details.

SELECT * FROM pgr_withPointsDD(
  'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
  'SELECT pid, edge_id, fraction, side from pointsOfInterest',
  -1, 3.3,
  driving_side => 'r',
  details => true);
 seq | node | edge | cost | agg_cost
-----+------+------+------+----------
   1 |   -1 |   -1 |    0 |        0
   2 |    5 |    1 |  0.4 |      0.4
   3 |    6 |    1 |    1 |      1.4
   4 |   -6 |    4 |  0.7 |      2.1
   5 |    7 |    4 |  0.3 |      2.4
(5 rows)

Múltiples vértices

pgr_withPointsDD(Edges SQL, Points SQL, Root vids, distance
   [, directed] [, driving_side] [, details] [, equicost])
RETURNS SET OF (seq, start_vid, node, edge, cost, agg_cost)
Ejemplo:

From point \(1\) and vertex \(16\) within a distance of \(3.3\) with equicost on a directed graph

SELECT * FROM pgr_withPointsDD(
  'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
  'SELECT pid, edge_id, fraction, side from pointsOfInterest',
  ARRAY[-1, 16], 3.3,
  driving_side => 'l',
  equicost => true);
 seq | start_vid | node | edge | cost | agg_cost
-----+-----------+------+------+------+----------
   1 |        -1 |   -1 |   -1 |    0 |        0
   2 |        -1 |    6 |    1 |  0.6 |      0.6
   3 |        -1 |    7 |    4 |    1 |      1.6
   4 |        -1 |    5 |    1 |    1 |      1.6
   5 |        -1 |    3 |    7 |    1 |      2.6
   6 |        -1 |    8 |   10 |    1 |      2.6
   7 |        16 |   16 |   -1 |    0 |        0
   8 |        16 |   11 |    9 |    1 |        1
   9 |        16 |   15 |   16 |    1 |        1
  10 |        16 |   17 |   15 |    1 |        1
  11 |        16 |   10 |    3 |    1 |        2
  12 |        16 |   12 |   11 |    1 |        2
(12 rows)

Parámetros

Columna

Tipo

Descripción

Edges SQL

TEXT

Edges SQL as described below

Points SQL

TEXT

Points SQL as described below

Root vid

BIGINT

Identifier of the root vertex of the tree.

  • Negative values represent a point

Root vids

ARRAY[ANY-INTEGER]

Array of identifiers of the root vertices.

  • Negative values represent a point

  • \(0\) values are ignored

  • For optimization purposes, any duplicated value is ignored.

distancia

FLOAT

Upper limit for the inclusion of a node in the result.

Optional parameters

Columna

Tipo

x Defecto

Descripción

directed

BOOLEAN

true

  • When true the graph is considered Directed

  • When false the graph is considered as Undirected.

With points optional parameters

Parámetro

Tipo

x Defecto

Descripción

driving_side

CHAR

b

Value in [r, l, b] indicating if the driving side is:

  • r for right driving side.

  • l for left driving side.

  • b for both.

details

BOOLEAN

false

  • When true the results will include the points that are in the path.

  • When false the results will not include the points that are in the path.

Driving distance optional parameters

Columna

Tipo

x Defecto

Descripción

equicost

BOOLEAN

true

  • When true the node will only appear in the closest from_v list.

  • When false which resembles several calls using the single starting point signatures. Tie brakes are arbitrary.

Inner Queries

Edges SQL

Columna

Tipo

x Defecto

Descripción

id

ANY-INTEGER

Identificador de la arista.

source

ANY-INTEGER

Identificador del primer vértice de la arista.

target

ANY-INTEGER

Identificador del segundo vértice de la arista.

cost

ANY-NUMERICAL

Weight of the edge (source, target)

reverse_cost

ANY-NUMERICAL

-1

Weight of the edge (target, source)

  • When negative: edge (target, source) does not exist, therefore it’s not part of the graph.

Donde:

ENTEROS:

SMALLINT, INTEGER, BIGINT

FLOTANTES:

SMALLINT, INTEGER, BIGINT, REAL, FLOAT

Points SQL

Parámetro

Tipo

x Defecto

Descripción

pid

ANY-INTEGER

value

Identifier of the point.

  • Use with positive value, as internally will be converted to negative value

  • If column is present, it can not be NULL.

  • If column is not present, a sequential negative value will be given automatically.

edge_id

ANY-INTEGER

Identificador de la arista «más cercana» al punto.

fraction

ANY-NUMERICAL

El valor en <0,1> que indica la posición relativa desde el primer punto de la arista.

side

CHAR

b

Value in [b, r, l, NULL] indicating if the point is:

  • In the right r,

  • In the left l,

  • In both sides b, NULL

Donde:

ENTEROS:

SMALLINT, INTEGER, BIGINT

FLOTANTES:

SMALLINT, INTEGER, BIGINT, REAL, FLOAT

Columnas de Resultados

Returns SET OF (seq, [start_vid,] node, edge, cost, agg_cost)

Parámetro

Tipo

Descripción

seq

BIGINT

Sequential value starting from \(1\).

[start_vid]

BIGINT

Identifier of the root vertex.

node

BIGINT

Identifier of node within the limits from from_v.

edge

BIGINT

Identifier of the edge used to arrive to node.

  • \(0\) when node = from_v.

cost

FLOAT

Costo por recorrer edge.

agg_cost

FLOAT

Aggregate cost from from_v to node.

Donde:

ENTEROS:

SMALLINT, INTEGER, BIGINT

ANY-NUMERIC:

SMALLINT, INTEGER, BIGINT, REAL, FLOAT, NUMERIC

Ejemplos Adicionales

Use pgr_findCloseEdges in the Points SQL.

Find the driving distance from the two closest locations on the graph of point (2.9, 1.8).

SELECT * FROM pgr_withPointsDD(
  $e$ SELECT * FROM edges $e$,
  $p$ SELECT edge_id, round(fraction::numeric, 2) AS fraction, side
      FROM pgr_findCloseEdges(
        $$SELECT id, geom FROM edges$$,
        (SELECT ST_POINT(2.9, 1.8)),
        0.5, cap => 2)
  $p$,
  ARRAY[-1, -2], 2.3,
  driving_side => 'r',
  details => true);
 seq | start_vid | node | edge | cost | agg_cost
-----+-----------+------+------+------+----------
   1 |        -1 |   -1 |   -1 |    0 |        0
   2 |        -1 |   11 |    5 |  0.2 |      0.2
   3 |        -1 |    7 |    8 |    1 |      1.2
   4 |        -1 |   12 |   11 |    1 |      1.2
   5 |        -1 |   16 |    9 |    1 |      1.2
   6 |        -1 |   -2 |    8 |  0.9 |      2.1
   7 |        -1 |    3 |    7 |    1 |      2.2
   8 |        -1 |    6 |    4 |    1 |      2.2
   9 |        -1 |    8 |   10 |    1 |      2.2
  10 |        -1 |   15 |   16 |    1 |      2.2
  11 |        -1 |   17 |   13 |    1 |      2.2
  12 |        -2 |   -2 |   -1 |    0 |        0
  13 |        -2 |   11 |    8 |  0.1 |      0.1
  14 |        -2 |    7 |    8 |    1 |      1.1
  15 |        -2 |   12 |   11 |    1 |      1.1
  16 |        -2 |   16 |    9 |    1 |      1.1
  17 |        -2 |    3 |    7 |    1 |      2.1
  18 |        -2 |    6 |    4 |    1 |      2.1
  19 |        -2 |    8 |   10 |    1 |      2.1
  20 |        -2 |   15 |   16 |    1 |      2.1
  21 |        -2 |   17 |   13 |    1 |      2.1
(21 rows)

  • Point \(-1\) corresponds to the closest edge from point (2.9,1.8).

  • Point \(-2\) corresponds to the next close edge from point (2.9,1.8).

Driving side does not matter

From point \(1\) within a distance of \(3.3\), does not matter driving side, with details.

SELECT * FROM pgr_withPointsDD(
  'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
  'SELECT pid, edge_id, fraction, side from pointsOfInterest',
  -1, 3.3,
  driving_side => 'b',
  details => true);
 seq | node | edge | cost | agg_cost
-----+------+------+------+----------
   1 |   -1 |   -1 |    0 |        0
   2 |    5 |    1 |  0.4 |      0.4
   3 |    6 |    1 |  0.6 |      0.6
   4 |   -6 |    4 |  0.7 |      1.3
   5 |    7 |    4 |  0.3 |      1.6
   6 |    3 |    7 |    1 |      2.6
   7 |    8 |   10 |    1 |      2.6
   8 |   11 |    8 |    1 |      2.6
   9 |   -3 |   12 |  0.6 |      3.2
  10 |   -4 |    6 |  0.7 |      3.3
(10 rows)

Ver también

Índices y tablas