From e041718322c44df1c8e89235e87b86666389c1d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Etil=C3=A8ne=20Jourdier?= Date: Sun, 13 Jul 2025 00:07:43 +0200 Subject: [PATCH 1/2] create function to get OSM type --- docs/CONFIGURATION.md | 1 + include/osm_lua_processing.h | 3 +++ src/osm_lua_processing.cpp | 7 +++++++ 3 files changed, 11 insertions(+) diff --git a/docs/CONFIGURATION.md b/docs/CONFIGURATION.md index 8533183b..dd84a88d 100644 --- a/docs/CONFIGURATION.md +++ b/docs/CONFIGURATION.md @@ -151,6 +151,7 @@ To do that, you use these methods: * `Attribute(key,value,minzoom)`: add an attribute to the most recently written layer. Argument `minzoom` is optional, use it if you do not want to write the attribute on lower zoom levels. * `AttributeNumeric(key,value,minzoom)`, `AttributeBoolean(key,value,minzoom)`: for numeric/boolean columns. * `Id()`: get the OSM ID of the current object. +* `OsmType()`: get the OSM type of the current object. * `IsClosed()`: returns true if the current object is a closed area. * `IsMultiPolygon()`: returns true if the current object is a multipolygon. * `ZOrder(number)`: Set a numeric value (default 0) used to sort features within a layer. Use this feature to ensure a proper rendering order if the rendering engine itself does not support sorting. Sorting is not supported across layers merged with `write_to`. Features with different z-order are not merged if `combine_below` or `combine_polygons_below` is used. Use this in conjunction with `feature_limit` to only write the most important (highest z-order) features within a tile. (Values can be -50,000,000 to 50,000,000 and are lossy, particularly beyond -1000 to 1000.) diff --git a/include/osm_lua_processing.h b/include/osm_lua_processing.h index 72100635..0218a7de 100644 --- a/include/osm_lua_processing.h +++ b/include/osm_lua_processing.h @@ -115,6 +115,9 @@ class OsmLuaProcessing { // Get the ID of the current object std::string Id() const; + // Get the Type of the current object + std::string OsmType() const; + // Gets a table of all the keys of the OSM tags kaguya::LuaTable AllKeys(kaguya::State& luaState); diff --git a/src/osm_lua_processing.cpp b/src/osm_lua_processing.cpp index cba5948c..5b1bbc57 100644 --- a/src/osm_lua_processing.cpp +++ b/src/osm_lua_processing.cpp @@ -141,6 +141,7 @@ kaguya::LuaTable getAllTags(kaguya::State& luaState, const boost::container::fla } std::string rawId() { return osmLuaProcessing->Id(); } +std::string rawOsmType() { return osmLuaProcessing->OsmType(); } kaguya::LuaTable rawAllKeys() { if (osmLuaProcessing->isPostScanRelation) { return osmLuaProcessing->AllKeys(*g_luaState); @@ -247,6 +248,7 @@ OsmLuaProcessing::OsmLuaProcessing( osmLuaProcessing = this; luaState["Id"] = &rawId; + luaState["OsmType"] = &rawOsmType; luaState["AllKeys"] = &rawAllKeys; luaState["AllTags"] = &rawAllTags; luaState["Holds"] = &rawHolds; @@ -356,6 +358,11 @@ string OsmLuaProcessing::Id() const { return to_string(originalOsmID); } +// Get the Type of the current object +string OsmLuaProcessing::OsmType() const { + return (isRelation ? "relation " : isWay ? "way " : "node "); +} + // Gets a table of all the keys of the OSM tags kaguya::LuaTable OsmLuaProcessing::AllKeys(kaguya::State& luaState) { // NOTE: this is only called in the PostScanRelation phase -- other phases are handled in rawAllKeys From 4db337185ad34e878ca8700aca11e1a1848f945b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Etil=C3=A8ne=20Jourdier?= Date: Mon, 29 Sep 2025 22:39:15 +0200 Subject: [PATCH 2/2] correct type in OsmType() --- src/osm_lua_processing.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/osm_lua_processing.cpp b/src/osm_lua_processing.cpp index 5b1bbc57..77490586 100644 --- a/src/osm_lua_processing.cpp +++ b/src/osm_lua_processing.cpp @@ -360,7 +360,7 @@ string OsmLuaProcessing::Id() const { // Get the Type of the current object string OsmLuaProcessing::OsmType() const { - return (isRelation ? "relation " : isWay ? "way " : "node "); + return (isRelation ? "relation" : isWay ? "way" : "node"); } // Gets a table of all the keys of the OSM tags