diff --git a/docs/RELATIONS.md b/docs/RELATIONS.md index aed6f29c..3c344f74 100644 --- a/docs/RELATIONS.md +++ b/docs/RELATIONS.md @@ -85,7 +85,7 @@ The three main processing functions (`way_function`, `node_function`, `relation_ However, relation hierarchies aren't available in `relation_scan_function`, because not all relations have been read yet. -Instead, you can supply an additional `relation_postscan_function`. This runs immediately after `relation_scan_function`, when all accepted relations are in memory. The concept is that you read the ancestor relations, and then use this to set tags on the child relation. These tags will then be accessible when reading the relation in `way_function` etc. +Instead, you can supply an additional `relation_postscan_function`. This runs immediately after `relation_scan_function`, when all accepted relations are in memory. It is called only for relations that you accepted in `relation_scan_function` and that are themselves a member of another accepted relation - not for every accepted relation. The concept is that you read the ancestor relations, and then use this to set tags on the child relation. These tags will then be accessible when reading the relation in `way_function` etc. For example, let's say you have a cycle route relation 8590454 (`type=route, route=bicycle, network=ncn, name=Loire à Vélo 3`). This has a parent relation 3199605 (`type=superroute, route=bicycle, network=ncn, name=Loire à Vélo`). You want to use the name from the latter. Write a relation_postscan_function like this: diff --git a/include/osm_store.h b/include/osm_store.h index 4f50cd5f..40ce5431 100644 --- a/include/osm_store.h +++ b/include/osm_store.h @@ -227,7 +227,9 @@ class RelationScanStore { if (relationsDone.find(rel) != relationsDone.end()) continue; relationsDone.insert(rel); // add all its parents - for (auto rp : relationsForRelations[rel]) { + auto it = relationsForRelations.find(rel); + if (it == relationsForRelations.end()) continue; + for (auto rp : it->second) { out.emplace_back(rp); relationsToDo.emplace_back(rp.first); } diff --git a/src/osm_lua_processing.cpp b/src/osm_lua_processing.cpp index c719eaac..ed261511 100644 --- a/src/osm_lua_processing.cpp +++ b/src/osm_lua_processing.cpp @@ -1432,9 +1432,11 @@ void OsmLuaProcessing::postScanRelations() { if (!supportsPostScanRelations) return; for (const auto &relp : osmStore.scannedRelations.relationsForRelations) { + RelationID id = relp.first; + // only accepted relations have stored tags; leave the others untouched + if (!osmStore.scannedRelations.has_relation_tags(id)) continue; reset(); isPostScanRelation = true; - RelationID id = relp.first; originalOsmID = id; currentPostScanTags = &(osmStore.scannedRelations.relation_tags(id)); relationList = osmStore.scannedRelations.relations_for_relation_with_parents(id);