What does 'type' stand for in segments output?

Hi,

I’m wondering what the ‘type’ output can be decoded with. Example here:

‘way_points’: [780, 804]}, {‘distance’: 49.6, ‘duration’: 4.0, ‘type’: 12

the ‘type’ values in my case range from 0 to 13, I can not find a reference…

thanks for your help!

Hey @onkel_butterbrot ,

this is the instruction type. Since this is a rather specialized feature, it is not documented in the API directly, but on github:

Best regards,
Jakob

1 Like

Thanks for your quick response. As I am looking at the duration on certain waycategories/waytypes this feature is a rather important one to me.

I’ve already had a look at the github documentation - but waytypes there have values ranging from 0 to 10 only. As stated I get values well beyond that - how can those be interpreted?

Also is there a correlation between waytype and waycategory? if say I wanted the duration on highways in the defined way_points, is there a way to get that?

thanks for your help!

Hey @onkel_butterbrot ,

I’m very sorry - I was mistaken in my answer from earlier.
This is an excerpt from a list of steps of one segment, right?

If so, the type mentioned here is the instructions type. I have corrected my link from earlier.

Waytypes are available via the extra_info-parameter and are given in the extras["waytype"]-section in the response.

Best regards,
Jakob

Yes, exactly. Good to know - so it does not make sense to extract that information to get the duration on certain waycategories…

Do you by chance know how to get that information?

I think if I do it just for one pair of coordinates it will display duration for waycategories, but if I do it for hundreds of coordinates, the duration will be added together and will not give information about the duration on waycategories for certain parts of the route, right?

e.g. I have coordinates from Hamburg to Vienna - I can see waycategories + duration
But if I have multiple coordinates from Hamburg to Vienna to Berlin to Köln, I will only get the durations for waycategories all together, but not for the route from Hamburg to Vienna alone - is this right?

thanks for sticking with me - hopefully my issue is understandable :slight_smile:

Hey,

as stated, waycategor/waytype-information will be available in the extras-section if you ask for it using the extra_info-parameter.
This can be a bit tricky to read, have a look at this response where it gets explained a bit.

The waycategory summary will then contain the durations for all segments together, but it is possible to tally up waycategory durations for specific segments manually.

Best regards,
Jakob

Hey,

thanks again for your response. Decoding waycategory is not a problem, it is more about duration on a certain waycategory.

I can NOT confirm this:

The waycategory summary will then contain the durations for all segments together, but it is possible to tally up waycategory durations for specific segments manually.

waycategory summary only contains distance:

[{'value': 3.0, 'distance': 58139672.8, 'amount': 81.02}, {'value': 0.0, 'distance': 10734242.1, 'amount': 14.96}, {'value': 1.0, 'distance': 2628612.8, 'amount': 3.66}, {'value': 2.0, 'distance': 258568.3, 'amount': 0.36}]

I tried connecting the duration and the according way_points in the segments ‘steps’ with the waycategory values - but they do not match. Steps of one segment look like that:

[{'distance': 114.6, 'duration': 20.6, 'type': 11, 'instruction': 'Head north', 'name': '-', 'way_points': [0, 5]}, {'distance': 288.1, 'duration': 28.5, 'type': 1, 'instruction': 'Turn right onto Knaufstraße', 'name': 'Knaufstraße', 'way_points': [5, 17]}, {'distance': 3626.0, 'duration': 273.0, 'type': 5, 'instruction': 'Turn slight right onto B320', 'name': 'B320', 'way_points': [17, 115]}, {'distance': 54983.9, 'duration': 2679.3, 'type': 13, 'instruction': 'Keep right onto Ennstal-Bundesstraße, B320', 'name': 'Ennstal-Bundesstraße, B320', 'way_points': [115, 675]}, {'distance': 11065.1, 'duration': 531.1, 'type': 12, 'instruction': 'Keep left onto Pyhrn Autobahn, A9', 'name': 'Pyhrn Autobahn, A9', 'way_points': [675, 780]}, {'distance': 800.7, 'duration': 64.1, 'type': 13, 'instruction': 'Keep right', 'name': '-', 'way_points': [780, 804]}, {'distance': 49.6, 'duration': 4.0, 'type': 12, 'instruction': 'Keep left', 'name': '-', 'way_points': [804, 807]}, {'distance': 102057.2, 'duration': 4915.0, 'type': 13, 'instruction': 'Keep right', 'name': '-', 'way_points': [807, 2104]}, {'distance': 56143.4, 'duration': 2784.5, 'type': 12, 'instruction': 'Keep left onto S6', 'name': 'S6', 'way_points': [2104, 2524]}, {'distance': 7580.6, 'duration': 389.8, 'type': 12, 'instruction': 'Keep left', 'name': '-', 'way_points': [2524, 2641]}, {'distance': 789.0, 'duration': 63.1, 'type': 13, 'instruction': 'Keep right', 'name': '-', 'way_points': [2641, 2663]}, {'distance': 815.9, 'duration': 65.3, 'type': 12, 'instruction': 'Keep left', 'name': '-', 'way_points': [2663, 2684]}, {'distance': 682.9, 'duration': 54.6, 'type': 0, 'instruction': 'Turn left onto Heinrich-Drimmel-Platz', 'name': 'Heinrich-Drimmel-Platz', 'way_points': [2684, 2711]}, {'distance': 988.1, 'duration': 79.0, 'type': 0, 'instruction': 'Turn left onto Arsenalstraße', 'name': 'Arsenalstraße', 'way_points': [2711, 2723]}, {'distance': 11.7, 'duration': 2.1, 'type': 0, 'instruction': 'Turn left', 'name': '-', 'way_points': [2723, 2725]}, {'distance': 0.0, 'duration': 0.0, 'type': 10, 'instruction': 'Arrive at your destination, on the left', 'name': '-', 'way_points': [2725, 2725]}]

So I get:
|20.6|[0, 5]|
|44344|[5, 17]|
|273.0|[17, 115]|
|2679.3|[115, 675]|
|531.1|[675, 780]|
|64.1|[780, 804]|
|4.0|[804, 807]|
|4915.0|[807, 2104]|
|2784.5|[2104, 2524]|
|389.8|[2524, 2641]|
|63.1|[2641, 2663]|
|65.3|[2663, 2684]|
|54.6|[2684, 2711]|
|79.0|[2711, 2723]|
|44198|[2723, 2725]|
|0.0|[2725, 2725]|

for duration and their according way_points. The waycategory values and their geometry in this case look like that:

[0, 145, 0], [145, 169, 1], [169, 2676, 3], [2676, 2772, 0], [2772, 4566, 3], [4566, 4569, 1], [4569, 5217, 3], [5217, 5237, 1], [5237, 5563, 0], [5563, 5587, 1],…

They do not match with the steps waypoints.

So I can see no way of connecting waycategory’s waypoints + value with steps’ waypoints + durations…

If there is another way, please let me know!

Hey,

yes, the extra-info summary currently does not contain durations, but only distances - this is an error on my side, sorry for that. Adding a duration to the extra-info summary looks like a non-trivial task to me, but if you want you can still open an issue in our repo.

I agree with your assessment that it’s currently not possible to connect the information you want - at least not from a single query.

What might be possible as a workaround is to add all points where the waycategory changes to your query and issue it once more. That way, the segments should “break” at the same points where the waycategories do, and you should be able to calculate durations for waycategories from the durations of the steps.

Out of curiosity:
Do I read correctly that you are requesting a route of ~80.000 km?
If so, are you using our API and aggregating queries or are you running your own instance?

If you include another example, could you also share the request you issued? This might make it easier to see what’s going on - e.g. when summing up durations and waypoints, two durations seem to be faulty given the response from above - [5,17] has duration 44344 in your summary and 28.5 in the response, same for 44198.

Best regards,
Jakob

Hi Jakob,

I am working with my own instance via docker.

I have actually no programming/it background, but am working with ORS for my master thesis - so everything I do is trial and error.

Thanks for noticing - the code I am running after requesting the data is:

for duration in data['features'][0]['properties']['segments'][0]['steps']:
       print(duration['duration'])

    
for wp in data['features'][0]['properties']['segments'][0]['steps']:
    print(wp['way_points'])

I reran it and it is fine now - must’ve been an error when copy/pasting…:slight_smile:

Thanks, will have to look into it - my workaround for now was to use the distance and have it calculate with avg speed into duration. We’ll see how that works out!

If that could be added in time, it would be really nice! Github issues only for issues/bugs - improvements in the forum? :yum:

Hey again,

I tried rerunning the coordinates of the steps’ waypoints but couldn’t even get that far.

The waypoints value in steps in my case go up to 945649, whereas the length of “coordinates” in geometry is only 945647.

Calling geometry[945646] gives me the last coordinate… which also fits the last waypoint of waycategories, which is also 945646.

What am I missing - where do the remaining three coordinates go missing? :stuck_out_tongue:

Could you please share a requests for your example?

This is my test-request:

import openrouteservice
import pandas as pd
import requests
import json

df = pd.read_csv(r"C:\file")

lon = list(df.Longitude)
lat = list(df.Latitude)

Coordinates = list(map(lambda x, y: [x, y], lon, lat))

from itertools import groupby
coords = [x[0] for x in groupby(Coordinates)]

body = {“coordinates”:coords,“extra_info”:[“waycategory”]}

headers = {
‘Accept’: ‘application/json, application/geo+json, application/gpx+xml, img/png; charset=utf-8’,
‘Content-Type’: ‘application/geo+json; charset=utf-8’
}
call = requests.post(‘http://127.0.0.1:8080/ors/v2/directions/driving-hgv/geojson’, json=body, headers=headers)

weiter = call.text

data = json.loads(weiter)

geometry = data[‘features’][0][‘geometry’][‘coordinates’]

print(len(geometry))

print(geometry[945646])

print(len(geometry) gives:

945647

last waypoints for segments:

way_points’: [945630, 945641]}, {‘distance’: 325.1, ‘duration’: 78.0, ‘type’: 0, ‘instruction’: ‘Turn left onto Weschelstraße’, ‘name’: ‘Weschelstraße’, ‘way_points’: [945641, 945649]}, {‘distance’: 0.0, ‘duration’: 0.0, ‘type’: 10, ‘instruction’: ‘Arrive at Weschelstraße, on the right’, ‘name’: ‘-’, ‘way_points’: [945649, 945649]}]}], ‘extras’: {‘waycategory’

last waypoints for waycategory:

, [944914, 945646, 0]], ‘summary’: [{‘value’: 3.0, ‘distance’: 58139672.8, ‘amount’: 81.02}, {‘value’: 0.0, ‘distance’: 10734242.1, ‘amount’: 14.96}, {‘value’: 1.0, ‘distance’: 2628612.8, ‘amount’: 3.66}, {‘value’: 2.0, ‘distance’: 258568.3, ‘amount’: 0.36}]}}

final waypoints:

939863, 940338, 940550, 940820, 941319, 941562, 941687, 941866, 942115, 942867, 943467, 943702, 944355, 944961, 945207, 945462, 945646], ‘summary’: {‘distance’: 71761096.1,

Could you print the body, so i can replicate the route please?

Thanks for your quick responses!!

Coordinates (if that’s what you mean with body) are here:

edit. no longer needed

Wow, thats over 1k coordinate pairs… is this really ment to be a single route?
Our normal API only allows for 50 at maximum.

If you can’t reproduce this problem in a simplistic minimal example request for us to check, theres not much we can do to help here.

Well, it is not a single route per se - these are lots of routes which are done one after another and need to be analysed. I’m running it through my own instance.

Maybe I can try to loop the request for one pair of coordinates only and see if the problem keeps on occuring.

But can you confirm, geometrie’s coordinates should be as long as the segements’ steps’ waypoints?

Edit.: I tried running coordinates[0:50] and coordinates[0:500] - at 500 it’s already missing a coordinate. Probably need to run it for less coordinates :slight_smile:

I actually tried running it again for less coordinates at a time, but the problem persists - so I tried narrowing down for the coordinates where we are “losing” geometry coordinates.

It happens e.g. when rquesting a route for this coordinate pair:

[[16.399336444444444, 48.140432], [16.398647148148147, 48.140541185185185]]

which results in:

{‘type’: ‘FeatureCollection’, ‘metadata’: {‘attribution’: ‘openrouteservice.org, OpenStreetMap contributors’, ‘service’: ‘routing’, ‘timestamp’: 1619421406076, ‘query’: {‘coordinates’: [[16.399336444444444, 48.140432], [16.398647148148147, 48.140541185185185]], ‘profile’: ‘driving-hgv’, ‘format’: ‘geojson’, ‘extra_info’: [‘waycategory’]}, ‘engine’: {‘version’: ‘6.3.6’, ‘build_date’: ‘2021-02-20T08:07:49Z’, ‘graph_date’: ‘2021-02-07T21:42:03Z’}}, ‘features’: [{‘bbox’: [16.399427, 48.140437, 16.399427, 48.140437], ‘type’: ‘Feature’, ‘properties’: {‘segments’: [{‘steps’: [{‘distance’: 0.0, ‘duration’: 0.0, ‘type’: 11, ‘instruction’: ‘Head east’, ‘name’: ‘-’, ‘way_points’: [0, 1]}]}], ‘extras’: {‘waycategory’: {‘values’: , ‘summary’: }}, ‘way_points’: [0, 0], ‘summary’: {}}, ‘geometry’: {‘coordinates’: [[16.399427, 48.140437]], ‘type’: ‘LineString’}}], ‘bbox’: [16.399427, 48.140437, 16.399427, 48.140437]}

We have 2 waypoints for segments’ steps, but only 1 in geometry and waycategory’s waypoints.

Edit: It appears to be happening for coordinate pairs, which are very close together. I will try finding the other coordinates where the geometry loss happens.

Edit2: Found the next pair of coordinates where it happens:

[[16.31205681818182, 48.20351900000001], [16.31216957142857, 48.20357839285714]]

Any idea on how to deal with this?

Hmm that’s really strange behaviour.
It seems to be happening only for the hgv profile.

i’ve created an issue in our backend repo:

feel free to add details

Actually tried this - unfortunately it does not line up perfectly…

will have a look - thanks!