Skip to content

Commit 3dde4d5

Browse files
authored
Added a spatial index to the overlayng polygonbuilder (#1379)
* added a spatial index to the overlayng polygonbuilder * Updated spelling. * reuse spatial filter result vector
1 parent 3b39127 commit 3dde4d5

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/operation/overlayng/PolygonBuilder.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,21 @@ PolygonBuilder::assignHoles(OverlayEdgeRing* shell, const std::vector<OverlayEdg
168168
void
169169
PolygonBuilder::placeFreeHoles(const std::vector<OverlayEdgeRing*>& shells, const std::vector<OverlayEdgeRing*> & freeHoles) const
170170
{
171-
// TODO: use a spatial index to improve performance
171+
// build spatial index
172+
index::strtree::TemplateSTRtree<OverlayEdgeRing*> index;
173+
for (auto& shell : shells) {
174+
index.insert(*shell->getRingPtr()->getEnvelopeInternal(), shell);
175+
}
176+
177+
std::vector<OverlayEdgeRing*> shellListOverlaps;
172178
for (OverlayEdgeRing* hole : freeHoles) {
173179
// only place this hole if it doesn't yet have a shell
174180
if (hole->getShell() == nullptr) {
175-
OverlayEdgeRing* shell = hole->findEdgeRingContaining(shells);
181+
// get list of overlapping shells
182+
shellListOverlaps.clear();
183+
index.query(*hole->getRingPtr()->getEnvelopeInternal(), shellListOverlaps);
184+
185+
OverlayEdgeRing* shell = hole->findEdgeRingContaining(shellListOverlaps);
176186
// only when building a polygon-valid result
177187
if (isEnforcePolygonal && shell == nullptr) {
178188
throw util::TopologyException("unable to assign free hole to a shell", hole->getCoordinate());

0 commit comments

Comments
 (0)