NearestFeaturesFilter implements IFeatureFilterVisitor { @NonNull public static List<Feature> getFilteredFeatures(@NonNull final GeoPoint geoPoint, double maxDistance, @NonNull final List<Feature> features) { final NearestFeaturesFilter nearestFeaturesFilter = new NearestFeaturesFilter(geoPoint, maxDistance); for (Feature feature : features) { feature.apply(nearestFeaturesFilter); } return nearestFeaturesFilter.getFilteredFeatures(); } NearestFeaturesFilter(@NonNull final GeoPoint geoPoint,
                                 double maxDistance); @NonNull static List<Feature> getFilteredFeatures(@NonNull final GeoPoint geoPoint,
                                                    double maxDistance,
                                                    @NonNull final List<Feature> features); @NonNull static List<Feature> getFilteredFeatures(@NonNull final GeoPoint geoPoint,
                                                    double maxDistance,
                                                    @NonNull final FeatureCollection featureCollection); @Override void filter(@NonNull Feature feature); @NonNull List<Feature> getFilteredFeatures();  }
@Test public void testNearestFeaturesFromFeatures() throws Exception { final GeoPoint geoPoint = new GeoPoint(47.225782d, -1.554476d); final List<Feature> features = asList(new Feature("id1", createPoint(gf, 47.226468d, -1.554996d)), new Feature("id2", createPoint(gf, 47.226126d, -1.554381d))); final List<Feature> filteredFeatures = getFilteredFeatures(geoPoint, 45d, features); assertNotNull(filteredFeatures); assertEquals(1, filteredFeatures.size()); assertEquals(features.get(1), filteredFeatures.get(0)); }
@Test public void testNearestFeaturesFromFeatureCollection() throws Exception { final GeoPoint geoPoint = new GeoPoint(47.225782d, -1.554476); final FeatureCollection featureCollection = new FeatureCollection(); featureCollection.addFeature(new Feature("id1", createPoint(gf, 47.226468d, -1.554996d))); featureCollection.addFeature(new Feature("id2", createPoint(gf, 47.226126d, -1.554381d))); final List<Feature> filteredFeatures = getFilteredFeatures(geoPoint, 45d, featureCollection); assertNotNull(filteredFeatures); assertEquals(1, filteredFeatures.size()); assertEquals(featureCollection.getFeature("id2"), filteredFeatures.get(0)); }