Skip to content

Commit 68847d3

Browse files
authored
Add new function to allow ID modification (#866)
* add new function to allow ID modification * document modifyId
1 parent 9ae6a27 commit 68847d3

3 files changed

Lines changed: 11 additions & 0 deletions

File tree

docs/CONFIGURATION.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ Note that this is not compatible with the `combine_xxx` settings to reduce tiles
128128

129129
If you need to include OSM object types as well, you can use the `OsmType()` function in your `process.lua` script.
130130

131+
It is possible to override the original OSM ID using the function `ModifyId(newId)`.
132+
131133
## Lua processing reference
132134

133135
Your Lua file can supply these functions for tilemaker to call:
@@ -163,6 +165,7 @@ To do that, you use these methods:
163165
* `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.
164166
* `AttributeNumeric(key,value,minzoom)`, `AttributeInteger(key,value,minzoom)`, `AttributeBoolean(key,value,minzoom)`: for numeric (floating-point), integer and boolean columns.
165167
* `Id()`: get the OSM ID of the current object.
168+
* `ModifyId(newId)`: replace the ID of the current object with newId.
166169
* `OsmType()`: get the OSM type of the current object.
167170
* `IsClosed()`: returns true if the current object is a closed area.
168171
* `IsMultiPolygon()`: returns true if the current object is a multipolygon.

include/osm_lua_processing.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ class OsmLuaProcessing {
197197
void LayerAsCentroid(const std::string &layerName, kaguya::VariadicArgType nodeSources);
198198

199199
// Set attributes in a vector tile's Attributes table
200+
void ModifyId(const int newId);
200201
void Attribute(const std::string &key, const protozero::data_view val, const char minzoom);
201202
void AttributeNumeric(const std::string &key, const double val, const char minzoom);
202203
void AttributeBoolean(const std::string &key, const bool val, const char minzoom);

src/osm_lua_processing.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ bool rawIsMultiPolygon() { return osmLuaProcessing->IsMultiPolygon(); }
188188
double rawArea() { return osmLuaProcessing->Area(); }
189189
double rawLength() { return osmLuaProcessing->Length(); }
190190
kaguya::optional<std::vector<double>> rawCentroid(kaguya::VariadicArgType algorithm) { return osmLuaProcessing->Centroid(algorithm); }
191+
void rawModifyId(const int newId) { return osmLuaProcessing->ModifyId(newId); }
191192
void rawLayer(const std::string& layerName, bool area) { return osmLuaProcessing->Layer(layerName, area); }
192193
void rawLayerAsCentroid(const std::string &layerName, kaguya::VariadicArgType nodeSources) { return osmLuaProcessing->LayerAsCentroid(layerName, nodeSources); }
193194
void rawMinZoom(const double z) { return osmLuaProcessing->MinZoom(z); }
@@ -267,6 +268,7 @@ OsmLuaProcessing::OsmLuaProcessing(
267268
luaState["Centroid"] = &rawCentroid;
268269
luaState["Layer"] = &rawLayer;
269270
luaState["LayerAsCentroid"] = &rawLayerAsCentroid;
271+
luaState["ModifyId"] = &rawModifyId;
270272
luaState["Attribute"] = kaguya::overload(
271273
[](const std::string &key, const protozero::data_view val) { osmLuaProcessing->Attribute(key, val, 0); },
272274
[](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) {
922924
outputKeys.push_back(key);
923925
}
924926

927+
// Force a new ID
928+
void OsmLuaProcessing::ModifyId(const int newId) {
929+
originalOsmID = static_cast<int64_t>(newId);
930+
}
931+
925932
// Set attributes in a vector tile's Attributes table
926933
void OsmLuaProcessing::Attribute(const string &key, const protozero::data_view val, const char minzoom) {
927934
if (outputs.size()==0) { ProcessingError("Can't add Attribute if no Layer set"); return; }

0 commit comments

Comments
 (0)