diff --git a/docs/CONFIGURATION.md b/docs/CONFIGURATION.md index 5ca2165a..a7bdd14e 100644 --- a/docs/CONFIGURATION.md +++ b/docs/CONFIGURATION.md @@ -128,6 +128,8 @@ Note that this is not compatible with the `combine_xxx` settings to reduce tiles If you need to include OSM object types as well, you can use the `OsmType()` function in your `process.lua` script. +It is possible to override the original OSM ID using the function `ModifyId(newId)`. + ## Lua processing reference Your Lua file can supply these functions for tilemaker to call: @@ -163,6 +165,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)`, `AttributeInteger(key,value,minzoom)`, `AttributeBoolean(key,value,minzoom)`: for numeric (floating-point), integer and boolean columns. * `Id()`: get the OSM ID of the current object. +* `ModifyId(newId)`: replace the ID of the current object with newId. * `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. diff --git a/include/osm_lua_processing.h b/include/osm_lua_processing.h index b34d9b5f..539c745c 100644 --- a/include/osm_lua_processing.h +++ b/include/osm_lua_processing.h @@ -197,6 +197,7 @@ class OsmLuaProcessing { void LayerAsCentroid(const std::string &layerName, kaguya::VariadicArgType nodeSources); // Set attributes in a vector tile's Attributes table + void ModifyId(const int newId); void Attribute(const std::string &key, const protozero::data_view val, const char minzoom); void AttributeNumeric(const std::string &key, const double val, const char minzoom); void AttributeBoolean(const std::string &key, const bool val, const char minzoom); diff --git a/src/osm_lua_processing.cpp b/src/osm_lua_processing.cpp index 33a80887..c395b902 100644 --- a/src/osm_lua_processing.cpp +++ b/src/osm_lua_processing.cpp @@ -188,6 +188,7 @@ bool rawIsMultiPolygon() { return osmLuaProcessing->IsMultiPolygon(); } double rawArea() { return osmLuaProcessing->Area(); } double rawLength() { return osmLuaProcessing->Length(); } kaguya::optional> rawCentroid(kaguya::VariadicArgType algorithm) { return osmLuaProcessing->Centroid(algorithm); } +void rawModifyId(const int newId) { return osmLuaProcessing->ModifyId(newId); } void rawLayer(const std::string& layerName, bool area) { return osmLuaProcessing->Layer(layerName, area); } void rawLayerAsCentroid(const std::string &layerName, kaguya::VariadicArgType nodeSources) { return osmLuaProcessing->LayerAsCentroid(layerName, nodeSources); } void rawMinZoom(const double z) { return osmLuaProcessing->MinZoom(z); } @@ -267,6 +268,7 @@ OsmLuaProcessing::OsmLuaProcessing( luaState["Centroid"] = &rawCentroid; luaState["Layer"] = &rawLayer; luaState["LayerAsCentroid"] = &rawLayerAsCentroid; + luaState["ModifyId"] = &rawModifyId; luaState["Attribute"] = kaguya::overload( [](const std::string &key, const protozero::data_view val) { osmLuaProcessing->Attribute(key, val, 0); }, [](const std::string &key, const protozero::data_view val, const char minzoom) { osmLuaProcessing->Attribute(key, val, minzoom); } @@ -922,6 +924,11 @@ void OsmLuaProcessing::removeAttributeIfNeeded(const string& key) { outputKeys.push_back(key); } +// Force a new ID +void OsmLuaProcessing::ModifyId(const int newId) { + originalOsmID = static_cast(newId); +} + // Set attributes in a vector tile's Attributes table void OsmLuaProcessing::Attribute(const string &key, const protozero::data_view val, const char minzoom) { if (outputs.size()==0) { ProcessingError("Can't add Attribute if no Layer set"); return; }