pgr_createVerticesTable
— para reconstruir la tabla de vértices basándose en la información de origen y de destino.
Disponibilidad
Soporte
La función devuelve:
OK
después de que se ha construido la tabla de vértices.FAIL
cuando la tabla de vértices no se construyó debido a un error: pgr_createVerticesTable(edge_table, the_geom, source, target, rows_where)
RETURNS VARCHAR
La función para la reconstrucción de la tabla mesa vértices acepta los siguientes parámetros:
edge_table: | text La tabla de la red. (puede contener el nombre del esquema) |
---|---|
the_geom: | text nombre de la columna de la geometría en la tabla de la red. El valor por defecto es the_geom |
source: | id``Nombre de columna de origen de la tabla de red. El valor predeterminado es``source . |
target: | text El nombre de la columna del nodo de llegada del segmento. El valor por defecto es target . |
rows_where: | text condición para seleccionar un subconjunto o filas. Valor predeterminado es true para indicar todas las filas. |
Advertencia
La edge_table
se verán afectados
the_geom
source
target
La función devuelve:
OK
después de que se ha construido la tabla de vértices.id
y the_geom
de la tabla de vértices basado en la información de la fuente y el destino.FAIL
cuando la tabla de vértices no se construyó debido a un error:La tabla de vértices
La tabla de vértices es un requerimiento de las funciones pgr_analyzeGraph y pgr_analyzeOneWay.
La estructura de la tabla de los vértices es:
id: | bigint identificador del vértice. |
---|---|
cnt: | integer Número de vértices en the edge_table que referencian este vértice. Ver pgr_analyzeGraph. |
chk: | integer Indicador de que el vértice podría tener un problema. Consulte pgr_analyzeGraph. |
ein: | integer Número de vértices en edge_table que hacen referencia a este vértice como entrante. Consulte pgr_analyzeOneWay. |
eout: | integer Número de vértices en el edge_table que hacen referencia a este vértice como saliente. Consulte pgr_analyzeOneWay. |
the_geom: | geometry Valor de la geometría POINT del vértice. |
Ejemplo 1: | La forma más sencilla de utilizar pgr_createVerticesTable |
SELECT pgr_createVerticesTable('edge_table');
NOTICE: PROCESSING:
NOTICE: pgr_createVerticesTable('edge_table','the_geom','source','target','true')
NOTICE: Performing checks, please wait .....
NOTICE: Populating public.edge_table_vertices_pgr, please wait...
NOTICE: -----> VERTICES TABLE CREATED WITH 17 VERTICES
NOTICE: FOR 18 EDGES
NOTICE: Edges with NULL geometry,source or target: 0
NOTICE: Edges processed: 18
NOTICE: Vertices table for table public.edge_table is: public.edge_table_vertices_pgr
NOTICE: ----------------------------------------------
pgr_createverticestable
-------------------------
OK
(1 row)
Ejemplo 2: | Cuando los argumentos se escriben en el orden descrito en los parámetros: |
---|
SELECT pgr_createVerticesTable('edge_table', 'the_geom', 'source', 'target');
NOTICE: PROCESSING:
NOTICE: pgr_createVerticesTable('edge_table','the_geom','source','target','true')
NOTICE: Performing checks, please wait .....
NOTICE: Populating public.edge_table_vertices_pgr, please wait...
NOTICE: -----> VERTICES TABLE CREATED WITH 17 VERTICES
NOTICE: FOR 18 EDGES
NOTICE: Edges with NULL geometry,source or target: 0
NOTICE: Edges processed: 18
NOTICE: Vertices table for table public.edge_table is: public.edge_table_vertices_pgr
NOTICE: ----------------------------------------------
pgr_createverticestable
-------------------------
OK
(1 row)
Obtenemos el mismo resultado que la forma más sencilla de utilizar la función.
Advertencia
Se producirá un error cuando los argumentos no se proporcionan en el orden adecuado: en este ejemplo, la columna de origen de columna “ source
de la tabla mytable
se pasa a la función como la columna de geometría, y la columna de geometría the_geom
se pasa a la función como la columna de origen.
SELECT pgr_createVerticesTable('edge_table', 'source', 'the_geom', 'target');
NOTICE: PROCESSING:
NOTICE: pgr_createVerticesTable('edge_table','source','the_geom','target','true')
NOTICE: Performing checks, please wait .....
NOTICE: ----> PGR ERROR in pgr_createVerticesTable: Wrong type of Column source: the_geom
HINT: ----> Expected type of the_geom is integer, smallint or bigint but USER-DEFINED was found
NOTICE: Unexpected error raise_exception
pgr_createverticestable
-------------------------
FAIL
(1 row)
Cuando se utiliza la notación por nombre
Ejemplo 3: | No importa el orden de los parámetros: |
---|
SELECT pgr_createVerticesTable('edge_table', the_geom:='the_geom', source:='source', target:='target');
NOTICE: PROCESSING:
NOTICE: pgr_createVerticesTable('edge_table','the_geom','source','target','true')
NOTICE: Performing checks, please wait .....
NOTICE: Populating public.edge_table_vertices_pgr, please wait...
NOTICE: -----> VERTICES TABLE CREATED WITH 17 VERTICES
NOTICE: FOR 18 EDGES
NOTICE: Edges with NULL geometry,source or target: 0
NOTICE: Edges processed: 18
NOTICE: Vertices table for table public.edge_table is: public.edge_table_vertices_pgr
NOTICE: ----------------------------------------------
pgr_createverticestable
-------------------------
OK
(1 row)
Ejemplo 4: | Usando un orden diferente |
---|
SELECT pgr_createVerticesTable('edge_table', source:='source', target:='target', the_geom:='the_geom');
NOTICE: PROCESSING:
NOTICE: pgr_createVerticesTable('edge_table','the_geom','source','target','true')
NOTICE: Performing checks, please wait .....
NOTICE: Populating public.edge_table_vertices_pgr, please wait...
NOTICE: -----> VERTICES TABLE CREATED WITH 17 VERTICES
NOTICE: FOR 18 EDGES
NOTICE: Edges with NULL geometry,source or target: 0
NOTICE: Edges processed: 18
NOTICE: Vertices table for table public.edge_table is: public.edge_table_vertices_pgr
NOTICE: ----------------------------------------------
pgr_createverticestable
-------------------------
OK
(1 row)
Ejemplo 5: | Parámetros definidos con un valor predeterminado se pueden omitir, siempre y cuando el valor coincida con el valor por defecto: |
---|
SELECT pgr_createVerticesTable('edge_table',source:='source');
NOTICE: PROCESSING:
NOTICE: pgr_createVerticesTable('edge_table','the_geom','source','target','true')
NOTICE: Performing checks, please wait .....
NOTICE: Populating public.edge_table_vertices_pgr, please wait...
NOTICE: -----> VERTICES TABLE CREATED WITH 17 VERTICES
NOTICE: FOR 18 EDGES
NOTICE: Edges with NULL geometry,source or target: 0
NOTICE: Edges processed: 18
NOTICE: Vertices table for table public.edge_table is: public.edge_table_vertices_pgr
NOTICE: ----------------------------------------------
pgr_createverticestable
-------------------------
OK
(1 row)
Seleccionar filas utilizando el parámetro rows_where
Ejemplo 6: | La selección de filas basadas en el id. |
---|
SELECT pgr_createVerticesTable('edge_table',rows_where:='id < 10');
NOTICE: PROCESSING:
NOTICE: pgr_createVerticesTable('edge_table','the_geom','source','target','id < 10')
NOTICE: Performing checks, please wait .....
NOTICE: Populating public.edge_table_vertices_pgr, please wait...
NOTICE: -----> VERTICES TABLE CREATED WITH 9 VERTICES
NOTICE: FOR 10 EDGES
NOTICE: Edges with NULL geometry,source or target: 0
NOTICE: Edges processed: 10
NOTICE: Vertices table for table public.edge_table is: public.edge_table_vertices_pgr
NOTICE: ----------------------------------------------
pgr_createverticestable
-------------------------
OK
(1 row)
Ejemplo 7: | Seleccionar las filas donde la geometría está cerca de la geometría de la fila con id =5. |
---|
SELECT pgr_createVerticesTable('edge_table',
rows_where:='the_geom && (select st_buffer(the_geom,0.5) FROM edge_table WHERE id=5)');
NOTICE: PROCESSING:
NOTICE: pgr_createVerticesTable('edge_table','the_geom','source','target','the_geom && (select st_buffer(the_geom,0.5) FROM edge_table WHERE id=5)')
NOTICE: Performing checks, please wait .....
NOTICE: Populating public.edge_table_vertices_pgr, please wait...
NOTICE: -----> VERTICES TABLE CREATED WITH 9 VERTICES
NOTICE: FOR 9 EDGES
NOTICE: Edges with NULL geometry,source or target: 0
NOTICE: Edges processed: 9
NOTICE: Vertices table for table public.edge_table is: public.edge_table_vertices_pgr
NOTICE: ----------------------------------------------
pgr_createverticestable
-------------------------
OK
(1 row)
Ejemplo 8: | Seleccionar las filas donde la geometría está cerca de la geometría de la fila con``gid`` =100 de la tabla othertable . |
---|
DROP TABLE IF EXISTS otherTable;
NOTICE: table "othertable" does not exist, skipping
DROP TABLE
CREATE TABLE otherTable AS (SELECT 100 AS gid, st_point(2.5,2.5) AS other_geom) ;
SELECT 1
SELECT pgr_createVerticesTable('edge_table',
rows_where:='the_geom && (select st_buffer(other_geom,0.5) FROM otherTable WHERE gid=100)');
NOTICE: PROCESSING:
NOTICE: pgr_createVerticesTable('edge_table','the_geom','source','target','the_geom && (select st_buffer(other_geom,0.5) FROM otherTable WHERE gid=100)')
NOTICE: Performing checks, please wait .....
NOTICE: Populating public.edge_table_vertices_pgr, please wait...
NOTICE: -----> VERTICES TABLE CREATED WITH 10 VERTICES
NOTICE: FOR 12 EDGES
NOTICE: Edges with NULL geometry,source or target: 0
NOTICE: Edges processed: 12
NOTICE: Vertices table for table public.edge_table is: public.edge_table_vertices_pgr
NOTICE: ----------------------------------------------
pgr_createverticestable
-------------------------
OK
(1 row)
Usando la siguiente tabla
DROP TABLE IF EXISTS mytable;
NOTICE: table "mytable" does not exist, skipping
DROP TABLE
CREATE TABLE mytable AS (SELECT id AS gid, the_geom AS mygeom, source AS src ,target AS tgt FROM edge_table) ;
SELECT 18
Usando notación posicional:
Ejemplo 9: | Las discusiones deben recibir en el orden descrito en los parámetros: |
---|
SELECT pgr_createVerticesTable('mytable', 'mygeom', 'src', 'tgt');
NOTICE: PROCESSING:
NOTICE: pgr_createVerticesTable('mytable','mygeom','src','tgt','true')
NOTICE: Performing checks, please wait .....
NOTICE: Populating public.mytable_vertices_pgr, please wait...
NOTICE: -----> VERTICES TABLE CREATED WITH 17 VERTICES
NOTICE: FOR 18 EDGES
NOTICE: Edges with NULL geometry,source or target: 0
NOTICE: Edges processed: 18
NOTICE: Vertices table for table public.mytable is: public.mytable_vertices_pgr
NOTICE: ----------------------------------------------
pgr_createverticestable
-------------------------
OK
(1 row)
Advertencia
src
de la tabla mytable
se pasa a la función como la columna de geometría, y la columna de geometría mygeom
se pasa a la función como columna de origen.SELECT pgr_createVerticesTable('mytable', 'src', 'mygeom', 'tgt');
NOTICE: PROCESSING:
NOTICE: pgr_createVerticesTable('mytable','src','mygeom','tgt','true')
NOTICE: Performing checks, please wait .....
NOTICE: ----> PGR ERROR in pgr_createVerticesTable: Wrong type of Column source: mygeom
HINT: ----> Expected type of mygeom is integer, smallint or bigint but USER-DEFINED was found
NOTICE: Unexpected error raise_exception
pgr_createverticestable
-------------------------
FAIL
(1 row)
Cuando se utiliza la notación por nombre
Ejemplo 10: | No importa el orden de los parámetros: |
---|
SELECT pgr_createVerticesTable('mytable',the_geom:='mygeom',source:='src',target:='tgt');
NOTICE: PROCESSING:
NOTICE: pgr_createVerticesTable('mytable','mygeom','src','tgt','true')
NOTICE: Performing checks, please wait .....
NOTICE: Populating public.mytable_vertices_pgr, please wait...
NOTICE: -----> VERTICES TABLE CREATED WITH 17 VERTICES
NOTICE: FOR 18 EDGES
NOTICE: Edges with NULL geometry,source or target: 0
NOTICE: Edges processed: 18
NOTICE: Vertices table for table public.mytable is: public.mytable_vertices_pgr
NOTICE: ----------------------------------------------
pgr_createverticestable
-------------------------
OK
(1 row)
Ejemplo 11: | Usando un orden diferente |
---|
En este escenario omitir un parámetro crearía un error porque los valores predeterminados de los nombres de columna no coinciden con los nombres de columna de la tabla.
SELECT pgr_createVerticesTable(
'mytable', source:='src', target:='tgt',
the_geom:='mygeom');
NOTICE: PROCESSING:
NOTICE: pgr_createVerticesTable('mytable','mygeom','src','tgt','true')
NOTICE: Performing checks, please wait .....
NOTICE: Populating public.mytable_vertices_pgr, please wait...
NOTICE: -----> VERTICES TABLE CREATED WITH 17 VERTICES
NOTICE: FOR 18 EDGES
NOTICE: Edges with NULL geometry,source or target: 0
NOTICE: Edges processed: 18
NOTICE: Vertices table for table public.mytable is: public.mytable_vertices_pgr
NOTICE: ----------------------------------------------
pgr_createverticestable
-------------------------
OK
(1 row)
Seleccionar filas utilizando el parámetro rows_where
Ejemplo 12: | Selección de filas en función del gid. (notación posicional) |
---|
SELECT pgr_createVerticesTable(
'mytable', 'mygeom', 'src', 'tgt',
rows_where:='gid < 10');
NOTICE: PROCESSING:
NOTICE: pgr_createVerticesTable('mytable','mygeom','src','tgt','gid < 10')
NOTICE: Performing checks, please wait .....
NOTICE: Populating public.mytable_vertices_pgr, please wait...
NOTICE: -----> VERTICES TABLE CREATED WITH 9 VERTICES
NOTICE: FOR 10 EDGES
NOTICE: Edges with NULL geometry,source or target: 0
NOTICE: Edges processed: 10
NOTICE: Vertices table for table public.mytable is: public.mytable_vertices_pgr
NOTICE: ----------------------------------------------
pgr_createverticestable
-------------------------
OK
(1 row)
Ejemplo 13: | Selección de filas en función del gid. (notación con nombre) |
---|
SELECT pgr_createVerticesTable(
'mytable', source:='src', target:='tgt', the_geom:='mygeom',
rows_where:='gid < 10');
NOTICE: PROCESSING:
NOTICE: pgr_createVerticesTable('mytable','mygeom','src','tgt','gid < 10')
NOTICE: Performing checks, please wait .....
NOTICE: Populating public.mytable_vertices_pgr, please wait...
NOTICE: -----> VERTICES TABLE CREATED WITH 9 VERTICES
NOTICE: FOR 10 EDGES
NOTICE: Edges with NULL geometry,source or target: 0
NOTICE: Edges processed: 10
NOTICE: Vertices table for table public.mytable is: public.mytable_vertices_pgr
NOTICE: ----------------------------------------------
pgr_createverticestable
-------------------------
OK
(1 row)
Ejemplo 14: | Selección de las filas en las que la geometría está cerca de la geometría de la fila con gid = 5. |
---|
SELECT pgr_createVerticesTable(
'mytable', 'mygeom', 'src', 'tgt',
rows_where := 'the_geom && (SELECT st_buffer(mygeom,0.5) FROM mytable WHERE gid=5)');
NOTICE: PROCESSING:
NOTICE: pgr_createVerticesTable('mytable','mygeom','src','tgt','the_geom && (SELECT st_buffer(mygeom,0.5) FROM mytable WHERE gid=5)')
NOTICE: Performing checks, please wait .....
NOTICE: Got column "the_geom" does not exist
NOTICE: ERROR: Condition is not correct, please execute the following query to test your condition
NOTICE: select * from public.mytable WHERE true AND (the_geom && (SELECT st_buffer(mygeom,0.5) FROM mytable WHERE gid=5)) limit 1
pgr_createverticestable
-------------------------
FAIL
(1 row)
Ejemplo 15: | Por Definirse |
---|
SELECT pgr_createVerticesTable(
'mytable', source:='src', target:='tgt', the_geom:='mygeom',
rows_where:='mygeom && (SELECT st_buffer(mygeom,0.5) FROM mytable WHERE id=5)');
NOTICE: PROCESSING:
NOTICE: pgr_createVerticesTable('mytable','mygeom','src','tgt','mygeom && (SELECT st_buffer(mygeom,0.5) FROM mytable WHERE id=5)')
NOTICE: Performing checks, please wait .....
NOTICE: Got column "id" does not exist
NOTICE: ERROR: Condition is not correct, please execute the following query to test your condition
NOTICE: select * from public.mytable WHERE true AND (mygeom && (SELECT st_buffer(mygeom,0.5) FROM mytable WHERE id=5)) limit 1
pgr_createverticestable
-------------------------
FAIL
(1 row)
Ejemplo 16: | Seleccionar las filas donde la geometría está cerca de la geometría de la fila con``gid`` =100 de la tabla othertable . |
---|
DROP TABLE IF EXISTS otherTable;
DROP TABLE
CREATE TABLE otherTable AS (SELECT 100 AS gid, st_point(2.5,2.5) AS other_geom) ;
SELECT 1
SELECT pgr_createVerticesTable(
'mytable', 'mygeom', 'src', 'tgt',
rows_where:='the_geom && (SELECT st_buffer(othergeom,0.5) FROM otherTable WHERE gid=100)');
NOTICE: PROCESSING:
NOTICE: pgr_createVerticesTable('mytable','mygeom','src','tgt','the_geom && (SELECT st_buffer(othergeom,0.5) FROM otherTable WHERE gid=100)')
NOTICE: Performing checks, please wait .....
NOTICE: Got column "the_geom" does not exist
NOTICE: ERROR: Condition is not correct, please execute the following query to test your condition
NOTICE: select * from public.mytable WHERE true AND (the_geom && (SELECT st_buffer(othergeom,0.5) FROM otherTable WHERE gid=100)) limit 1
pgr_createverticestable
-------------------------
FAIL
(1 row)
Ejemplo 17: | Por Definirse |
---|
SELECT pgr_createVerticesTable(
'mytable',source:='src',target:='tgt',the_geom:='mygeom',
rows_where:='the_geom && (SELECT st_buffer(othergeom,0.5) FROM otherTable WHERE gid=100)');
NOTICE: PROCESSING:
NOTICE: pgr_createVerticesTable('mytable','mygeom','src','tgt','the_geom && (SELECT st_buffer(othergeom,0.5) FROM otherTable WHERE gid=100)')
NOTICE: Performing checks, please wait .....
NOTICE: Got column "the_geom" does not exist
NOTICE: ERROR: Condition is not correct, please execute the following query to test your condition
NOTICE: select * from public.mytable WHERE true AND (the_geom && (SELECT st_buffer(othergeom,0.5) FROM otherTable WHERE gid=100)) limit 1
pgr_createverticestable
-------------------------
FAIL
(1 row)
En el ejemplo se utiliza la red Datos Muestra.
Índices y tablas