pgRouting Manual (2.2)

pgr_pointsToDMatrix

«  pgr_pointsToVids   ::   Contents   ::   pgr_vidsToDMatrix  »

pgr_pointsToDMatrix

Name

pgr_pointsToDMatrix - Creates a distance matrix from an array of points.

Warning

This is a proposed function

  • Is not officially in the release.
  • Name could change.
  • Signature could change.
  • Needs testing.
  • Functionality could change.

Synopsis

Create a distance symetric distance matrix suitable for TSP using Euclidean distances based on the st_distance(). You might want to create a variant of this the uses st_distance_sphere() or st_distance_spheriod() or some other function.

The function returns:

  • record - with two fields as describe here
    • dmatrix:float8[] - the distance matrix suitable to pass to pgrTSP() function.
    • ids:integer[] - an array of ids for the distance matrix.
record pgr_pointsToDMatrix(pnts geometry[], OUT dmatrix double precision[], OUT ids integer[])

Description

Paramters

pnts:geometry[] - An array of point geometries.

Warning

The generated matrix will be symmetric as required for pgr_TSP.

History

  • Proposed in version 2.1.0

Examples

SELECT * FROM pgr_pointstodmatrix(pgr_texttopoints('2,0;2,1;3,1;2,2', 0));
                                              dmatrix                                              |    ids    
---------------------------------------------------------------------------------------------------+-----------
 {{0,1,1.4142135623731,2},{1,0,1,1},{1.4142135623731,1,0,1.4142135623731},{2,1,1.4142135623731,0}} | {1,2,3,4}
(1 row)

This example shows how this can be used in the context of feeding the results into pgr_tsp() function.

SELECT * from pgr_tsp(
    (SELECT dMatrix FROM pgr_pointstodmatrix(pgr_texttopoints('2,0;2,1;3,1;2,2', 0))
    ),
    1
);
 seq | id 
-----+----
   0 |  1
   1 |  3
   2 |  2
   3 |  0
(4 rows)

See Also

Indices and tables

«  pgr_pointsToVids   ::   Contents   ::   pgr_vidsToDMatrix  »