Skip to content

Commit 687f63d

Browse files
committed
add combineLinesBelow in layers
1 parent 0ebc1d7 commit 687f63d

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

include/shared_data.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct LayerDef {
3131
uint featureLimit;
3232
uint featureLimitBelow;
3333
bool combinePoints;
34+
uint combineLinesBelow;
3435
std::string source;
3536
std::vector<std::string> sourceColumns;
3637
bool allSourceColumns;
@@ -59,7 +60,7 @@ class LayerDefinition {
5960
uint addLayer(std::string name, uint minzoom, uint maxzoom,
6061
uint simplifyBelow, double simplifyLevel, double simplifyLength, double simplifyRatio, uint simplifyAlgo,
6162
uint filterBelow, double filterArea, uint combinePolygonsBelow, bool sortZOrderAscending,
62-
uint featureLimit, uint featureLimitBelow, bool combinePoints,
63+
uint featureLimit, uint featureLimitBelow, bool combinePoints, uint combineLinesBelow,
6364
const std::string &source,
6465
const std::vector<std::string> &sourceColumns,
6566
bool allSourceColumns,

src/shared_data.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void SharedData::writePMTilesBounds() {
137137
uint LayerDefinition::addLayer(string name, uint minzoom, uint maxzoom,
138138
uint simplifyBelow, double simplifyLevel, double simplifyLength, double simplifyRatio, uint simplifyAlgo,
139139
uint filterBelow, double filterArea, uint combinePolygonsBelow, bool sortZOrderAscending,
140-
uint featureLimit, uint featureLimitBelow, bool combinePoints,
140+
uint featureLimit, uint featureLimitBelow, bool combinePoints, uint combineLinesBelow,
141141
const std::string &source,
142142
const std::vector<std::string> &sourceColumns,
143143
bool allSourceColumns,
@@ -147,7 +147,7 @@ uint LayerDefinition::addLayer(string name, uint minzoom, uint maxzoom,
147147

148148
bool isWriteTo = !writeTo.empty();
149149
LayerDef layer = { name, minzoom, maxzoom, simplifyBelow, simplifyLevel, simplifyLength, simplifyRatio, simplifyAlgo,
150-
filterBelow, filterArea, combinePolygonsBelow, sortZOrderAscending, featureLimit, featureLimitBelow, combinePoints,
150+
filterBelow, filterArea, combinePolygonsBelow, sortZOrderAscending, featureLimit, featureLimitBelow, combinePoints, combineLinesBelow,
151151
source, sourceColumns, allSourceColumns, indexed, indexName,
152152
std::map<std::string,uint>(), isWriteTo };
153153
layers.push_back(layer);
@@ -318,6 +318,10 @@ void Config::readConfig(rapidjson::Document &jsonConfig, bool &hasClippingBox, B
318318
int featureLimit = it->value.HasMember("feature_limit" ) ? it->value["feature_limit" ].GetInt() : 0;
319319
int featureLimitBelow= it->value.HasMember("feature_limit_below") ? it->value["feature_limit_below"].GetInt() : (maxZoom+1);
320320
bool combinePoints = it->value.HasMember("combine_points" ) ? it->value["combine_points" ].GetBool() : true;
321+
// test with forced value : not working either
322+
int combineLinesBelow = 14;
323+
// expected final version using value defined in each layer (and default value defined in settings)
324+
//int combineLinesBelow = it->value.HasMember("combine_below" ) ? it->value["combine_below" ].GetInt() : combineBelow;
321325
bool sortZOrderAscending = it->value.HasMember("z_order_ascending") ? it->value["z_order_ascending"].GetBool() : (featureLimit==0);
322326
string algo = it->value.HasMember("simplify_algorithm") ? it->value["simplify_algorithm"].GetString() : "";
323327
uint simplifyAlgo = algo=="visvalingam" ? LayerDef::VISVALINGAM : LayerDef::DOUGLAS_PEUCKER;
@@ -340,7 +344,7 @@ void Config::readConfig(rapidjson::Document &jsonConfig, bool &hasClippingBox, B
340344

341345
layers.addLayer(layerName, minZoom, maxZoom,
342346
simplifyBelow, simplifyLevel, simplifyLength, simplifyRatio, simplifyAlgo,
343-
filterBelow, filterArea, combinePolyBelow, sortZOrderAscending, featureLimit, featureLimitBelow, combinePoints,
347+
filterBelow, filterArea, combinePolyBelow, sortZOrderAscending, featureLimit, featureLimitBelow, combinePoints, combineLinesBelow,
344348
source, sourceColumns, allSourceColumns, indexed, indexName,
345349
writeTo);
346350

src/tile_worker.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,13 @@ void ProcessObjects(
277277
double simplifyLevel,
278278
unsigned simplifyAlgo,
279279
double filterArea,
280-
bool combinePolygons,
281280
bool combinePoints,
281+
bool combineLines,
282+
bool combinePolygons,
282283
unsigned zoom,
283284
const TileBbox &bbox,
284285
vtzero::layer_builder& vtLayer
285286
) {
286-
287287
for (auto jt = ooSameLayerBegin; jt != ooSameLayerEnd; ++jt) {
288288
OutputObjectID oo = *jt;
289289
if (zoom < oo.oo.minZoom) { continue; }
@@ -330,7 +330,7 @@ void ProcessObjects(
330330
}
331331

332332
//This may increment the jt iterator
333-
if (oo.oo.geomType == LINESTRING_ && zoom < sharedData.config.combineBelow) {
333+
if (oo.oo.geomType == LINESTRING_ && combineLines) {
334334
// Append successive linestrings, then reorder afterwards
335335
while (jt<(ooSameLayerEnd-1) && oo.oo.compatible((jt+1)->oo)) {
336336
jt++;
@@ -440,7 +440,13 @@ void ProcessLayer(
440440
if (zoom < ld.filterBelow) {
441441
filterArea = meter2degp(ld.filterArea, latp) * pow(2.0, (ld.filterBelow-1) - zoom);
442442
}
443-
443+
// verbose for test
444+
if (ld.combineLinesBelow > 0) {
445+
std::cout << "Layer " << layerName << " at " << zoom << "/ combine lines below " << ld.combineLinesBelow << std::endl;
446+
}
447+
if (ld.combinePolygonsBelow > 0) {
448+
std::cout << "Layer " << layerName << " at " << zoom << "/ combine polygons below " << ld.combinePolygonsBelow << std::endl;
449+
}
444450
for (size_t i=0; i<sources.size(); i++) {
445451
// Loop through output objects
446452
auto ooListSameLayer = getObjectsAtSubLayer(data[i], layerNum);
@@ -449,7 +455,7 @@ void ProcessLayer(
449455
ProcessObjects(sources[i], attributeStore,
450456
ooListSameLayer.first, end, sharedData,
451457
simplifyLevel, ld.simplifyAlgo,
452-
filterArea, zoom < ld.combinePolygonsBelow, ld.combinePoints, zoom, bbox, vtLayer);
458+
filterArea, ld.combinePoints, zoom < ld.combineLinesBelow, zoom < ld.combinePolygonsBelow, zoom, bbox, vtLayer);
453459
}
454460
}
455461
if (verbose && std::time(0)-start>3) {

0 commit comments

Comments
 (0)