Routing
implproposalSupport for pgRouting to compute routes.
Scope
pgRouting can be used to compute routes on a network dataset. This feature provider extension allows to provide the edges / segments of a route as a query response. The route segment schema is specified as a feature type.
The route segment feature type has to meet the following conditions:
- Each feature is a route segment / edge of the route. The edges are returned in sequence from start to end.
- The name of the feature table is "_route_".
- The feature type has an INTEGER property
nodethat identifies the node at the start of the route segment. The value is either the same asdata/source(traveling in positive edge direction) or asdata/target(traveling in negative edge direction).
- The feature type has an INTEGER property
- The feature type has a FLOAT property
costthat states the cost of the edge in the direction of travel.
- The feature type has a FLOAT property
- The feature type has an OBJECT property
data.
- The feature type has an OBJECT property
- The
dataobject has a INTEGER propertysourcewith the node identifier at the start of edge.
- The
- The
dataobject has a INTEGER propertytargetwith the node identifier at the end of edge.
- The
- The
dataobject has a FLOAT propertylength_mwith the length of the edge in meter.
- The
- Das
dataobject has a GEOMETRY property with a LINE_STRING geometry.
- Das
- The
dataobject can have a FLOAT propertyduration_forward_swith the duration for traveling the edge in positive direction.
- The
- The
dataobject can have a FLOAT propertyduration_backward_swith the duration for traveling the edge in negative direction.
- The
- The
dataobject can have a FLOAT propertymaxHeight_mwith the maximum vehicle height in meter for the edge.
- The
- The
dataobject can have a FLOAT propertymaxWeight_mwith the maximum vehicle weight in metric tons for the edge.
- The
- The
dataobject can have a FLOAT propertymaxspeed_forwardwith the speed limit on the edge in positive direction.
- The
- The
dataobject can have a FLOAT propertymaxspeed_backwardwith the speed limit on the edge in negative direction.
- The
Configuration
Options
| Name | Default | Description | Type | Since |
|---|---|---|---|---|
type | Always ROUTES. | string | v2.0 | |
enabled | false | Enable the extension? | boolean | v2.0 |
fromToQuery | null | Required The SQL query to determine the start and end vertex of the route. ${point} will be replaced with the WKT POINT geometry of the waypoint to use as start/end. | object | v3.1 |
edgesQuery | null | Required The SQL query to determine the edges / route segments of the route. ${cost_column} and ${reverse_cost_column} will be replaced with the column names to use for optimizing the route. ${cost_column} is the value in the direction of the edge, ${reverse_cost_column} in the opposite direction. | object | v3.1 |
routeQuery | null | Required The SQL query to compute the route. Use ${edgesQuery} as placeholder for the edgesQuery, ${from_vid} and ${to_vid} as placeholders for the start/end vertex. If supported, use ${height}, ${weight}, and ${obstacles} as placeholders for the height, weight and area constraints. ${flag_mask}, if provided, is replaced by the sum of all additional flags set for the routing request. | string | v3.1 |
flags | {} | Additional flags that can be set to consider during the computation of the route. The integer value of a flag must be a unique bit value. | object | v3.1 |
nativeCrs | CRS84 | Coordinate reference system of geometries in the routing dataset. The EPSG code of the coordinate reference system is given as integer in code. forceAxisOrder may be set to use a non-default axis order: LON_LAT uses longitude/east as first value and latitude/north as second value, LAT_LON uses the reverse. NONE uses the default axis order and is the default value. Example: The default coordinate reference system CRS84 would look like this: code: 4326 and forceAxisOrder: LON_LAT. | object | v3.1 |
preferences | {} | Required Lists the available options for optimizing the route. The key is the preference id, the value an object of key-value pairs with the following required keys: "label", "costColumn" (name of the column in the table of network segment to minimize, if the segment is traveled in positive direction), "reverseCostColumn" (same, but for travelling in negative direction). | object | v3.1 |
modes | {} | Lists the available modes of transportation, the key is the mode id, the value a descriptive label. | object | v3.1 |
weightDefault | 0 | Sets a default value for the weight of a vehicle in tons. 0 means no weight. | string | v3.1 |
heightDefault | 0 | Sets a default value for the height of a vehicle in meters. 0 means no height. | string | v3.1 |
obstaclesDefault | EMPTY | Sets a default value for an area to avoid. | string | v3.1 |
warmup | false | Enables a route calculation with the default values at provider startup. This can be useful, if the routing algorithm caches certain information. | boolean | v3.1 |
Example
extensions:
- type: ROUTES
enabled: true
warmup: true
fromToQuery:
driving: 'SELECT id as oid, ST_Distance(${point},the_geom) AS distance FROM v_ways_vertices_pgr WHERE connected and ST_DWithin(${point},the_geom, 0.25) ORDER BY distance ASC LIMIT 1'
edgesQuery:
driving: 'SELECT gid as id, source, target, x1, y1, x2, y2, ${cost_column} AS cost, ${reverse_cost_column} AS reverse_cost, maxheight, maxweight FROM v_ways WHERE tag_id NOT IN (113, 114, 115, 116, 117, 118, 119, 120, 122, 201, 202, 203, 204, 301, 302, 303, 304, 305)'
routeQuery: 'SELECT * from pgr_aStar(${edgesQuery}, ${from_vid}, ${to_vid}, ${height}, ${weight}, ''SELECT gid FROM v_ways WHERE ST_Intersects(the_geom, ${obstacles})'', false, 5, (1+8+16))'
nativeCrs:
code: 4326
forceAxisOrder: LON_LAT
preferences:
fastest:
label: Fastest
costColumn: cost_s
reverseCostColumn: reverse_cost_s
shortest:
label: Shortest
costColumn: cost
reverseCostColumn: reverse_cost
modes:
driving: Driving
types:
route:
type: OBJECT
sourcePath: /_route_
properties:
id:
sourcePath: id
type: INTEGER
role: ID
edge:
sourcePath: edge
type: INTEGER
node:
sourcePath: node
type: INTEGER
cost:
sourcePath: cost
type: FLOAT
agg_cost:
sourcePath: agg_cost
type: FLOAT
data:
type: OBJECT
sourcePath: '[edge=gid]v_ways{sortKey=gid}'
properties:
geometry:
sourcePath: the_geom
type: GEOMETRY
geometryType: LINE_STRING
role: PRIMARY_GEOMETRY
forcePolygonCCW: false
source:
sourcePath: source
type: INTEGER
target:
sourcePath: target
type: INTEGER
type:
sourcePath: tag_id
type: STRING
transformations:
codelist: wayTag
#osm_id:
# sourcePath: osm_id
# type: INTEGER
length_m:
sourcePath: length_m
type: FLOAT
duration_forward_s:
sourcePath: cost_s
type: FLOAT
duration_backward_s:
sourcePath: reverse_cost_s
type: FLOAT
roadName:
sourcePath: name
type: STRING
oneway:
sourcePath: oneway
type: STRING
maxspeed_forward:
sourcePath: maxspeed_forward
type: FLOAT
maxspeed_backward:
sourcePath: maxspeed_backward
type: FLOAT
maxHeight_m:
sourcePath: maxheight
type: FLOAT
maxWeight_t:
sourcePath: maxweight
type: FLOAT