Skip to content

Commit 698f938

Browse files
authored
docs: describe GeoJSON fields in directions response (#2154)
2 parents b82c701 + b9a17a3 commit 698f938

File tree

18 files changed

+126
-54
lines changed

18 files changed

+126
-54
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Releasing is documented in RELEASE.md
2828
## [unreleased]
2929

3030
### Added
31-
31+
- documentation on the fields of JSON and GeoJSON responses of the directions endpoint ([#2084](https://github.com/GIScience/openrouteservice/issue/2084))
3232
- docs: comment on API key usage ([#2179](https://github.com/GIScience/openrouteservice/pull/2179))
3333
- type-specific filtering for mapping point features to graph edges ([#2156](https://github.com/GIScience/openrouteservice/pull/2156))
3434
- documentation on the matching endpoint ([#2156](https://github.com/GIScience/openrouteservice/pull/2156))

docs/api-reference/endpoints/directions/instruction-types.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
The following table contains the encoding of the instruction types present in the `type`-field of a directions response in a step of a segment of a route.
77

8-
JSON-Path in json response:
8+
JSONPath in JSON response:
99
```jsonpath
1010
$.routes[*].segments[*].steps[*].type
1111
```
1212

13-
JSON-Path in geojson response:
13+
JSONPath in GeoJSON response:
1414
```jsonpath
1515
$.features[*].properties.segments[*].steps[*].type
1616
```

docs/api-reference/endpoints/directions/requests-and-return-types.md

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,43 @@ Additionally, there is one simple GET request that does not allow advanced reque
1818

1919
### JSON
2020

21-
The **JSON** return type is best suited for further processing.
21+
The **JSON** output format is the most flexible and best suited one for further processing.
22+
Its top level structure consists of three main fields:
2223

23-
### GPX
24+
| Field | Description |
25+
|----------------|---------------------------------------------------------------------------------------------------------------------------------------|
26+
| **`bbox`** | Bounding box `[minLon, minLat, maxLon, maxLat]` covering all of the routes in the response. |
27+
| **`routes`** | List of routes. |
28+
| **`metadata`** | Additional details about the request and routing engine, including `attribution`, `service`, `timestamp`, `query`, and `engine` info. |
29+
30+
Each of the `routes` entries can contain the following fields.
31+
32+
| Field | Description |
33+
|------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
34+
| **`summary`** | Properties of the route such as total `distance` (m) and `duration` (s). |
35+
| **`segments`** | List of route sections between waypoints, each with `distance`, `duration`, and `steps` containing turn-by-turn navigation instructions if these have been requested. |
36+
| **`bbox`** | Bounding box of the route. |
2437

25-
The **GPX** return type is an XML dialect from openrouteservice based on the [GPS Exchange Format](https://www.topografix.com/gpx.asp) with an own [XML Schema](https://raw.githubusercontent.com/GIScience/openrouteservice-schema/main/gpx/v2/ors-gpx.xsd).
26-
It is a very old standard for lightweight interchange of GPS data and thus being used by hundreds of software programs and Web services.
38+
Furthermore, if route geometry has been requested (which is the default), the following fields are present.
39+
40+
| Field | Description |
41+
|------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
42+
| **`geometry`** | The path of the route. In JSON it is [encoded](https://developers.google.com/maps/documentation/utilities/polylinealgorithm), while in GeoJSON it is a `LineString` with explicit coordinates. |
43+
| **`way_points`** | Indices of way points corresponding to the `geometry`. |
2744

2845
### GeoJSON
2946

30-
**GeoJSON** is a format for encoding a variety of geographic data structures, see [geojson.org](https://datatracker.ietf.org/doc/html/rfc7946).
31-
It is widely used and can therefore be easily processed or displayed in many applications, e.g. in [QGIS](https://qgis.org/) or on [geojson.io](http://geojson.io/)
47+
**GeoJSON** is a standardized format for encoding a variety of geographic data structures, see [geojson.org](https://datatracker.ietf.org/doc/html/rfc7946).
48+
It is widely used and can therefore be easily processed or displayed in many applications, e.g. in [QGIS](https://qgis.org/) or on [geojson.io](http://geojson.io/).
49+
50+
The **GeoJSON** output contains the same routing information as its **JSON** counterpart, but organized in slightly different way.
51+
52+
In the **GeoJSON** format, the route data is structured as a standard **FeatureCollection** where individual routes are represented as `features`.
53+
Each **Feature** includes a `geometry` of type `LineString` and `properties` that contain the same fields as the `routes` elements in the JSON format, i.e. `summary`, `segments`, `way_points`, etc.
54+
55+
### GPX
56+
57+
The **GPX** return type is an XML dialect from openrouteservice based on the [GPS Exchange Format](https://www.topografix.com/gpx.asp) with its own [XML Schema](https://raw.githubusercontent.com/GIScience/openrouteservice-schema/main/gpx/v2/ors-gpx.xsd).
58+
It is a very old standard for lightweight interchange of GPS data and thus being used by a wide range of software applications and Web services.
3259

33-
More information about the result types can be found in the [API Playground](https://openrouteservice.org/dev/#/api-docs/directions_service).
60+
More details on the structure of the different return types can be found in the [API Playground](https://openrouteservice.org/dev/#/api-docs/directions_service).

docs/api-reference/endpoints/directions/routing-options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ A string array of features to avoid. The available features are :
3434
| `steps` | cycling-\*, foot-\*, wheelchair |
3535

3636
### `options.avoid_polygons`
37-
Comprises areas to be avoided for the route. Formatted as [geojson polygon](https://datatracker.ietf.org/doc/html/rfc7946#appendix-A.3) or [geojson multipolygon](https://datatracker.ietf.org/doc/html/rfc7946#appendix-A.6).
37+
Comprises areas to be avoided for the route. Formatted as [GeoJSON polygon](https://datatracker.ietf.org/doc/html/rfc7946#appendix-A.3) or [GeoJSON multipolygon](https://datatracker.ietf.org/doc/html/rfc7946#appendix-A.6).
3838

3939
### `options.profile_params`
4040
An object of additional routing parameters for all profiles except `driving-car`:

docs/api-reference/endpoints/export/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ curl -X 'POST' \
3535
}'
3636
```
3737

38-
The json response contains nodes and edges in the bounding box relevant for this routing profile.
38+
The JSON response contains nodes and edges in the bounding box relevant for this routing profile.
3939
The edge entry `weight` contains the fastest car duration in seconds.
4040

41-
The json response for the above request looks like this:
41+
The JSON response for the above request looks like this:
4242

4343
```json
4444
{

docs/api-reference/error-codes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Endpoints.
7575
| 4000 | Invalid JSON object in request. |
7676
| 4001 | Category or category group ids missing. |
7777
| 4002 | Geometry is missing. |
78-
| 4003 | Bounding box and or geojson not present in request. |
78+
| 4003 | Bounding box and or GeoJSON not present in request. |
7979
| 4004 | Buffer is missing. |
8080
| 4005 | Geometry length does not meet the restrictions. |
8181
| 4006 | Unsupported HTTP method. |

docs/api-reference/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Use the form "API Server" on the top left to select and edit "Development Server
2121
![Development server usage](/playground-select-server.png "Development server usage"){ style="display: block; margin: 0 auto"}
2222

2323
The responses of your sample requests are visualized on a small map on the bottom right,
24-
but can also be shown as json, table or downloaded as file:
24+
but can also be shown as JSON, table or downloaded as file:
2525
![Example request visualization](/playground-map.png "Example request visualization"){ style="display: block; margin: 0 auto"}
2626

2727
::: warning Hint

docs/run-instance/configuration/engine/profiles/build.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ country borders, compatible with any profile type.
159159

160160
| key | type | description | example value |
161161
|--------------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------|
162-
| boundaries | string | The path to a geojson file containing polygons representing country borders. Ignored if `preprocessed = true` is set. | `borders.geojson.tar.gz` |
162+
| boundaries | string | The path to a GeoJSON file containing polygons representing country borders. Ignored if `preprocessed = true` is set. | `borders.geojson.tar.gz` |
163163
| preprocessed | boolean | Indicates whether the source OSM file has been enriched with country data. If set to `true` then country codes are read from `country` node tags rather than being resolved at build time based on geometries provided in `boundaries`. | `true` |
164164
| ids | string | Path to a csv file containing a unique id for each country, its local name and its English name | `ids.csv` |
165165
| openborders | string | Path to a csv file containing pairs of countries where the borders are open (i.e. Schengen borders) | `openborders.csv` |

ors-api/src/main/java/org/heigit/ors/api/responses/routing/IndividualRouteResponse.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
import org.heigit.ors.routing.RouteResult;
2020
import org.locationtech.jts.geom.Coordinate;
2121

22-
public class IndividualRouteResponse {
22+
public abstract class IndividualRouteResponse {
2323
protected Coordinate[] routeCoordinates;
2424
protected boolean includeElevation = false;
2525
protected boolean isPtRequest = false;
2626

2727

28-
public IndividualRouteResponse(RouteResult result, RouteRequest request) {
28+
protected IndividualRouteResponse(RouteResult result, RouteRequest request) {
2929
if (result.getGeometry() != null)
3030
this.routeCoordinates = result.getGeometry();
3131

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313
* if not, see <https://www.gnu.org/licenses/>.
1414
*/
1515

16-
package org.heigit.ors.api.responses.routing.json;
16+
package org.heigit.ors.api.responses.routing;
1717

1818
import org.heigit.ors.api.requests.routing.RouteRequest;
1919
import org.heigit.ors.api.responses.common.boundingbox.BoundingBox;
2020
import org.heigit.ors.api.responses.common.boundingbox.BoundingBoxFactory;
21-
import org.heigit.ors.api.responses.routing.IndividualRouteResponse;
21+
import org.heigit.ors.api.responses.routing.json.JSONExtra;
22+
import org.heigit.ors.api.responses.routing.json.JSONLeg;
23+
import org.heigit.ors.api.responses.routing.json.JSONSegment;
2224
import org.heigit.ors.common.DistanceUnit;
2325
import org.heigit.ors.exceptions.StatusCodeException;
2426
import org.heigit.ors.routing.RouteExtraInfo;
@@ -32,10 +34,10 @@
3234
import java.util.List;
3335
import java.util.Map;
3436

35-
public class JSONBasedIndividualRouteResponse extends IndividualRouteResponse {
37+
public abstract class JSONBasedIndividualRouteResponse extends IndividualRouteResponse {
3638
protected BoundingBox bbox;
3739

38-
public JSONBasedIndividualRouteResponse(RouteResult result, RouteRequest request) throws StatusCodeException {
40+
protected JSONBasedIndividualRouteResponse(RouteResult result, RouteRequest request) throws StatusCodeException {
3941
super(result, request);
4042
if (request.hasUseElevation() && request.getUseElevation())
4143
includeElevation = true;
@@ -44,7 +46,7 @@ public JSONBasedIndividualRouteResponse(RouteResult result, RouteRequest request
4446
}
4547

4648
protected List<JSONSegment> constructSegments(RouteResult routeResult, RouteRequest request) {
47-
List segments = new ArrayList<>();
49+
List<JSONSegment> segments = new ArrayList<>();
4850
for (RouteSegment routeSegment : routeResult.getSegments()) {
4951
segments.add(new JSONSegment(routeSegment, request, routeResult.getSummary().getDistance()));
5052
}

0 commit comments

Comments
 (0)