Skip to content

Commit

Permalink
split geometry collections into separate features (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
mourner committed Jul 6, 2016
1 parent 002889b commit fc0717c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 37 deletions.
13 changes: 1 addition & 12 deletions include/mapbox/geojsonvt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,7 @@ struct ToFeatureCollection {
return { value };
}
feature_collection operator()(const geometry& value) const {
if (value.is<geometry_collection>()) {
geometry_collection collection = std::move(value.get<geometry_collection>());
feature_collection features;
features.reserve(collection.size());
for (const auto& geom : collection) {
feature feat{ geom };
features.emplace_back(std::move(feat));
}
return features;
} else {
return { { value } };
}
return { { value } };
}
};

Expand Down
51 changes: 26 additions & 25 deletions include/mapbox/geojsonvt/tile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class InternalTile {

vt_geometry::visit(geom, [&](const auto& g) {
// `this->` is a workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61636
this->addFeature(this->transform(g), props);
this->addFeature(g, props);
});

bbox.min.x = std::min(feature.bbox.min.x, bbox.min.x);
Expand Down Expand Up @@ -93,30 +93,43 @@ class InternalTile {
return true;
}

void addFeature(geometry::point<int16_t>&& point, const property_map& props) {
tile.features.push_back({ std::move(point), props });
void addFeature(const vt_point& point, const property_map& props) {
tile.features.push_back({ transform(point), props });
}

void addFeature(geometry::line_string<int16_t>&& line, const property_map& props) {
if (!line.empty())
tile.features.push_back({ std::move(line), props });
void addFeature(const vt_line_string& line, const property_map& props) {
const auto new_line = transform(line);
if (!new_line.empty())
tile.features.push_back({ std::move(new_line), props });
}

void addFeature(geometry::polygon<int16_t>&& polygon, const property_map& props) {
if (!polygon.empty())
tile.features.push_back({ std::move(polygon), props });
void addFeature(const vt_polygon& polygon, const property_map& props) {
const auto new_polygon = transform(polygon);
if (!new_polygon.empty())
tile.features.push_back({ std::move(new_polygon), props });
}

void addFeature(const vt_geometry_collection& collection, const property_map& props) {
for (const auto& geom : collection) {
vt_geometry::visit(geom, [&](const auto& g) {
// `this->` is a workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61636
this->addFeature(g, props);
});
}
}

template <class T>
void addFeature(T&& multi, const property_map& props) {
switch (multi.size()) {
void addFeature(const T& multi, const property_map& props) {
const auto new_multi = transform(multi);

switch (new_multi.size()) {
case 0:
break;
case 1:
tile.features.push_back({ std::move(multi[0]), props });
tile.features.push_back({ std::move(new_multi[0]), props });
break;
default:
tile.features.push_back({ std::move(multi), props });
tile.features.push_back({ std::move(new_multi), props });
break;
}
}
Expand Down Expand Up @@ -185,18 +198,6 @@ class InternalTile {
}
return result;
}

mapbox::geometry::geometry_collection<int16_t>
transform(const vt_geometry_collection& geometries) {
mapbox::geometry::geometry_collection<int16_t> result;
for (const auto& geometry : geometries) {
vt_geometry::visit(geometry, [&](const auto& g) {
// `this->` is a workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61636
result.push_back(this->transform(g));
});
}
return result;
}
};

} // namespace detail
Expand Down

0 comments on commit fc0717c

Please sign in to comment.