@Override public List<Double> unshiftPoint(Point point) { return point.coordinates(); }
@Override public List<Double> unshiftPoint(Point point) { return point.coordinates(); }
/** * This returns a double value ranging from -90 to 90 representing the y or northing position of * this point. ideally, this value would be restricted to 6 decimal places to correctly follow the * GeoJson spec. * * @return a double value ranging from -90 to 90 representing the y or northing position of this * point * @since 3.0.0 */ public double latitude() { return coordinates().get(1); }
/** * This returns a double value ranging from -180 to 180 representing the x or easting position of * this point. ideally, this value would be restricted to 6 decimal places to correctly follow the * GeoJson spec. * * @return a double value ranging from -180 to 180 representing the x or easting position of this * point * @since 3.0.0 */ public double longitude() { return coordinates().get(0); }
/** * This returns a double value ranging from -180 to 180 representing the x or easting position of * this point. ideally, this value would be restricted to 6 decimal places to correctly follow the * GeoJson spec. * * @return a double value ranging from -180 to 180 representing the x or easting position of this * point * @since 3.0.0 */ public double longitude() { return coordinates().get(0); }
/** * This returns a double value ranging from -90 to 90 representing the y or northing position of * this point. ideally, this value would be restricted to 6 decimal places to correctly follow the * GeoJson spec. * * @return a double value ranging from -90 to 90 representing the y or northing position of this * point * @since 3.0.0 */ public double latitude() { return coordinates().get(1); }
/** * Optionally, the coordinate spec in GeoJson allows for altitude values to be placed inside the * coordinate array. {@link #hasAltitude()} can be used to determine if this value was set during * initialization of this Point instance. This double value should only be used to represent * either the elevation or altitude value at this particular point. * * @return a double value ranging from negative to positive infinity * @since 3.0.0 */ public double altitude() { if (coordinates().size() < 3) { return Double.NaN; } return coordinates().get(2); }
/** * Optionally, the coordinate spec in GeoJson allows for altitude values to be placed inside the * coordinate array. {@link #hasAltitude()} can be used to determine if this value was set during * initialization of this Point instance. This double value should only be used to represent * either the elevation or altitude value at this particular point. * * @return a double value ranging from negative to positive infinity * @since 3.0.0 */ public double altitude() { if (coordinates().size() < 3) { return Double.NaN; } return coordinates().get(2); }
@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 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()); }
@Test public void testShortLine() throws IOException, TurfException { // Distance between points is about 186 miles 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()); } }
@Test public void fromJson() throws IOException { final String json = loadJsonFixture(SAMPLE_POINT); Point geo = Point.fromJson(json); assertEquals(geo.type(), "Point"); assertEquals(geo.longitude(), 100.0, DELTA); assertEquals(geo.latitude(), 0.0, DELTA); assertEquals(geo.altitude(), Double.NaN, DELTA); assertEquals(geo.coordinates().get(0), 100.0, DELTA); assertEquals(geo.coordinates().get(1), 0.0, DELTA); assertEquals(geo.coordinates().size(), 2); assertFalse(geo.hasAltitude()); }
@Test public void passingInSingleFeature_doesHandleCorrectly() throws Exception { Point geometry = Point.fromLngLat(1.0, 2.0); Feature feature = Feature.fromGeometry(geometry); FeatureCollection geo = FeatureCollection.fromFeature(feature); assertNotNull(geo.features()); assertEquals(1, geo.features().size()); assertEquals(2.0, ((Point) geo.features().get(0).geometry()).coordinates().get(1), DELTA); }