I'm looking for an implementation of a spatial index that allows me to quickly count and sum up the values that are contained in a specified region.
The longer version: I have a lot of objects that I want to store in a spatial index. They each have their coordinates in the n-dimensional space as well as one extra value. Given a range I need a quick answer to the questions of (1) how many objects are within the range and (2) what is the sum of all their values.
I know that a spatial index is usually implemented using R-trees. Of course I could simply retrieve all the objects within a range and sum them up each time.
However, it seems like there is a significant speed up opportunity by storing the sum and count of all elements contained under a node within that very node. Thus, once the node in question is entirely within the queried range, it is not necessary to descend the tree any further.
Does anyone know a C++ implementation that supports these kind of "cached" operations?