I have a set of features (a few hundreds, can grow to a couple of thousands), which have a latitude and longitude. They are not stored in a database because they change frequently (another system is keeping track of them and feeding them to systems including the one in question).
I want to just keep them in memory because the information is very volatile (the objects will be moving on the map).
What is the best Java API I can use to query the closest N
features of a certain type to a specific point?
I was looking at either JTS or GeoTools (which uses JTS under the hood), but couldn't find any examples of "find the nearest N features" (maybe I was looking at the wrong thing or searched with the wrong keywords).
JTS seems to have a KDTree
that I gather is an efficient data structure for what I need? But no idea how to go from there.
The answer to Finding N nearest points to point using JTS? seems to indicate that more work is needed to do it, but there surely must be a way to do it from the APIs available that I am just missing, because this is such a common requirement (closest restaurants, closest ATMs etc.).