@Override public void write(JsonWriter out, Geometry value) throws IOException { out.beginObject(); out.name("type").value(value.type()); if (value.bbox() != null) { out.name("bbox").jsonValue(value.bbox().toJson()); } if (value instanceof CoordinateContainer) { out.name("coordinates").jsonValue(((CoordinateContainer) value).coordinates().toString()); } out.endObject(); }
return BoundingBox.fromLngLats( rawCoordinates.get(0).getAsDouble(), rawCoordinates.get(1).getAsDouble(), return BoundingBox.fromLngLats( rawCoordinates.get(0).getAsDouble(), rawCoordinates.get(1).getAsDouble(),
@Test public void bbox_basic_shift() throws Exception { Point southwest = Point.fromLngLat(2.0, 2.0); Point northeast = Point.fromLngLat(4.0, 4.0); CoordinateShifter shifter = new TestCoordinateShifter(); // Manually shifted List<Double> shifted = shifter.shiftLonLat(southwest.longitude(), southwest.latitude()); Point southwestManualShifted = Point.fromLngLat(shifted.get(0), shifted.get(1)); shifted = shifter.shiftLonLat(northeast.longitude(), northeast.latitude()); Point northeastManualShifted = Point.fromLngLat(shifted.get(0), shifted.get(1)); CoordinateShifterManager.setCoordinateShifter(shifter); BoundingBox boundingBoxFromDouble = BoundingBox.fromLngLats(2.0, 2.0, 4.0, 4.0); BoundingBox boundingBoxFromPoints = BoundingBox.fromPoints(Point.fromLngLat(2.0, 2.0), Point.fromLngLat(4.0, 4.0)); assertEquals(boundingBoxFromDouble, boundingBoxFromPoints); assertEquals(southwestManualShifted, boundingBoxFromPoints.southwest()); assertEquals(northeastManualShifted, boundingBoxFromPoints.northeast()); CoordinateShifterManager.setCoordinateShifter(null); }
@Test public void east_doesReturnMostEastCoordinate() throws Exception { Point southwest = Point.fromLngLat(1.0, 2.0); Point northeast = Point.fromLngLat(3.0, 4.0); BoundingBox boundingBox = BoundingBox.fromPoints(southwest, northeast); assertEquals(3.0, boundingBox.east(), DELTA); }
@Test public void north_doesReturnMostNorthCoordinate() throws Exception { Point southwest = Point.fromLngLat(1.0, 2.0); Point northeast = Point.fromLngLat(3.0, 4.0); BoundingBox boundingBox = BoundingBox.fromPoints(southwest, northeast); assertEquals(4.0, boundingBox.north(), DELTA); } }
@Test public void west_doesReturnMostWestCoordinate() throws Exception { Point southwest = Point.fromLngLat(1.0, 2.0); Point northeast = Point.fromLngLat(3.0, 4.0); BoundingBox boundingBox = BoundingBox.fromPoints(southwest, northeast); assertEquals(1.0, boundingBox.west(), DELTA); }
@Test public void south_doesReturnMostSouthCoordinate() throws Exception { Point southwest = Point.fromLngLat(1.0, 2.0); Point northeast = Point.fromLngLat(3.0, 4.0); BoundingBox boundingBox = BoundingBox.fromPoints(southwest, northeast); assertEquals(2.0, boundingBox.south(), DELTA); }
/** * 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(); }
/** * 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 west() { return southwest().longitude(); }
@Test public void northEast_doesReturnMostNortheastCoordinate() throws Exception { Point southwest = Point.fromLngLat(1.0, 2.0); Point northeast = Point.fromLngLat(3.0, 4.0); BoundingBox boundingBox = BoundingBox.fromPoints(southwest, northeast); assertTrue(northeast.equals(boundingBox.northeast())); }
@Test public void southWest_doesReturnMostSouthwestCoordinate() throws Exception { Point southwest = Point.fromLngLat(1.0, 2.0); Point northeast = Point.fromLngLat(3.0, 4.0); BoundingBox boundingBox = BoundingBox.fromPoints(southwest, northeast); assertTrue(southwest.equals(boundingBox.southwest())); }
return BoundingBox.fromLngLats( rawCoordinates.get(0).getAsDouble(), rawCoordinates.get(1).getAsDouble(), return BoundingBox.fromLngLats( rawCoordinates.get(0).getAsDouble(), rawCoordinates.get(1).getAsDouble(),
/** * Convenience method for getting the bounding box most easterly point (longitude) as a double * coordinate. * * @return the most easterly coordinate inside this bounding box * @since 3.0.0 */ public final double east() { return northeast().longitude(); }
/** * Convenience method for getting the bounding box most southerly point (latitude) as a double * coordinate. * * @return the most southerly coordinate inside this bounding box * @since 3.0.0 */ public final double south() { return southwest().latitude(); }
/** * Define a new instance of this class by passing in four coordinates in the same order they would * appear in the serialized GeoJson form. Limits are placed on the minimum and maximum coordinate * values which can exist and comply with the GeoJson spec. * * @param west the left side of the bounding box when the map is facing due north * @param south the bottom side of the bounding box when the map is facing due north * @param east the right side of the bounding box when the map is facing due north * @param north the top side of the bounding box when the map is facing due north * @return a new instance of this class defined by the provided coordinates * @since 3.0.0 * @deprecated As of 3.1.0, use {@link #fromLngLats} instead. */ @Deprecated public static BoundingBox fromCoordinates( @FloatRange(from = MIN_LONGITUDE, to = GeoJsonConstants.MAX_LONGITUDE) double west, @FloatRange(from = MIN_LATITUDE, to = GeoJsonConstants.MAX_LATITUDE) double south, @FloatRange(from = MIN_LONGITUDE, to = GeoJsonConstants.MAX_LONGITUDE) double east, @FloatRange(from = MIN_LATITUDE, to = GeoJsonConstants.MAX_LATITUDE) double north) { return fromLngLats(west, south, east, north); }
/** * Convenience method for getting the bounding box most easterly point (longitude) as a double * coordinate. * * @return the most easterly coordinate inside this bounding box * @since 3.0.0 */ public final double east() { return northeast().longitude(); }