TurfMeasurement { public static Point along(@NonNull LineString line, @FloatRange(from = 0) double distance, @NonNull @TurfConstants.TurfUnitCriteria String units) { return along(line.coordinates(), distance, units); } private  TurfMeasurement(); static double bearing(@NonNull Point point1, @NonNull Point point2); @NonNull static Point destination(@NonNull Point point, @FloatRange(from = 0) double distance,
                                  @FloatRange(from = -180, to = 180) double bearing,
                                  @NonNull @TurfConstants.TurfUnitCriteria String units); static double distance(@NonNull Point point1, @NonNull Point point2); static double distance(@NonNull Point point1, @NonNull Point point2,
                                @NonNull @TurfConstants.TurfUnitCriteria String units); static double length(@NonNull LineString lineString,
                              @NonNull @TurfConstants.TurfUnitCriteria String units); static double length(@NonNull MultiLineString multiLineString,
                              @NonNull @TurfConstants.TurfUnitCriteria String units); static double length(@NonNull Polygon polygon,
                              @NonNull @TurfConstants.TurfUnitCriteria String units); static double length(@NonNull MultiPolygon multiPolygon,
                              @NonNull @TurfConstants.TurfUnitCriteria String units); static double length(List<Point> coords, String units); static Point midpoint(@NonNull Point from, @NonNull Point to); static Point along(@NonNull LineString line, @FloatRange(from = 0) double distance,
                            @NonNull @TurfConstants.TurfUnitCriteria String units); static Point along(@NonNull List<Point> coords, @FloatRange(from = 0) double distance,
                            @NonNull @TurfConstants.TurfUnitCriteria String units); static double[] bbox(@NonNull Point point); static double[] bbox(@NonNull LineString lineString); static double[] bbox(@NonNull MultiPoint multiPoint); static double[] bbox(@NonNull Polygon polygon); static double[] bbox(@NonNull MultiLineString multiLineString); static double[] bbox(MultiPolygon multiPolygon); static double[] bbox(GeoJson geoJson); static double[] bbox(FeatureCollection featureCollection); static double[] bbox(Feature feature); static double[] bbox(Geometry geometry); static Feature bboxPolygon(@NonNull BoundingBox boundingBox); static Feature bboxPolygon(@NonNull BoundingBox boundingBox,
                                    @Nullable JsonObject properties,
                                    @Nullable String id); static Feature bboxPolygon(@NonNull double[] bbox); static Feature bboxPolygon(@NonNull double[] bbox,
                                    @Nullable JsonObject properties,
                                    @Nullable String id); static Polygon envelope(GeoJson geoJson); static BoundingBox square(@NonNull BoundingBox boundingBox); static double area(@NonNull Feature feature); static double area(@NonNull FeatureCollection featureCollection); static double area(@NonNull Geometry geometry); static Feature center(Feature feature,
                               @Nullable JsonObject properties,
                               @Nullable String id); static Feature center(Feature feature); static Feature center(FeatureCollection featureCollection,
                               @Nullable JsonObject properties,
                               @Nullable String id); static Feature center(FeatureCollection featureCollection); static double EARTH_RADIUS; }
@Test public void turfAlong_returnsZeroWhenRouteIsPoint() throws Exception { List<Point> coords = new ArrayList<>(); coords.add(Point.fromLngLat(1.0, 1.0)); LineString lineString = LineString.fromLngLats(coords); Point point = TurfMeasurement.along(lineString, 0, TurfConstants.UNIT_METERS); assertEquals(1.0, point.latitude(), DELTA); assertEquals(1.0, point.longitude(), DELTA); }
@Test public void testTurfAlong() throws IOException, TurfException { Feature feature = Feature.fromJson(loadJsonFixture(TURF_ALONG_DC_LINE)); LineString line = (LineString) feature.geometry(); Point pt1 = TurfMeasurement.along(line, 1, "miles"); Point pt2 = TurfMeasurement.along(line, 1.2, "miles"); Point pt3 = TurfMeasurement.along(line, 1.4, "miles"); Point pt4 = TurfMeasurement.along(line, 1.6, "miles"); Point pt5 = TurfMeasurement.along(line, 1.8, "miles"); Point pt6 = TurfMeasurement.along(line, 2, "miles"); Point pt7 = TurfMeasurement.along(line, 100, "miles"); Point pt8 = TurfMeasurement.along(line, 0, "miles"); FeatureCollection fc = FeatureCollection.fromFeatures(new Feature[] { Feature.fromGeometry(pt1), Feature.fromGeometry(pt2), Feature.fromGeometry(pt3), Feature.fromGeometry(pt4), Feature.fromGeometry(pt5), Feature.fromGeometry(pt6), Feature.fromGeometry(pt7), Feature.fromGeometry(pt8) }); for (Feature f : fc.features()) { assertNotNull(f); assertEquals("Feature", f.type()); assertEquals("Point", f.geometry().type()); } assertEquals(8, fc.features().size()); assertEquals(((Point) fc.features().get(7).geometry()).longitude(), pt8.longitude(), DELTA); assertEquals(((Point) fc.features().get(7).geometry()).latitude(), pt8.latitude(), DELTA); }