@Test public void testShortLine() throws IOException, TurfException { LineString lineStringLine1 = LineString.fromLngLats(Arrays.asList( Point.fromLngLat(113.99414062499999, 22.350075806124867), Point.fromLngLat(116.76269531249999, 23.241346102386135))); double start = 50; double stop = 100; Point start_point = TurfMeasurement.along(lineStringLine1, start, TurfConstants.UNIT_MILES); Point end_point = TurfMeasurement.along(lineStringLine1, stop, TurfConstants.UNIT_MILES); LineString sliced = TurfMisc.lineSliceAlong(lineStringLine1, start, stop, TurfConstants.UNIT_MILES); assertEquals(sliced.coordinates().get(0).coordinates(), start_point.coordinates()); assertEquals(sliced.coordinates().get(sliced.coordinates().size() - 1).coordinates(), end_point.coordinates()); }
@NonNull public static LineString lineSliceAlong(@NonNull Feature line, @FloatRange(from = 0) double startDist, @FloatRange(from = 0) double stopDist, @NonNull @TurfConstants.TurfUnitCriteria String units) { if (line.geometry() == null) { throw new NullPointerException("Feature.geometry() == null"); } if (!line.geometry().type().equals("LineString")) { throw new TurfException("input must be a LineString Feature or Geometry"); } return lineSliceAlong((LineString)line.geometry(), startDist, stopDist, units); }
TurfMisc { @NonNull public static LineString lineSliceAlong(@NonNull Feature line, @FloatRange(from = 0) double startDist, @FloatRange(from = 0) double stopDist, @NonNull @TurfConstants.TurfUnitCriteria String units) { if (line.geometry() == null) { throw new NullPointerException("Feature.geometry() == null"); } if (!line.geometry().type().equals("LineString")) { throw new TurfException("input must be a LineString Feature or Geometry"); } return lineSliceAlong((LineString)line.geometry(), startDist, stopDist, units); } }
TurfMisc { @NonNull public static LineString lineSliceAlong(@NonNull Feature line, @FloatRange(from = 0) double startDist, @FloatRange(from = 0) double stopDist, @NonNull @TurfConstants.TurfUnitCriteria String units) { if (line.geometry() == null) { throw new NullPointerException("Feature.geometry() == null"); } if (!line.geometry().type().equals("LineString")) { throw new TurfException("input must be a LineString Feature or Geometry"); } return lineSliceAlong((LineString)line.geometry(), startDist, stopDist, units); } private  TurfMisc(); }
TurfMisc { @NonNull public static LineString lineSliceAlong(@NonNull Feature line, @FloatRange(from = 0) double startDist, @FloatRange(from = 0) double stopDist, @NonNull @TurfConstants.TurfUnitCriteria String units) { if (line.geometry() == null) { throw new NullPointerException("Feature.geometry() == null"); } if (!line.geometry().type().equals("LineString")) { throw new TurfException("input must be a LineString Feature or Geometry"); } return lineSliceAlong((LineString)line.geometry(), startDist, stopDist, units); } 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 LineString lineSliceAlong(@NonNull Feature line, @FloatRange(from = 0) double startDist, @FloatRange(from = 0) double stopDist, @NonNull @TurfConstants.TurfUnitCriteria String units) { if (line.geometry() == null) { throw new NullPointerException("Feature.geometry() == null"); } if (!line.geometry().type().equals("LineString")) { throw new TurfException("input must be a LineString Feature or Geometry"); } return lineSliceAlong((LineString)line.geometry(), startDist, stopDist, units); } 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);  }