Skip to content

Commit

Permalink
Merge pull request OSGeo#2284 from bjornharrtell/fgb-spat-fid-fix
Browse files Browse the repository at this point in the history
FlatGeobuf: Fix FID stability on spatial searches
  • Loading branch information
rouault authored Feb 29, 2020
2 parents 765782a + a82f5b5 commit 7c8c895
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions gdal/ogr/ogrsf_frmts/flatgeobuf/packedrtree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ PackedRTree::PackedRTree(const void *data, const uint64_t numItems, const uint16

std::vector<SearchResultItem> PackedRTree::search(double minX, double minY, double maxX, double maxY) const
{
uint64_t leafNodesOffset = _levelBounds.front().first;
NodeItem n { minX, minY, maxX, maxY, 0 };
std::vector<SearchResultItem> results;
std::unordered_map<uint64_t, uint64_t> queue;
Expand All @@ -270,7 +271,7 @@ std::vector<SearchResultItem> PackedRTree::search(double minX, double minY, doub
if (!n.intersects(nodeItem))
continue;
if (isLeafNode)
results.push_back({ nodeItem.offset, pos - 1 });
results.push_back({ nodeItem.offset, pos - leafNodesOffset });
else
queue.insert(std::pair<uint64_t, uint64_t>(nodeItem.offset, level - 1));
}
Expand All @@ -283,6 +284,7 @@ std::vector<SearchResultItem> PackedRTree::streamSearch(
const std::function<void(uint8_t *, size_t, size_t)> &readNode)
{
auto levelBounds = generateLevelBounds(numItems, nodeSize);
uint64_t leafNodesOffset = levelBounds.front().first;
uint64_t numNodes = levelBounds.front().second;
std::vector<NodeItem> nodeItems;
nodeItems.reserve(nodeSize);
Expand Down Expand Up @@ -318,7 +320,7 @@ std::vector<SearchResultItem> PackedRTree::streamSearch(
if (!item.intersects(nodeItem))
continue;
if (isLeafNode)
results.push_back({ nodeItem.offset, pos - 1 });
results.push_back({ nodeItem.offset, pos - leafNodesOffset });
else
queue.insert(std::pair<uint64_t, uint64_t>(nodeItem.offset, level - 1));
}
Expand Down

0 comments on commit 7c8c895

Please sign in to comment.