spatial icon indicating copy to clipboard operation
spatial copied to clipboard

startNearestNeighborLatLonSearch() returns zero results when using numItemsToFind

Open mpeniak opened this issue 10 years ago • 3 comments

Using the same database, this works fine:

double maxDistanceInKm = 1.0; List<SpatialDatabaseRecord> results = GeoPipeline.startNearestNeighborLatLonSearch(layer, new Coordinate(51.502692, -0.240081), maxDistanceInKm)�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������.toSpatialDatabaseRecordList();���������������������������������

and returns around 70 nodes but this does not return anything:

int numItemsToFind = 10; List<SpatialDatabaseRecord> results = GeoPipeline.startNearestNeighborLatLonSearch(layer, new Coordinate(51.502692, -0.240081), numItemsToFind).toSpatialDatabaseRecordList();��������������������������������

mpeniak avatar Nov 16 '15 11:11 mpeniak

This problem is documented in the Javadoc: The numItemsToFind parameter is used to calculate an Envelope based on the overall average layer density, so it's normal that this version returns no items, especially when the layer density decreases when coming nearer to the point (and thus, the chance that an Envelope with certain boundaries on that particular position will contain much less items than usual is higher).

ehx-v1 avatar Jun 06 '16 11:06 ehx-v1

So it's a known inconvenience, and none anyone is likely to do anything about (it's a downside of the implementation that made most sense), one just has to deal with it.

ehx-v1 avatar Jun 06 '16 12:06 ehx-v1

The workaround is to keep increasing the number of items until you do get hits. That could also be encoded into the algorithm (automatically increment estimated search window if too few items are found).

craigtaverner avatar Jun 06 '16 16:06 craigtaverner