/** * Optionally, the coordinate spec in GeoJson allows for altitude values to be placed inside the * coordinate array. If an altitude value was provided while initializing this instance, this will * return true. * * @return true if this instance of point contains an altitude value * @since 3.0.0 */ public boolean hasAltitude() { return !Double.isNaN(altitude()); }
/** * Optionally, the coordinate spec in GeoJson allows for altitude values to be placed inside the * coordinate array. If an altitude value was provided while initializing this instance, this will * return true. * * @return true if this instance of point contains an altitude value * @since 3.0.0 */ public boolean hasAltitude() { return !Double.isNaN(altitude()); }
@Override public List<Double> unshiftPoint(Point shiftedPoint) { return Arrays.asList(shiftedPoint.longitude() - 3, shiftedPoint.latitude() - 5, shiftedPoint.altitude() - 8); }
@Test public void point_deserializeArrayOfArraysOfArrays() throws Exception { String jsonString = "[[[50.0, 50.0, 100.0], [100.0, 100.0, 200.0]]]"; GsonBuilder gsonBuilder = new GsonBuilder() .registerTypeAdapter(Point.class, new PointDeserializer()); Type type = new TypeToken<List<List<Point>>>() {}.getType(); List<List<Point>> points = gsonBuilder.create().fromJson(jsonString, type); assertEquals(50, points.get(0).get(0).longitude(), DELTA); assertEquals(50, points.get(0).get(0).latitude(), DELTA); assertEquals(100, points.get(0).get(0).altitude(), DELTA); assertEquals(100, points.get(0).get(1).longitude(), DELTA); assertEquals(100, points.get(0).get(1).latitude(), DELTA); assertEquals(200, points.get(0).get(1).altitude(), DELTA); } }
@Test public void point_deserializeArrayOfArrays() throws Exception { String jsonString = "[[50.0, 50.0, 100.0], [100.0, 100.0, 200.0]]"; GsonBuilder gsonBuilder = new GsonBuilder() .registerTypeAdapter(Point.class, new PointDeserializer()); List<Point> points = gsonBuilder.create().fromJson(jsonString, new TypeToken<List<Point>>() {}.getType()); assertEquals(50, points.get(0).longitude(), DELTA); assertEquals(50, points.get(0).latitude(), DELTA); assertEquals(100, points.get(0).altitude(), DELTA); assertEquals(100, points.get(1).longitude(), DELTA); assertEquals(100, points.get(1).latitude(), DELTA); assertEquals(200, points.get(1).altitude(), DELTA); }
@Test public void point_deserializeArray() throws Exception { String jsonString = "[100.0, 0.0, 200.0]"; GsonBuilder gsonBuilder = new GsonBuilder() .registerTypeAdapter(Point.class, new PointDeserializer()); Point point = gsonBuilder.create().fromJson(jsonString, Point.class); assertEquals(100, point.longitude(), DELTA); assertEquals(0, point.latitude(), DELTA); assertEquals(200, point.altitude(), DELTA); }
@Test public void altitude_doesReturnCorrectValueFromDoubleArray() throws Exception { double[] coords = new double[] {1.0, 2.0, 5.0}; Point point = Point.fromLngLat(coords); assertEquals(5, point.altitude(), DELTA); }
@Test public void point_hasAltitudeValueNoBoundingBoxAltCheck() throws Exception { Point point = Point.fromLngLat(100, 0, 200); assertEquals(200, point.altitude(), 0); }
@Test public void fromJson() throws IOException { final String json = loadJsonFixture(SAMPLE_MULTIPOINT); MultiPoint geo = MultiPoint.fromJson(json); assertEquals(geo.type(), "MultiPoint"); assertEquals(geo.coordinates().get(0).longitude(), 100.0, DELTA); assertEquals(geo.coordinates().get(0).latitude(), 0.0, DELTA); assertEquals(geo.coordinates().get(1).longitude(), 101.0, DELTA); assertEquals(geo.coordinates().get(1).latitude(), 1.0, DELTA); assertFalse(geo.coordinates().get(0).hasAltitude()); assertEquals(Double.NaN, geo.coordinates().get(0).altitude(), DELTA); }
@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()); }