@Test public void testTurfPointOnLinePointsOnTopOfLine() throws TurfException { List<Point> line = new ArrayList<>(); line.add(Point.fromLngLat(-0.10919809341430663, 51.52204224896724)); line.add(Point.fromLngLat(-0.10923027992248535, 51.521942114455435)); line.add(Point.fromLngLat(-0.10916590690612793, 51.52186200668747)); line.add(Point.fromLngLat(-0.10904788970947266, 51.52177522311313)); line.add(Point.fromLngLat(-0.10886549949645996, 51.521601655468345)); line.add(Point.fromLngLat(-0.10874748229980469, 51.52138135712038)); line.add(Point.fromLngLat(-0.10855436325073242, 51.5206870765674)); line.add(Point.fromLngLat(-0.10843634605407713, 51.52027984939518)); line.add(Point.fromLngLat(-0.10839343070983887, 51.519952729849024)); line.add(Point.fromLngLat(-0.10817885398864746, 51.51957887606202)); line.add(Point.fromLngLat(-0.10814666748046874, 51.51928513164789)); line.add(Point.fromLngLat(-0.10789990425109863, 51.518624199789016)); line.add(Point.fromLngLat(-0.10759949684143065, 51.51778299991493)); double dist = TurfMeasurement.length(LineString.fromLngLats(line), TurfConstants.UNIT_MILES); double increment = dist / 10; for (int i = 0; i < 10; i++) { Point pt = TurfMeasurement.along( LineString.fromLngLats(line), increment * i, TurfConstants.UNIT_MILES); Feature snappedFeature = TurfMisc.nearestPointOnLine(pt, line); Point snapped = (Point) snappedFeature.geometry(); double shift = TurfMeasurement.distance(pt, snapped, TurfConstants.UNIT_MILES); assertTrue(shift < 0.000001); } }
@NonNull public static Feature nearestPointOnLine(@NonNull Point pt, @NonNull List<Point> coords) { return nearestPointOnLine(pt, coords, null); }
TurfMisc { @NonNull public static Feature nearestPointOnLine(@NonNull Point pt, @NonNull List<Point> coords) { return nearestPointOnLine(pt, coords, null); } }
TurfMisc { @NonNull public static Feature nearestPointOnLine(@NonNull Point pt, @NonNull List<Point> coords) { return nearestPointOnLine(pt, coords, null); } private  TurfMisc(); }
TurfMisc { @NonNull public static Feature nearestPointOnLine(@NonNull Point pt, @NonNull List<Point> coords) { return nearestPointOnLine(pt, coords, null); } private  TurfMisc(); @NonNull static LineString lineSlice(@NonNull Point startPt, @NonNull Point stopPt,
                                     @NonNull Feature line); @NonNull static LineString lineSlice(@NonNull Point startPt, @NonNull Point stopPt,
                                     @NonNull LineString line); @NonNull static LineString lineSliceAlong(@NonNull Feature line,
                                          @FloatRange(from = 0) double startDist,
                                          @FloatRange(from = 0) double stopDist,
                                          @NonNull @TurfConstants.TurfUnitCriteria String units); @NonNull static LineString lineSliceAlong(@NonNull LineString line,
                                          @FloatRange(from = 0) double startDist,
                                          @FloatRange(from = 0) double stopDist,
                                          @NonNull @TurfConstants.TurfUnitCriteria String units); @NonNull static Feature nearestPointOnLine(@NonNull Point pt, @NonNull List<Point> coords); @NonNull static Feature nearestPointOnLine(@NonNull Point pt, @NonNull List<Point> coords,
                                           @Nullable @TurfConstants.TurfUnitCriteria String units); }
TurfMisc { @NonNull public static Feature nearestPointOnLine(@NonNull Point pt, @NonNull List<Point> coords) { return nearestPointOnLine(pt, coords, null); } private  TurfMisc(); @NonNull static LineString lineSlice(@NonNull Point startPt, @NonNull Point stopPt,
                                     @NonNull Feature line); @NonNull static LineString lineSlice(@NonNull Point startPt, @NonNull Point stopPt,
                                     @NonNull LineString line); @NonNull static LineString lineSliceAlong(@NonNull Feature line,
                                          @FloatRange(from = 0) double startDist,
                                          @FloatRange(from = 0) double stopDist,
                                          @NonNull @TurfConstants.TurfUnitCriteria String units); @NonNull static LineString lineSliceAlong(@NonNull LineString line,
                                          @FloatRange(from = 0) double startDist,
                                          @FloatRange(from = 0) double stopDist,
                                          @NonNull @TurfConstants.TurfUnitCriteria String units); @NonNull static Feature nearestPointOnLine(@NonNull Point pt, @NonNull List<Point> coords); @NonNull static Feature nearestPointOnLine(@NonNull Point pt, @NonNull List<Point> coords,
                                           @Nullable @TurfConstants.TurfUnitCriteria String units);  }