Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] Add only the outer polygon ring geometry to the feature index
Browse files Browse the repository at this point in the history
  • Loading branch information
pozdnyakov committed Jun 10, 2019
1 parent 774d320 commit 04012e4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
13 changes: 5 additions & 8 deletions src/mbgl/geometry/feature_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@ FeatureIndex::FeatureIndex(std::unique_ptr<const GeometryTileData> tileData_)

void FeatureIndex::insert(const GeometryCollection& geometries,
std::size_t index,
FeatureType featureType,
const std::string& sourceLayerName,
const std::string& bucketLeaderID) {
auto featureSortIndex = sortIndex++;
for (const auto& ring : geometries) {
auto envelope = mapbox::geometry::envelope(ring);
if (envelope.min.x < util::EXTENT &&
envelope.min.y < util::EXTENT &&
envelope.max.x >= 0 &&
envelope.max.y >= 0) {
grid.insert(IndexedSubfeature(index, sourceLayerName, bucketLeaderID, featureSortIndex++),
grid.insert(IndexedSubfeature(index, sourceLayerName, bucketLeaderID, sortIndex++),
{convertPoint<float>(envelope.min), convertPoint<float>(envelope.max)});
if (featureType == FeatureType::Polygon) {
break; // Add only the first geometry as it contains outer polygon ring.
}
}
}
}
Expand Down Expand Up @@ -67,13 +70,7 @@ void FeatureIndex::query(
std::sort(features.begin(), features.end(), [](const IndexedSubfeature& a, const IndexedSubfeature& b) {
return a.sortIndex > b.sortIndex;
});
size_t previousSortIndex = std::numeric_limits<size_t>::max();
for (const auto& indexedFeature : features) {

// If this feature is the same as the previous feature, skip it.
if (indexedFeature.sortIndex == previousSortIndex) continue;
previousSortIndex = indexedFeature.sortIndex;

addFeature(result, indexedFeature, queryOptions, tileID.canonical, layers, queryGeometry, transformState, pixelsToTileUnits, posMatrix);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/geometry/feature_index.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class FeatureIndex {

const GeometryTileData* getData() { return tileData.get(); }

void insert(const GeometryCollection&, std::size_t index, const std::string& sourceLayerName, const std::string& bucketLeaderID);
void insert(const GeometryCollection&, std::size_t index, FeatureType, const std::string& sourceLayerName, const std::string& bucketLeaderID);

void query(
std::unordered_map<std::string, std::vector<Feature>>& result,
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/layout/pattern_layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class PatternLayout : public Layout {
GeometryCollection geometries = feature->getGeometries();

bucket->addFeature(*feature, geometries, patternPositions, patterns);
featureIndex->insert(geometries, i, sourceLayerID, bucketLeaderID);
featureIndex->insert(geometries, i, feature->getType(), sourceLayerID, bucketLeaderID);
}
if (bucket->hasData()) {
for (const auto& pair : layerPropertiesMap) {
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/tile/geometry_tile_worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ void GeometryTileWorker::parse() {

GeometryCollection geometries = feature->getGeometries();
bucket->addFeature(*feature, geometries, {}, PatternLayerMap ());
featureIndex->insert(geometries, i, sourceLayerID, leaderImpl.id);
featureIndex->insert(geometries, i, feature->getType(), sourceLayerID, leaderImpl.id);
}

if (!bucket->hasData()) {
Expand Down

0 comments on commit 04012e4

Please sign in to comment.