TurfClassification { @NonNull public static Point nearestPoint(@NonNull Point targetPoint, @NonNull List<Point> points) { if (points.isEmpty()) { return targetPoint; } Point nearestPoint = points.get(0); double minDist = Double.POSITIVE_INFINITY; for (Point point : points) { double distanceToPoint = TurfMeasurement.distance(targetPoint, point); if (distanceToPoint < minDist) { nearestPoint = point; minDist = distanceToPoint; } } return nearestPoint; } private  TurfClassification(); @NonNull static Point nearestPoint(@NonNull Point targetPoint, @NonNull List<Point> points);  }
@Test public void testLineDistanceWithGeometries() throws IOException, TurfException { Point pt = (Point) Feature.fromJson(loadJsonFixture(PT)).geometry(); FeatureCollection pts = FeatureCollection.fromJson(loadJsonFixture(PTS)); List<Point> pointList = new ArrayList<>(); for (Feature feature : pts.features()) { pointList.add((Point) (feature.geometry())); } Point closestPt = TurfClassification.nearestPoint(pt, pointList); Assert.assertNotNull(closestPt); Assert.assertEquals(closestPt.type(), "Point"); Assert.assertEquals(closestPt.longitude(), -75.33, DELTA); Assert.assertEquals(closestPt.latitude(), 39.44, DELTA); }