Skip to content

Commit 4a85c60

Browse files
authored
Compile-time option for float ZOrder (#486)
1 parent 06e0b28 commit 4a85c60

5 files changed

Lines changed: 37 additions & 4 deletions

File tree

docs/CONFIGURATION.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ To do that, you use these methods:
134134
* `node:Attribute(key,value)` or `node:Attribute(key,value)`: add an attribute to the most recently written layer.
135135
* `node:AttributeNumeric(key,value)`, `node:AttributeBoolean(key,value)` (and `way:`...): for numeric/boolean columns.
136136
* `node:Id()` or `way:Id()`: get the OSM ID of the current object.
137-
* `node:ZOrder(number)` or `way:ZOrder(number)`: Set a numeric value (default 0, 1-byte unsigned integer) 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.
137+
* `node:ZOrder(number)` or `way:ZOrder(number)`: Set a numeric value (default 0, 1-byte signed integer) 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.
138138
* `node:MinZoom(zoom)` or `way: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).
139139
* `way:Length()` and `way:Area()`: return the length (metres)/area (square metres) of the current object. Requires recent Boost.
140140
* `way:Centroid()`: return the lat/lon of the centre of the current object as a two-element Lua table (element 1 is lat, 2 is lon).

docs/INSTALL.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,13 @@ The docker container can be run like this:
6363
docker run -v /Users/Local/Downloads/:/srv -i -t --rm tilemaker /srv/germany-latest.osm.pbf --output=/srv/germany.mbtiles
6464

6565
Keep in mind to map the volume your .osm.pbf files are in to a path within your docker container, as seen in the example above.
66+
67+
### Compile-time options
68+
69+
tilemaker has two compile-time options that increase memory usage but may be useful in certain circumstances. You can include them when building like this:
70+
71+
make "CONFIG=-DFLOAT_Z_ORDER"
72+
73+
FLOAT_Z_ORDER allows you to use a full range of ZOrder values in your Lua script, rather than being restricted to single-byte integer (-127 to 127).
74+
75+
FAT_TILE_INDEX allows you to generate vector tiles at zoom level 17 or greater. You almost certainly don't need to do this. Vector tiles are usually generated up to zoom 14 (sometimes 15), and then the browser/app client uses the vector data to scale up at subsequent zoom levels.

include/osm_lua_processing.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ class OsmLuaProcessing {
161161
void AttributeBooleanWithMinZoom(const std::string &key, const bool val, const char minzoom);
162162
void MinZoom(const double z);
163163
void ZOrder(const double z);
164+
void ZOrderWithScale(const double z, const double scale);
164165

165166
// Relation scan support
166167
kaguya::optional<int> NextRelation();

include/output_object.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
#include "osmformat.pb.h"
1616
#include "vector_tile.pb.h"
1717

18+
#ifdef FLOAT_Z_ORDER
19+
typedef float ZOrder;
20+
#else
21+
typedef int8_t ZOrder;
22+
#endif
23+
1824
enum OutputGeometryType : unsigned int { POINT_, LINESTRING_, MULTILINESTRING_, POLYGON_ };
1925

2026
#define OSMID_TYPE_OFFSET 40
@@ -46,16 +52,18 @@ class OutputObject {
4652
public:
4753
NodeID objectID : 42; // id of way (linestring/polygon) or node (point)
4854
uint_least8_t layer : 8; // what layer is it in?
49-
int8_t z_order : 8; // z_order: used for sorting features within layers
55+
ZOrder z_order ; // z_order: used for sorting features within layers
5056
OutputGeometryType geomType : 2; // point, linestring, polygon
5157
unsigned minZoom : 4;
5258

5359
AttributeStoreRef attributes;
5460

55-
void setZOrder(const int z) {
61+
void setZOrder(const ZOrder z) {
62+
#ifndef FLOAT_Z_ORDER
5663
if (z <= -127 || z >= 127) {
5764
throw std::runtime_error("z_order is limited to 1 byte signed integer.");
5865
}
66+
#endif
5967
z_order = z;
6068
}
6169

src/osm_lua_processing.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ OsmLuaProcessing::OsmLuaProcessing(
5555
.addOverloadedFunctions("AttributeNumeric", &OsmLuaProcessing::AttributeNumeric, &OsmLuaProcessing::AttributeNumericWithMinZoom)
5656
.addOverloadedFunctions("AttributeBoolean", &OsmLuaProcessing::AttributeBoolean, &OsmLuaProcessing::AttributeBooleanWithMinZoom)
5757
.addFunction("MinZoom", &OsmLuaProcessing::MinZoom)
58-
.addFunction("ZOrder", &OsmLuaProcessing::ZOrder)
58+
.addOverloadedFunctions("ZOrder", &OsmLuaProcessing::ZOrder, &OsmLuaProcessing::ZOrderWithScale)
5959
.addFunction("Accept", &OsmLuaProcessing::Accept)
6060
.addFunction("NextRelation", &OsmLuaProcessing::NextRelation)
6161
.addFunction("FindInRelation", &OsmLuaProcessing::FindInRelation)
@@ -501,7 +501,21 @@ void OsmLuaProcessing::MinZoom(const double z) {
501501
// Set z_order
502502
void OsmLuaProcessing::ZOrder(const double z) {
503503
if (outputs.size()==0) { ProcessingError("Can't set z_order if no Layer set"); return; }
504+
#ifdef FLOAT_Z_ORDER
505+
outputs.back().first->setZOrder(make_valid<float>(z));
506+
#else
504507
outputs.back().first->setZOrder(make_valid<int>(z));
508+
#endif
509+
}
510+
511+
// Set z_order (variant with scaling)
512+
void OsmLuaProcessing::ZOrderWithScale(const double z, const double scale) {
513+
if (outputs.size()==0) { ProcessingError("Can't set z_order if no Layer set"); return; }
514+
#ifdef FLOAT_Z_ORDER
515+
outputs.back().first->setZOrder(make_valid<float>(z));
516+
#else
517+
outputs.back().first->setZOrder(make_valid<int>(z/scale*127));
518+
#endif
505519
}
506520

507521
// Read scanned relations

0 commit comments

Comments
 (0)