Skip to content

Commit

Permalink
Merges compatible points into multipoints, closes systemed#719
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-j-h committed May 25, 2024
1 parent b89b0eb commit a246a01
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/tile_worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,38 @@ void ProcessObjects(
OutputObjectID oo = *jt;
if (zoom < oo.oo.minZoom) { continue; }

if (oo.oo.geomType == POINT_) {
if (oo.oo.geomType == POINT_) {
// The very first point; below we check if there are more compatible points
// so that we can write a multipoint instead of many point features

std::vector<std::pair<int, int>> multipoint;

LatpLon pos = source->buildNodeGeometry(jt->oo.objectID, bbox);
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)) {
jt++;
LatpLon pos = source->buildNodeGeometry(jt->oo.objectID, bbox);
pair<int,int> xy = bbox.scaleLatpLon(pos.latp/10000000.0, pos.lon/10000000.0);
multipoint.push_back(xy);
}

vtzero::point_feature_builder fbuilder{vtLayer};
if (sharedData.config.includeID && oo.id) fbuilder.set_id(oo.id);

LatpLon pos = source->buildNodeGeometry(oo.oo.objectID, bbox);
pair<int,int> xy = bbox.scaleLatpLon(pos.latp/10000000.0, pos.lon/10000000.0);
fbuilder.add_point(xy.first, xy.second);
fbuilder.add_points(multipoint.size());

if (verbose && multipoint.size() > 1)
std::cout << "Merging " << multipoint.size() << " points into a multipoint" << std::endl;

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

oo.oo.writeAttributes(attributeStore, fbuilder, zoom);
fbuilder.commit();

oo = *jt;
} else {
Geometry g;
try {
Expand Down

0 comments on commit a246a01

Please sign in to comment.