-
Notifications
You must be signed in to change notification settings - Fork 239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Add global lua function to list all tags #748
Comments
I've create a patch for this, but my C++ isn't great, so while it does work, there are probably better methods. I'll leave this up here for any comments, and I can create a PR is desired. diff --git a/include/osm_lua_processing.h b/include/osm_lua_processing.h
index f4d664d..ca7627a 100644
--- a/include/osm_lua_processing.h
+++ b/include/osm_lua_processing.h
@@ -111,6 +111,9 @@ public:
// Get the ID of the current object
std::string Id() const;
+ // Gets a table of all the OSM tags
+ kaguya::LuaTable AllTags(kaguya::State& luaState);
+
// Check if there's a value for a given key
bool Holds(const std::string& key) const;
diff --git a/src/osm_lua_processing.cpp b/src/osm_lua_processing.cpp
index 545b1f3..e2ea791 100644
--- a/src/osm_lua_processing.cpp
+++ b/src/osm_lua_processing.cpp
@@ -118,6 +118,20 @@ template<> struct kaguya::lua_type_traits<protozero::data_view> {
};
std::string rawId() { return osmLuaProcessing->Id(); }
+kaguya::LuaTable rawAllTags() {
+ if (osmLuaProcessing->isPostScanRelation) {
+ return osmLuaProcessing->AllTags(*g_luaState);
+ }
+
+ auto tags = osmLuaProcessing->currentTags->exportToBoostMap();
+ kaguya::LuaTable tagsTable = g_luaState->newTable();
+
+ for (const auto& kv : tags) {
+ tagsTable[kv.first] = kv.second;
+ }
+
+ return tagsTable;
+}
bool rawHolds(const KnownTagKey& key) {
if (osmLuaProcessing->isPostScanRelation) {
return osmLuaProcessing->Holds(key.stringValue);
@@ -196,6 +210,7 @@ OsmLuaProcessing::OsmLuaProcessing(
osmLuaProcessing = this;
luaState["Id"] = &rawId;
+ luaState["AllTags"] = &rawAllTags;
luaState["Holds"] = &rawHolds;
luaState["Find"] = &rawFind;
luaState["HasTags"] = &rawHasTags;
@@ -290,6 +305,16 @@ string OsmLuaProcessing::Id() const {
return to_string(originalOsmID);
}
+// Gets a table of all the OSM tags
+kaguya::LuaTable OsmLuaProcessing::AllTags(kaguya::State& luaState) {
+ // NOTE: this is only called in the PostScanRelation phase -- other phases are handled in rawAllTags
+ kaguya::LuaTable tagsTable = luaState.newTable();
+ for (const auto& kv: *currentPostScanTags) {
+ tagsTable[kv.first] = kv.second;
+ }
+ return tagsTable;
+}
+
// Check if there's a value for a given key
bool OsmLuaProcessing::Holds(const string& key) const {
// NOTE: this is only called in the PostScanRelation phase -- other phases are handled in rawHolds |
oobayly
added a commit
to oobayly/tilemaker
that referenced
this issue
Sep 9, 2024
systemed
pushed a commit
that referenced
this issue
Oct 13, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could we have a global function that would allow us to iterate through all the key-value pairs in the
currentPostScanTags
? I would to be able to add attributes which have a certain prefix.I'm trying to create a layer whose tags can't easily be abstracted, and would like to be able to include all the tags (at the cost of increased tile size) that may be needed for rendering via MapLibre without having to rebuild the tiles.
The text was updated successfully, but these errors were encountered: