dataservices-api/doc/routing_functions.md

85 lines
4.9 KiB
Markdown
Raw Permalink Normal View History

2016-04-06 03:48:57 +08:00
# Routing Functions
2016-03-01 23:47:49 +08:00
Routing is the navigation from a defined start location to a defined end location. The calculated results are displayed as turn-by-turn directions on your map, based on the transportation mode that you specified. Routing services through CARTO are available by using the available functions in the Data Services API.
2016-03-01 23:47:49 +08:00
2016-05-26 00:19:05 +08:00
## cdb_route_point_to_point(_origin geometry(Point), destination geometry(Point), mode text, [options text[], units text]_)
2016-03-01 23:47:49 +08:00
2016-05-25 00:04:15 +08:00
Returns a route from origin to destination.
2016-03-01 23:47:49 +08:00
#### Arguments
Name | Type | Description | Accepted values
--- | --- | --- | ---
`origin` | `geometry(Point)` | Origin point, in 4326 projection, which defines the start location. |
`destination` | `geometry(Point)` | Destination point, in 4326 projection, which defines the end location. |
2016-11-21 18:51:51 +08:00
`mode` | `text` | Type of transport used to calculate the routes. | `car`, `walk`, `bicycle` or `public_transport`
2016-03-01 23:47:49 +08:00
`options` | `text[]` | (Optional) Multiple options to add more capabilities to the analysis. See [Optional routing parameters](#optional-routing-parameters) for details.
`units` | `text` | (Optional) Unit used to represent the length of the route. | `kilometers`, `miles`. By default is `kilometers`. This option is not supported by Mapbox provider
2016-03-01 23:47:49 +08:00
#### Returns
Name | Type | Description
--- | --- | ---
`duration` | `integer` | Duration in seconds of the calculated route.
`length` | `real` | Length in the defined unit in the `units` field. `meters` by default .
2016-03-01 23:47:49 +08:00
`the_geom` | `geometry(LineString)` | LineString geometry of the calculated route in the 4326 projection.
#### Examples
##### Insert the values from the calculated route in your table
```bash
INSERT INTO <TABLE> (duration, length, the_geom) SELECT duration, length, shape FROM cdb_route_point_to_point('POINT(-3.70237112 40.41706163)'::geometry,'POINT(-3.69909883 40.41236875)'::geometry, 'car')
```
##### Update the geometry field with the calculated route shape
```bash
UPDATE <TABLE> SET the_geom = (SELECT shape FROM cdb_route_point_to_point('POINT(-3.70237112 40.41706163)'::geometry,'POINT(-3.69909883 40.41236875)'::geometry, 'car', ARRAY['mode_type=shortest']::text[]))
```
2016-05-26 00:19:05 +08:00
## cdb_route_with_waypoints(_waypoints geometry(Point)[], mode text, [options text[], units text]_)
2016-05-25 00:04:15 +08:00
Returns a route that goes from origin to destination and whose path travels through the defined locations.
#### Arguments
Name | Type | Description | Accepted values
--- | --- | --- | ---
`waypoints` | `geometry(Point)[]` | Array of ordered points, in 4326 projection, which defines the origin point, one or more locations for the route path to travel through, and the destination. The first element of the array defines the origin and the last element the destination of the route. |
2016-11-21 18:51:51 +08:00
`mode` | `text` | Type of transport used to calculate the routes. | `car`, `walk`, `bicycle` or `public_transport`
2016-05-25 00:04:15 +08:00
`options` | `text[]` | (Optional) Multiple options to add more capabilities to the analysis. See [Optional routing parameters](#optional-routing-parameters) for details.
`units` | `text` | (Optional) Unit used to represent the length of the route. | `kilometers`, `miles`. By default is `kilometers`. This option is not supported by Mapbox provider
2016-05-25 00:04:15 +08:00
#### Returns
Name | Type | Description
--- | --- | ---
`duration` | `integer` | Duration in seconds of the calculated route.
`length` | `real` | Length in the defined unit in the `units` field. `meters` by default .
2016-05-25 00:04:15 +08:00
`the_geom` | `geometry(LineString)` | LineString geometry of the calculated route in the 4326 projection.
2016-05-25 21:19:08 +08:00
*Note*: A request to the function _cdb\_route\_with\_waypoints(waypoints geometry(Point)[], mode text, [options text[], units text])_ with only two points in the geometry array are automatically defined as origin and destination. It is equivalent to performing the following request with these two locations as parameters: _cdb\_route\_point\_to\_point(origin geometry(Point), destination geometry(Point), mode text, [options text[], units text])_.
2016-05-25 00:04:15 +08:00
#### Examples
##### Insert the values from the calculated route in your table
```bash
INSERT INTO <TABLE> (duration, length, the_geom) SELECT duration, length, shape FROM cdb_route_with_waypoints(Array['POINT(-3.7109 40.4234)'::GEOMETRY, 'POINT(-3.7059 40.4203)'::geometry, 'POINT(-3.7046 40.4180)'::geometry]::geometry[], 'walk')
```
##### Update the geometry field with the calculated route shape
```bash
UPDATE <TABLE> SET the_geom = (SELECT shape FROM cdb_route_with_waypoints(Array['POINT(-3.7109 40.4234)'::GEOMETRY, 'POINT(-3.7059 40.4203)'::geometry, 'POINT(-3.7046 40.4180)'::geometry]::geometry[], 'car', ARRAY['mode_type=shortest']::text[]))
```
2016-03-01 23:47:49 +08:00
### Optional routing parameters
The optional value parameters must be passed using the format: `option=value`. Not all are available for all the routing providers
2016-03-01 23:47:49 +08:00
Name | Type | Description | Accepted values
--- | --- | --- | ---
2018-11-30 19:30:02 +08:00
`mode_type` | `text` | Type of route calculation | `shortest` or `fastest` (this option only applies to the car transport mode)