I am trying to implement encoded values for custom attributes, but the details of the encoded values in the routing response seems erroneous. I request your help to help me understand and fix this. I am using 10.0 SNAPSHOT.
What I have done:
I have calculated an attribute called “road_curvature_classification” for each way_id, and added these to the input PBF file on which my GraphHopper server is running.
I have also created the encoded value for “road_curvature_classification” (Created the RoadCurvatureClassification class, updated it in DefaultImportRegistry and created RoadCurvatureClassificationParser), and mentioned it in my config file in graph.encoded_values (along with osm_way_id).
In my routing request, I have mentioned both osm_way_id and road_curvature_classification in “details”
The response json does contain the osm_way_ids and road_curvature_classification. But while the osm_way_id is mapped correctly to the segments, the road_curvature_classification is incorrect.
The road_curvature_classification is not returned correctly. In the above image, I have also mapped the actual road_curvature_classification that each osm_way_id is mapped to, in the input PBF file.
The segments for road_curvature_classification in the GH response does not correspond to the same segments as the osm_way_id. This is weird, since the road_curvature_classification is actually mapped to the osm_way_id in the PBF file, and read from the osm_way_id in the RoadCurvatureClassificationParser.
With a few tests I figured that the road_curvature_classification always follows the same format as below: (road segments 0 to n)
[segment_start, segment_end, road_curvature_classification] =
[0,1,A], [1,n-1, B], [n-1,n, C] OR
[0,1,A], [1,n, B].
The actual classification returned (A,B,C) seems to follow no specific consistent pattern (doesnt match to the first/last osm_way_id’s classification)
My objective is to “describe” the route in terms of the custom-defined road_curvature_classification values., i.e., obtain the yellow highlighted column below.
The first thing I would try is enabling the Routing Graph Layer in the layer menu of the GH Maps UI. Then you can hover the roads to see their attributes / encoded values. Do the values of road_curvature_classification for the different roads match those you set in your input data?
@easbar - Thanks for your suggestion! I checked the routing graph layer and the road_curvature_classification values are not matching the input data. I guess I need to check the parser, let me do that and post here in case I am still stuck. Surprisingly, the details in routing response is not totally matching the visual inspection using routing graph layer. What I mean is, for example, the osm_way_id 880897089 is returned for the segment from [1650-1682]. While that osm_way_id has a road_curvature_classification as high in the routing graph layer, the segment [1681-1682] still shows medium! I will investigate my encoded values.
Request:
I want some more control on how I define the road curvature - essentially I am also relating to the average curvature of roads in that area, and accordingly changing the thresholds for “medium”/“high”. E.g.: for motorcyclists who are in a city in the plains, a curvature value of say, 0.7 may correspond to “high”, whereas for someone who lives in the Himalayan foothills, it may correspond to only “medium”
I am using road_curvature_classification as a test use case, and will define other encoded values using this template (once I am successful ). For e.g., I also have a road_classification attribute which provides values that are useful in the Indian context (you can see in the response screenshot above) - for which I am deriving values from a combination of the ref field, and some additional spatial work in postgres.
Thanks both, I will check and post here again if I am still stuck.
This issue got fixed, there was an issue in the Parser - thanks for the help @easbar and @karussell . I am now able to get the road_curvature_classification encoded values for each segment correctly.
Another question:
In order to make sense of the response in the way I require - which is I want to check the % share of roads falling under each defined road_curvature_classification (refer image above in the original post for an example) - I am currently doing these calculations in post processing. I was wondering what it would take for me to get these share % values in the routing response itself, something like below.
ResponsePath.java : Added fields and corresponding getter and setter methods for straightCurvatureDistance, mediumCurvatureDistance, and highCurvatureDistance.
CHPathCalculator.java : Implemented the logic to iterate through each edge of the calculated paths and sum up the distances based on the road_curvature_classification attribute. The calculated distances are then set in the ResponsePath object.
FlexiblePathCalculator.java: Similar update as CHPathCalculator.java
GHResponse.java: Added methods to retrieve the custom distance metrics from the best path in the response.
However, I am getting multiple compilation errors (which I am working through). But I wanted to check if the approach is correct? If not, can you please give me a broad guidance?