1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
From 8d372c02eac37c7a1e80bfb12e40d20ad19a07d6 Mon Sep 17 00:00:00 2001
From: Richard Fairhurst <richard@systemeD.net>
Date: Mon, 14 Apr 2025 21:21:53 +0100
Subject: IsMultiPolygon Lua method (#810)
---
docs/CONFIGURATION.md | 2 ++
include/osm_lua_processing.h | 1 +
src/osm_lua_processing.cpp | 7 +++++++
3 files changed, 10 insertions(+)
diff --git a/docs/CONFIGURATION.md b/docs/CONFIGURATION.md
index 5919f31..49ab1ad 100644
--- a/docs/CONFIGURATION.md
+++ b/docs/CONFIGURATION.md
@@ -151,6 +151,8 @@ 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.
+* `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.)
* `MinZoom(zoom)`: set the minimum zoom level (0-15) at which this object will be written. Note that the JSON layer configuration minimum still applies (so `:MinZoom(5)` will have no effect if your layer only starts at z6).
* `Length()` and `Area()`: return the length (metres)/area (square metres) of the current object. Requires Boost 1.67+.
diff --git a/include/osm_lua_processing.h b/include/osm_lua_processing.h
index bfcb5d4..86cd680 100644
--- a/include/osm_lua_processing.h
+++ b/include/osm_lua_processing.h
@@ -143,6 +143,7 @@ public:
// Returns whether it is closed polygon
bool IsClosed() const;
+ bool IsMultiPolygon() const;
// Returns area
double Area();
diff --git a/src/osm_lua_processing.cpp b/src/osm_lua_processing.cpp
index 62cdf10..2200794 100644
--- a/src/osm_lua_processing.cpp
+++ b/src/osm_lua_processing.cpp
@@ -181,6 +181,7 @@ bool rawIntersects(const std::string& layerName) { return osmLuaProcessing->Inte
std::vector<std::string> rawFindCovering(const std::string& layerName) { return osmLuaProcessing->FindCovering(layerName); }
bool rawCoveredBy(const std::string& layerName) { return osmLuaProcessing->CoveredBy(layerName); }
bool rawIsClosed() { return osmLuaProcessing->IsClosed(); }
+bool rawIsMultiPolygon() { return osmLuaProcessing->IsMultiPolygon(); }
double rawArea() { return osmLuaProcessing->Area(); }
double rawLength() { return osmLuaProcessing->Length(); }
kaguya::optional<std::vector<double>> rawCentroid(kaguya::VariadicArgType algorithm) { return osmLuaProcessing->Centroid(algorithm); }
@@ -246,6 +247,7 @@ OsmLuaProcessing::OsmLuaProcessing(
luaState["FindCovering"] = &rawFindCovering;
luaState["CoveredBy"] = &rawCoveredBy;
luaState["IsClosed"] = &rawIsClosed;
+ luaState["IsMultiPolygon"] = &rawIsMultiPolygon;
luaState["Area"] = &rawArea;
luaState["AreaIntersecting"] = &rawAreaIntersecting;
luaState["Length"] = &rawLength;
@@ -475,6 +477,11 @@ bool OsmLuaProcessing::IsClosed() const {
return isClosed;
}
+// Return whether it's a multipolygon
+bool OsmLuaProcessing::IsMultiPolygon() const {
+ return isWay && isRelation;
+}
+
void reverse_project(DegPoint& p) {
geom::set<1>(p, latp2lat(geom::get<1>(p)));
}
--
2.47.3
|