Hello!
I’m trying to encode trail colors into Graphhopper. The colors are typically part of relations, and it worked perfectly when there was only one relation. However, I have encountered a problem with ways that are part of multiple relations, each with its own color. For example, this way is part of two relations, both of which have a color:
In my code, I can see that Graphhopper is reading both relations and their respective colors:
override fun handleRelationTags(relFlags: IntsRef, relation: ReaderRelation) {
val relIntAccess = IntsRefEdgeIntAccess(relFlags)
val colour = relation.getTag("colour")
val osmcSymbol = relation.getTag("osmcSymbol")
val colors = when {
colour != null -> RouteColors.fromColourTag(colour)
osmcSymbol != null -> RouteColors.fromOsmcSymbolTag(osmcSymbol)
else -> null
}
if (relation.id == 3360362L) {
println("Colors $colors")
}
if (relation.id == 3352332L) {
println("Colors $colors")
}
if (colors != null) {
transformerRouteTypeEnc.setInt(false, -1, relIntAccess, colors.encode())
}
}
In this snippet, the two if
statements are there to confirm that both relations are being read correctly and that I get colors from them.
However, when I read the color value in the way, I only see one of them (the second value that was printed):
override fun handleWayTags(edgeId: Int, edgeIntAccess: EdgeIntAccess, way: ReaderWay, relationFlags: IntsRef) {
val relIntAccess = IntsRefEdgeIntAccess(relationFlags)
val colors = RouteColors.decode(transformerRouteTypeEnc.getInt(false, -1, relIntAccess))
if (way.id == 28126961L) {
println("For way ${way.id} colors $colors") // Only RED color here, from the second relation
}
}
I was under the impression that handleWayTags
would be called once for each relation associated with the way. However, it is only being called once. I was expecting I could merge the results from both relations, it is not possible if handleWayTags is called once.
How can I achieve the desired result and merge the colors from both relations?