I gave a talk at the Italian C++ Community where I explain how spatial indices work, when they are useful, and the code I wrote.
Link to the video on youtube: link
mkdir build && cd build
cmake ..
cmake --build .
If you have installed the dependency libraries in a non-standard path, you must specify the path before building with:
cmake .. -DGEOS_PATH:PATH=<your_path_to_geos>
cmake .. -DSHAPELIB_PATH:PATH=<your_path_to_shapelib>
cmake .. -DCLI_PATH:PATH=<your_path_to_cli>
I created a CLI with several commands:
-
help
Displays the list of commands and how to use them. -
load [file.shp]
Reads a shapefile containing geometries and saves them in memory. -
build [kd-tree|quad-tree|r-tree|geohash]
Builds the specified data structure with the previously loaded geometries. -
search_range [kd-tree|quad-tree|r-tree|geohash] --x1 --y1 --x2 --y2
Performs a query on the specified data structure using the rectangle defined by the given coordinates. -
search_range [kd-tree|quad-tree|r-tree|geohash]
Performs a query on the specified data structure using a randomly generated rectangle. -
compare <iterations>
Performs n queries on the already built data structures and prints the times. -
compare --x1 --y1 --x2 --y2
Performs a query on the already built data structures using the rectangle defined by the given coordinates and prints the times.