So for this application each of the N-groups are all pretty localized and N is a large number, so I think I could keep each group in a group-r-tree and then keep each group-r-tree in an overarching-r-tree (with things like indexable and compariable_distance for a group-r-tree and a point overloaded to give the distance between the closest object in the r-tree to the point). If I did that, I could run a nearest neighbor search on the overarching-r-tree and get the k closest group-r-tree's, but then in order to get the objects in each group-r-tree, I'd have to run another nearest neighbor search on the group-r-tree. Is there a good way around that repeated computation?
If that doesn't work, I might just put all of the objects in a single r-tree and get all or the objects withing a certain range (using something like the intersects query) and then process those items to get what I want, and then just live with the fact that fewer than k groups might intersect a range, so it would be a find the nearest k-or-less neighbors with at most one in each group query.
Adam