/** * Convenience method for getting the bounding box most westerly point (longitude) as a double * coordinate. * * @return the most westerly coordinate inside this bounding box * @since 3.0.0 */ public final double north() { return northeast().latitude(); }
private static String formatCoordinates(List<Point> coordinates) { List<String> coordinatesFormatted = new ArrayList<>(); for (Point point : coordinates) { coordinatesFormatted.add(String.format(Locale.US, "%s,%s", TextUtils.formatCoordinate(point.longitude()), TextUtils.formatCoordinate(point.latitude()))); } return TextUtils.join(";", coordinatesFormatted.toArray()); } }
private static String formatCoordinates(List<Point> coordinates) { List<String> coordinatesFormatted = new ArrayList<>(); for (Point point : coordinates) { coordinatesFormatted.add(String.format(Locale.US, "%s,%s", TextUtils.formatCoordinate(point.longitude()), TextUtils.formatCoordinate(point.latitude()))); } return TextUtils.join(";", coordinatesFormatted.toArray()); } }
private static String formatCoordinates(List<Point> coordinates) { List<String> coordinatesFormatted = new ArrayList<>(); for (Point point : coordinates) { coordinatesFormatted.add(String.format(Locale.US, "%s,%s", TextUtils.formatCoordinate(point.longitude()), TextUtils.formatCoordinate(point.latitude()))); } return TextUtils.join(";", coordinatesFormatted.toArray()); } }
private static String formatCoordinates(List<Point> coordinates) { List<String> coordinatesFormatted = new ArrayList<>(); for (Point point : coordinates) { coordinatesFormatted.add(String.format(Locale.US, "%s,%s", TextUtils.formatCoordinate(point.longitude()), TextUtils.formatCoordinate(point.latitude()))); } return TextUtils.join(";", coordinatesFormatted.toArray()); } }
private static String formatCoordinates(List<Point> coordinates) { List<String> coordinatesFormatted = new ArrayList<>(); for (Point point : coordinates) { coordinatesFormatted.add(String.format(Locale.US, "%s,%s", TextUtils.formatCoordinate(point.longitude()), TextUtils.formatCoordinate(point.latitude()))); } return TextUtils.join(";", coordinatesFormatted.toArray()); } }
private static String formatCoordinates(List<Point> coordinates) { List<String> coordinatesFormatted = new ArrayList<>(); for (Point point : coordinates) { coordinatesFormatted.add(String.format(Locale.US, "%s,%s", TextUtils.formatCoordinate(point.longitude()), TextUtils.formatCoordinate(point.latitude()))); } return TextUtils.join(";", coordinatesFormatted.toArray()); } }
private static String formatCoordinates(List<Point> coordinates) { String[] coordinatesFormatted = new String[coordinates.size()]; int index = 0; for (Point point : coordinates) { coordinatesFormatted[index++] = String.format(Locale.US, "%s,%s", TextUtils.formatCoordinate(point.longitude()), TextUtils.formatCoordinate(point.latitude())); } return TextUtils.join(";", coordinatesFormatted); }
private static String formatCoordinates(List<Point> coordinates) { String[] coordinatesFormatted = new String[coordinates.size()]; int index = 0; for (Point point : coordinates) { coordinatesFormatted[index++] = String.format(Locale.US, "%s,%s", TextUtils.formatCoordinate(point.longitude()), TextUtils.formatCoordinate(point.latitude())); } return TextUtils.join(";", coordinatesFormatted); }
@Override public List<Double> unshiftPoint(Point shiftedPoint) { return Arrays.asList(shiftedPoint.longitude() - 3, shiftedPoint.latitude() - 5, shiftedPoint.altitude() - 8); }
@Test public void deserialize_sanity() throws Exception { String jsonString = "[100.0, 0.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); }
@Test public void fromJson() throws IOException { final String json = loadJsonFixture(SAMPLE_MULTIPOLYGON); MultiPolygon geo = MultiPolygon.fromJson(json); assertEquals(geo.type(), "MultiPolygon"); assertEquals(geo.coordinates().get(0).get(0).get(0).longitude(), 102.0, DELTA); assertEquals(geo.coordinates().get(0).get(0).get(0).latitude(), 2.0, DELTA); assertFalse(geo.coordinates().get(0).get(0).get(0).hasAltitude()); }
@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 testDecodePath() { List<Point> latLngs = decode(TEST_LINE, Constants.PRECISION_5); int expectedLength = 21; assertEquals("Wrong length.", expectedLength, latLngs.size()); Point lastPoint = latLngs.get(expectedLength - 1); expectNearNumber(37.76953, lastPoint.latitude(), 1e-6); expectNearNumber(-122.41488, lastPoint.longitude(), 1e-6); }
@Test public void fromJson() throws IOException { final String json = loadJsonFixture(SAMPLE_POLYGON); Polygon geo = Polygon.fromJson(json); assertEquals("Polygon", geo.type()); assertEquals(100.0, geo.coordinates().get(0).get(0).longitude(), DELTA); assertEquals(0.0, geo.coordinates().get(0).get(0).latitude(), DELTA); assertFalse(geo.coordinates().get(0).get(0).hasAltitude()); }
@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_LINESTRING_FIXTURE); LineString geo = LineString.fromJson(json); assertEquals(geo.type(), "LineString"); assertEquals(geo.coordinates().get(0).longitude(), 100.0, 0.0); assertEquals(geo.coordinates().get(0).latitude(), 0.0, 0.0); assertFalse(geo.coordinates().get(0).hasAltitude()); }
@Test public void test_point_feature_fromJson() throws IOException { final String json = "{ \"type\": \"Feature\"," + "\"geometry\": { \"type\": \"Point\", \"coordinates\": [ 125.6, 10.1] }," + "\"properties\": {\"name\": \"Dinagat Islands\" }}"; Feature geo = Feature.fromJson(json); assertEquals(geo.type(), "Feature"); assertEquals(geo.geometry().type(), "Point"); assertEquals(((Point)geo.geometry()).longitude(), 125.6, DELTA); assertEquals(((Point)geo.geometry()).latitude(), 10.1, DELTA); assertEquals(geo.properties().get("name").getAsString(), "Dinagat Islands"); }
@Test public void testFromJson() { String stepIntersectionJsonString = "{\"out\": 0, \"entry\": [true], \"bearings\": [ 125 ], " + "\"location\": [ 13.426579, 52.508068 ] }"; StepIntersection stepIntersection = StepIntersection.fromJson(stepIntersectionJsonString); Point location = stepIntersection.location(); Assert.assertEquals(13.426579, location.longitude(), 0.0001); Assert.assertEquals(52.508068, location.latitude(), 0.0001); String jsonStr = stepIntersection.toJson(); compareJson(stepIntersectionJsonString, jsonStr); } }
@Test public void location_doesGetConvertedToGeoJsonPoint() throws Exception { DirectionsWaypoint waypoint = DirectionsWaypoint.builder() .rawLocation(new double[] {1.0, 2.0}) .build(); assertNotNull(waypoint.location()); assertEquals(1.0, waypoint.location().longitude(), DELTA); assertEquals(2.0, waypoint.location().latitude(), DELTA); }