From dbdb4da09772ec38422d99cf870f13a9a635166b Mon Sep 17 00:00:00 2001 From: Richard Fairhurst Date: Mon, 9 Oct 2023 12:30:03 +0200 Subject: [PATCH] RestartRelations() to reset relation subscript (#548) --- docs/RELATIONS.md | 2 ++ include/osm_lua_processing.h | 1 + src/osm_lua_processing.cpp | 5 +++++ 3 files changed, 8 insertions(+) diff --git a/docs/RELATIONS.md b/docs/RELATIONS.md index a30cfdcc..6e436b68 100644 --- a/docs/RELATIONS.md +++ b/docs/RELATIONS.md @@ -41,6 +41,8 @@ Now that you've accepted the relations, they will be available from `way_functio print ("Part of route "..way:FindInRelation("ref")) end +(Should you need to re-read the relations, you can reset the iterator with `way:RestartRelations()`.) + ### Writing relation geometries diff --git a/include/osm_lua_processing.h b/include/osm_lua_processing.h index 1485a0b2..c111c00b 100644 --- a/include/osm_lua_processing.h +++ b/include/osm_lua_processing.h @@ -165,6 +165,7 @@ class OsmLuaProcessing { // Relation scan support kaguya::optional NextRelation(); + void RestartRelations(); std::string FindInRelation(const std::string &key); void Accept(); diff --git a/src/osm_lua_processing.cpp b/src/osm_lua_processing.cpp index c69d55bc..d368ed8d 100644 --- a/src/osm_lua_processing.cpp +++ b/src/osm_lua_processing.cpp @@ -58,6 +58,7 @@ OsmLuaProcessing::OsmLuaProcessing( .addOverloadedFunctions("ZOrder", &OsmLuaProcessing::ZOrder, &OsmLuaProcessing::ZOrderWithScale) .addFunction("Accept", &OsmLuaProcessing::Accept) .addFunction("NextRelation", &OsmLuaProcessing::NextRelation) + .addFunction("RestartRelations", &OsmLuaProcessing::RestartRelations) .addFunction("FindInRelation", &OsmLuaProcessing::FindInRelation) ); supportsRemappingShapefiles = !!luaState["attribute_function"]; @@ -525,6 +526,10 @@ kaguya::optional OsmLuaProcessing::NextRelation() { return relationList[relationSubscript]; } +void OsmLuaProcessing::RestartRelations() { + relationSubscript = -1; +} + std::string OsmLuaProcessing::FindInRelation(const std::string &key) { return osmStore.get_relation_tag(relationList[relationSubscript], key); }