@Test public void testTurfLineSliceVertical() throws IOException, TurfException { Point start = Point.fromLngLat(-121.25447809696198, 38.70582415504791); Point stop = Point.fromLngLat(-121.25447809696198, 38.70634324369764); Feature vertical = Feature.fromJson(loadJsonFixture(LINE_SLICE_VERTICAL)); LineString sliced = TurfMisc.lineSlice(start, stop, vertical); assertNotNull(sliced); // No duplicated coords assertEquals(2, sliced.coordinates().size()); // Vertical slice does not collapse to 1st coord assertNotEquals(sliced.coordinates().get(0), sliced.coordinates().get(1)); }
@Test public void testLineAlongStopLongerThanLength() throws IOException, TurfException { Feature line1 = Feature.fromJson(loadJsonFixture(LINE_SLICE_ALONG_LINE_ONE)); LineString lineStringLine1 = (LineString) line1.geometry(); double start = 500; double stop = 800000; Point start_point = TurfMeasurement.along(lineStringLine1, start, TurfConstants.UNIT_MILES); List<Point> lineCoordinates = lineStringLine1.coordinates(); LineString sliced = TurfMisc.lineSliceAlong(line1, start, stop, TurfConstants.UNIT_MILES); assertEquals(sliced.coordinates().get(0).coordinates(), start_point.coordinates()); assertEquals(sliced.coordinates().get(sliced.coordinates().size() - 1).coordinates(), lineCoordinates.get(lineCoordinates.size() - 1).coordinates()); }
@Test public void testTurfLineSliceLine1() throws IOException, TurfException { Point start = Point.fromLngLat(-97.79617309570312, 22.254624939561698); Point stop = Point.fromLngLat(-97.72750854492188, 22.057641623615734); Feature line1 = Feature.fromJson(loadJsonFixture(LINE_SLICE_ONE)); LineString sliced = TurfMisc.lineSlice(start, stop, line1); assertNotNull(sliced); }
@Test public void testTurfLineSliceRoute1() throws IOException, TurfException { Point start = Point.fromLngLat(-79.0850830078125, 37.60117623656667); Point stop = Point.fromLngLat(-77.7667236328125, 38.65119833229951); Feature route1 = Feature.fromJson(loadJsonFixture(LINE_SLICE_ROUTE_ONE)); LineString sliced = TurfMisc.lineSlice(start, stop, route1); assertNotNull(sliced); }
@Test public void testLineAlongStartLongerThanLength() throws Exception { thrown.expect(TurfException.class); thrown.expectMessage(startsWith("Start position is beyond line")); Feature line1 = Feature.fromJson(loadJsonFixture(LINE_SLICE_ALONG_LINE_ONE)); double start = 500000; double stop = 800000; TurfMisc.lineSliceAlong(line1, start, stop, TurfConstants.UNIT_MILES); }
@Test public void testTurfLineSliceRoute2() throws IOException, TurfException { Point start = Point.fromLngLat(-112.60660171508789, 45.96021963947196); Point stop = Point.fromLngLat(-111.97265625, 48.84302835299516); Feature route2 = Feature.fromJson(loadJsonFixture(LINE_SLICE_ROUTE_TWO)); LineString sliced = TurfMisc.lineSlice(start, stop, route2); assertNotNull(sliced); }
@Test public void testTurfLineSliceRawGeometry() throws IOException, TurfException { Point start = Point.fromLngLat(-97.79617309570312, 22.254624939561698); Point stop = Point.fromLngLat(-97.72750854492188, 22.057641623615734); Feature line1 = Feature.fromJson(loadJsonFixture(LINE_SLICE_ONE)); LineString sliced = TurfMisc.lineSlice(start, stop, (LineString) line1.geometry()); assertNotNull(sliced); }
@Test public void testLineSliceAlongRoute2() throws IOException, TurfException { Feature route2 = Feature.fromJson(loadJsonFixture(LINE_SLICE_ALONG_ROUTE_TWO)); LineString lineStringRoute2 = (LineString)route2.geometry(); double start = 25; double stop = 50; Point start_point = TurfMeasurement.along(lineStringRoute2, start, TurfConstants.UNIT_MILES); Point end_point = TurfMeasurement.along(lineStringRoute2, stop, TurfConstants.UNIT_MILES); LineString sliced = TurfMisc.lineSliceAlong(route2, 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()); }
@Test public void testLineSliceAlongLine1() throws IOException, TurfException { Feature line1 = Feature.fromJson(loadJsonFixture(LINE_SLICE_ALONG_LINE_ONE)); LineString lineStringLine1 = (LineString) line1.geometry(); double start = 500; double stop = 750; Point start_point = TurfMeasurement.along(lineStringLine1, start, TurfConstants.UNIT_MILES); Point end_point = TurfMeasurement.along(lineStringLine1, stop, TurfConstants.UNIT_MILES); LineString sliced = TurfMisc.lineSliceAlong(line1, 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()); }
@Test public void testLineSliceAlongOvershootLine1() throws IOException, TurfException { Feature line1 = Feature.fromJson(loadJsonFixture(LINE_SLICE_ALONG_LINE_ONE)); LineString lineStringLine1 = (LineString) line1.geometry(); double start = 500; double stop = 1500; Point start_point = TurfMeasurement.along(lineStringLine1, start, TurfConstants.UNIT_MILES); Point end_point = TurfMeasurement.along(lineStringLine1, stop, TurfConstants.UNIT_MILES); LineString sliced = TurfMisc.lineSliceAlong(line1, 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()); }
@Test public void testLineSliceAlongRoute1() throws IOException, TurfException { Feature route1 = Feature.fromJson(loadJsonFixture(LINE_SLICE_ALONG_ROUTE_ONE)); LineString lineStringRoute1 = (LineString)route1.geometry(); double start = 500; double stop = 750; Point start_point = TurfMeasurement.along(lineStringRoute1, start, TurfConstants.UNIT_MILES); Point end_point = TurfMeasurement.along(lineStringRoute1, stop, TurfConstants.UNIT_MILES); LineString sliced = TurfMisc.lineSliceAlong(route1, 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()); }