How quadtree searching works in Shapelib
masterSearching the quadtree is a multi-stage process designed to balance speed and accuracy. The SHPTreeFindLikelyShapes() function in shptree.c implements the first stage.
- Phase 1: Quadtree Traversal: The algorithm traverses the quadtree and collects
shapeidsfrom every node whose bounding rectangle overlaps the search rectangle. This stage is fast but can produce "false positives" because a shape's actual bounding box is often much smaller than its containing quadtree node. - Phase 2: Shape Verification: The actual shapes are fetched, and their specific bounding boxes are checked against the search area to filter out the false positives from Phase 1.
- Phase 3 (Optional/Manual): A third phase can be implemented to verify if actual line segments within a shape cross the area of interest, though this is typically handled by drawing engines via clipping.