Skip to content

Commit

Permalink
RestartRelations() to reset relation subscript (#548)
Browse files Browse the repository at this point in the history
  • Loading branch information
systemed authored Oct 9, 2023
1 parent 98246b3 commit dbdb4da
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/RELATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions include/osm_lua_processing.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ class OsmLuaProcessing {

// Relation scan support
kaguya::optional<int> NextRelation();
void RestartRelations();
std::string FindInRelation(const std::string &key);
void Accept();

Expand Down
5 changes: 5 additions & 0 deletions src/osm_lua_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down Expand Up @@ -525,6 +526,10 @@ kaguya::optional<int> 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);
}
Expand Down

0 comments on commit dbdb4da

Please sign in to comment.