3636#include " ShapefileReader.hpp"
3737#include " poly_math.h"
3838#include " ocpndc.h"
39+ #include " spatial_rtree.h"
3940
4041#if (defined(OCPN_GHC_FILESYSTEM) || \
4142 (defined (__clang_major__) && (__clang_major__ < 15 )))
@@ -143,6 +144,7 @@ class ShapeBaseChart {
143144 _min_scale(min_scale),
144145 _filename(filename),
145146 _reader(nullptr ),
147+ _rtree(nullptr ),
146148 _color(color) {
147149 _is_usable = fs::exists (filename);
148150 }
@@ -153,13 +155,16 @@ class ShapeBaseChart {
153155 this ->_is_tiled = t._is_tiled ;
154156 this ->_min_scale = t._min_scale ;
155157 this ->_reader = nullptr ;
158+ this ->_rtree = nullptr ; // Will be recreated when LoadSHP() is called
156159 this ->_color = t._color ;
157160 this ->_dmod = t._dmod ;
158161 this ->_loading = t._loading ;
159162 }
160163 ~ShapeBaseChart () {
161164 CancelLoading (); // Ensure async operation is done before cleanup.
162165 delete _reader;
166+ // _rtree is managed by a std::unique_ptr so it will be automatically
167+ // cleaned up
163168 }
164169
165170 void SetColor (wxColor color) { _color = color; }
@@ -263,6 +268,12 @@ class ShapeBaseChart {
263268 * for efficient spatial queries.
264269 */
265270 std::unordered_map<LatLonKey, std::vector<size_t >> _tiles;
271+ /* *
272+ * R-tree spatial index for efficient spatial queries. Provides logarithmic
273+ * search time for finding features that intersect with a given bounding box
274+ * or line segment. Built during LoadSHP() and used by CrossesLand().
275+ */
276+ std::unique_ptr<RTree> _rtree;
266277 /* *
267278 * The color used for rendering land areas in this specific chart instance.
268279 * Initially set during construction from the parent ShapeBaseChartSet's
0 commit comments