Hello. I need to add RelationTagParser which would parse all relations with tag “piste” and modify access for all ways inside this relation.
I tried to duplicate code from OSMFootNetworkTagParser. My relation parser looks like this:
class PisteRelationParser(private val pisteNordicEnc: BooleanEncodedValue, relConfig: EncodedValue.InitializerConfig) : RelationTagParser {
val transformerPisteEnc = SimpleBooleanEncodedValue(getKey("piste", "piste_relation"))
init {
transformerPisteEnc.init(relConfig)
}
override fun handleRelationTags(relFlags: IntsRef, relation: ReaderRelation) {
val relIntAccess = IntsRefEdgeIntAccess(relFlags)
val type = relation.tags.get("piste:type") as? String
if (type == "nordic") {
transformerPisteEnc.setBool(false, -1, relIntAccess, true)
}
}
override fun handleWayTags(edgeId: Int, edgeIntAccess: EdgeIntAccess, way: ReaderWay, relationFlags: IntsRef) {
val relIntAccess = IntsRefEdgeIntAccess(relationFlags)
val isNordicPiste = transformerPisteEnc.getBool(false, -1, relIntAccess)
pisteNordicEnc.setBool(false, edgeId, edgeIntAccess, isNordicPiste)
}
}
All I do in other TagParsers is checking this boolean value and treat it as correct way:
Speed:
val isNordicRelation = nordicRelation.getBool(false, edgeId, edgeIntAccess)
if (isNordicRelation) { setSpeed(false, edgeId, edgeIntAccess, 5.0) }
Access:
val isNordicRelation = nordicRelation.getBool(false, edgeId, edgeIntAccess)
if (isNordicRelation) {
accessEnc.setBool(false, edgeId, edgeIntAccess, true)
accessEnc.setBool(true, edgeId, edgeIntAccess, true)
}
Priority:
val isNordicRelation = nordicRelation.getBool(false, edgeId, edgeIntAccess)
if (isNordicRelation) {
priorityWayEncoder.setDecimal(false, edgeId, edgeIntAccess, PriorityCode.getValue(PriorityCode.BEST.value))
}
I made prints and I am sure that correct ways are marked as “isNordicRelation”, but routing doesn’t always work. If I limit reading relation to only one (for example this) then it will work:
val relIntAccess = IntsRefEdgeIntAccess(relFlags)
val type = relation.tags.get("piste:type") as? String
if (type == "nordic" && (relation.id == 8269871L)) {
transformerPisteEnc.setBool(false, -1, relIntAccess, true)
}
But if I allow to read one more relation (like this):
val relIntAccess = IntsRefEdgeIntAccess(relFlags)
val type = relation.tags.get("piste:type") as? String
if (type == "nordic" && (relation.id == 8269871L || relation.id == 3900859L)) {
transformerPisteEnc.setBool(false, -1, relIntAccess, true)
}
Then only one of those relations will work. What is suprising that if I print “isNordicRelation” in TagParsers then ways from both relations will have correct value!!! I think that reading relation and passing its data to Ways works correctly, but something is wrong when graph is limited to small number of possible ways?
Everything is tested on Graphhoper 8.0