Skip to content

Add per-layer ability to disable multipoints #771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ You can add optional parameters to layers:
* `feature_limit` - restrict the number of features written to each tile
* `feature_limit_below` - restrict only below this zoom level
* `combine_polygons_below` - merge adjacent polygons with the same attributes below this zoom level
* `combine_points` - merge points with the same attributes (defaults to `true`: specify `false` to disable)
* `z_order_ascending` - sort features in ascending order by a numeric value set in the Lua processing script (defaults to `true`: specify `false` for descending order)

`write_to` enables you to combine different layer specs within one outputted layer. For example:
Expand Down
3 changes: 2 additions & 1 deletion include/shared_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct LayerDef {
bool sortZOrderAscending;
uint featureLimit;
uint featureLimitBelow;
bool combinePoints;
std::string source;
std::vector<std::string> sourceColumns;
bool allSourceColumns;
Expand All @@ -54,7 +55,7 @@ class LayerDefinition {
uint addLayer(std::string name, uint minzoom, uint maxzoom,
uint simplifyBelow, double simplifyLevel, double simplifyLength, double simplifyRatio,
uint filterBelow, double filterArea, uint combinePolygonsBelow, bool sortZOrderAscending,
uint featureLimit, uint featureLimitBelow,
uint featureLimit, uint featureLimitBelow, bool combinePoints,
const std::string &source,
const std::vector<std::string> &sourceColumns,
bool allSourceColumns,
Expand Down
7 changes: 4 additions & 3 deletions src/shared_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void SharedData::writePMTilesBounds() {
uint LayerDefinition::addLayer(string name, uint minzoom, uint maxzoom,
uint simplifyBelow, double simplifyLevel, double simplifyLength, double simplifyRatio,
uint filterBelow, double filterArea, uint combinePolygonsBelow, bool sortZOrderAscending,
uint featureLimit, uint featureLimitBelow,
uint featureLimit, uint featureLimitBelow, bool combinePoints,
const std::string &source,
const std::vector<std::string> &sourceColumns,
bool allSourceColumns,
Expand All @@ -147,7 +147,7 @@ uint LayerDefinition::addLayer(string name, uint minzoom, uint maxzoom,

bool isWriteTo = !writeTo.empty();
LayerDef layer = { name, minzoom, maxzoom, simplifyBelow, simplifyLevel, simplifyLength, simplifyRatio,
filterBelow, filterArea, combinePolygonsBelow, sortZOrderAscending, featureLimit, featureLimitBelow,
filterBelow, filterArea, combinePolygonsBelow, sortZOrderAscending, featureLimit, featureLimitBelow, combinePoints,
source, sourceColumns, allSourceColumns, indexed, indexName,
std::map<std::string,uint>(), isWriteTo };
layers.push_back(layer);
Expand Down Expand Up @@ -317,6 +317,7 @@ void Config::readConfig(rapidjson::Document &jsonConfig, bool &hasClippingBox, B
int combinePolyBelow=it->value.HasMember("combine_polygons_below") ? it->value["combine_polygons_below"].GetInt() : 0;
int featureLimit = it->value.HasMember("feature_limit" ) ? it->value["feature_limit" ].GetInt() : 0;
int featureLimitBelow= it->value.HasMember("feature_limit_below") ? it->value["feature_limit_below"].GetInt() : (maxZoom+1);
bool combinePoints = it->value.HasMember("combine_points" ) ? it->value["combine_points" ].GetBool() : true;
bool sortZOrderAscending = it->value.HasMember("z_order_ascending") ? it->value["z_order_ascending"].GetBool() : (featureLimit==0);
string source = it->value.HasMember("source") ? it->value["source"].GetString() : "";
vector<string> sourceColumns;
Expand All @@ -337,7 +338,7 @@ void Config::readConfig(rapidjson::Document &jsonConfig, bool &hasClippingBox, B

layers.addLayer(layerName, minZoom, maxZoom,
simplifyBelow, simplifyLevel, simplifyLength, simplifyRatio,
filterBelow, filterArea, combinePolyBelow, sortZOrderAscending, featureLimit, featureLimitBelow,
filterBelow, filterArea, combinePolyBelow, sortZOrderAscending, featureLimit, featureLimitBelow, combinePoints,
source, sourceColumns, allSourceColumns, indexed, indexName,
writeTo);

Expand Down
7 changes: 4 additions & 3 deletions src/tile_worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ void ProcessObjects(
double simplifyLevel,
double filterArea,
bool combinePolygons,
bool combinePoints,
unsigned zoom,
const TileBbox &bbox,
vtzero::layer_builder& vtLayer
Expand All @@ -285,7 +286,7 @@ void ProcessObjects(
pair<int,int> xy = bbox.scaleLatpLon(pos.latp/10000000.0, pos.lon/10000000.0);
multipoint.push_back(xy);

while (jt<(ooSameLayerEnd-1) && oo.oo.compatible((jt+1)->oo)) {
while (jt<(ooSameLayerEnd-1) && oo.oo.compatible((jt+1)->oo) && combinePoints) {
jt++;
LatpLon pos = source->buildNodeGeometry(jt->oo.objectID, bbox);
pair<int,int> xy = bbox.scaleLatpLon(pos.latp/10000000.0, pos.lon/10000000.0);
Expand All @@ -300,7 +301,7 @@ void ProcessObjects(
if (verbose && multipoint.size() > 1)
std::cout << "Merging " << multipoint.size() << " points into a multipoint" << std::endl;

for (const auto point : multipoint)
for (const auto &point : multipoint)
fbuilder.set_point(point.first, point.second);

oo.oo.writeAttributes(attributeStore, fbuilder, zoom);
Expand Down Expand Up @@ -435,7 +436,7 @@ void ProcessLayer(
if (ld.featureLimit>0 && end-ooListSameLayer.first>ld.featureLimit && zoom<ld.featureLimitBelow) end = ooListSameLayer.first+ld.featureLimit;
ProcessObjects(sources[i], attributeStore,
ooListSameLayer.first, end, sharedData,
simplifyLevel, filterArea, zoom < ld.combinePolygonsBelow, zoom, bbox, vtLayer);
simplifyLevel, filterArea, zoom < ld.combinePolygonsBelow, ld.combinePoints, zoom, bbox, vtLayer);
}
}
if (verbose && std::time(0)-start>3) {
Expand Down
Loading