/** * Get all coordinates from a {@link MultiPoint} object, returning a {@code List} of Point * objects. If you have a geometry collection, you need to break it down to individual geometry * objects before using {@link #coordAll}. * * @param multiPoint any {@link MultiPoint} object * @return a {@code List} made up of {@link Point}s * @since 2.0.0 */ @NonNull public static List<Point> coordAll(@NonNull MultiPoint multiPoint) { List<Point> coords = new ArrayList<>(); coords.addAll(multiPoint.coordinates()); return coords; }
@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 bbox_doesNotSerializeWhenNotPresent() throws Exception { List<Point> points = new ArrayList<>(); points.add(Point.fromLngLat(1.0, 2.0)); points.add(Point.fromLngLat(2.0, 3.0)); MultiPoint multiPoint = MultiPoint.fromLngLats(points); compareJson(multiPoint.toJson(), "{\"coordinates\":[[1,2],[2,3]],\"type\":\"MultiPoint\"}"); }
@Test public void bbox_nullWhenNotSet() throws Exception { List<Point> points = new ArrayList<>(); points.add(Point.fromLngLat(1.0, 2.0)); points.add(Point.fromLngLat(2.0, 3.0)); MultiPoint multiPoint = MultiPoint.fromLngLats(points); assertNull(multiPoint.bbox()); }
@Test public void sanity() throws Exception { List<Point> points = new ArrayList<>(); points.add(Point.fromLngLat(1.0, 2.0)); points.add(Point.fromLngLat(2.0, 3.0)); MultiPoint multiPoint = MultiPoint.fromLngLats(points); assertNotNull(multiPoint); }
@Test public void fromJson_coordinatesPresent() throws Exception { thrown.expect(NullPointerException.class); MultiPoint.fromJson("{\"type\":\"MultiPoint\",\"coordinates\":null}"); } }
@Test public void bbox_doesSerializeWhenPresent() throws Exception { List<Point> points = new ArrayList<>(); points.add(Point.fromLngLat(1.0, 2.0)); points.add(Point.fromLngLat(2.0, 3.0)); BoundingBox bbox = BoundingBox.fromLngLats(1.0, 2.0, 3.0, 4.0); MultiPoint multiPoint = MultiPoint.fromLngLats(points, bbox); compareJson(multiPoint.toJson(), "{\"coordinates\":[[1,2],[2,3]],\"type\":\"MultiPoint\",\"bbox\":[1.0,2.0,3.0,4.0]}"); }
@Test public void bbox_returnsCorrectBbox() throws Exception { List<Point> points = new ArrayList<>(); points.add(Point.fromLngLat(1.0, 2.0)); points.add(Point.fromLngLat(2.0, 3.0)); BoundingBox bbox = BoundingBox.fromLngLats(1.0, 2.0, 3.0, 4.0); MultiPoint multiPoint = MultiPoint.fromLngLats(points, bbox); assertNotNull(multiPoint.bbox()); assertEquals(1.0, multiPoint.bbox().west(), DELTA); assertEquals(2.0, multiPoint.bbox().south(), DELTA); assertEquals(3.0, multiPoint.bbox().east(), DELTA); assertEquals(4.0, multiPoint.bbox().north(), DELTA); }
points.add(Point.fromLngLat(bbox[0], bbox[3])); return TurfMeasurement.bbox(MultiPoint.fromLngLats(points)); } else { throw new RuntimeException(("Unknown geometry class: " + geometry.getClass()));
@Test public void bboxFromGeometryCollection() throws IOException, TurfException { // Check that geometry collection and direct bbox are equal MultiPolygon multiPolygon = MultiPolygon.fromJson(loadJsonFixture(TURF_BBOX_MULTIPOLYGON)); assertArrayEquals(TurfMeasurement.bbox(multiPolygon), TurfMeasurement.bbox(GeometryCollection.fromGeometry(multiPolygon)), DELTA); // Check all geometry types List<Geometry> geometries = new ArrayList<>(); geometries.add(Feature.fromJson(loadJsonFixture(TURF_BBOX_POINT)).geometry()); geometries.add(MultiPoint.fromJson(loadJsonFixture(TURF_BBOX_MULTI_POINT))); geometries.add(LineString.fromJson(loadJsonFixture(TURF_BBOX_LINESTRING))); geometries.add(MultiLineString.fromJson(loadJsonFixture(TURF_BBOX_MULTILINESTRING))); geometries.add(Feature.fromJson(loadJsonFixture(TURF_BBOX_POLYGON)).geometry()); geometries.add(MultiPolygon.fromJson(loadJsonFixture(TURF_BBOX_MULTIPOLYGON))); geometries.add(GeometryCollection.fromGeometry(Point.fromLngLat(-1., -1.))); double[] bbox = TurfMeasurement.bbox(GeometryCollection.fromGeometries(geometries)); assertEquals(4, bbox.length); assertEquals(-1, bbox[0], DELTA); assertEquals(-10, bbox[1], DELTA); assertEquals(130, bbox[2], DELTA); assertEquals(4, bbox[3], DELTA); } }
/** * Create a new instance of this class by defining a {@link MultiPoint} object and passing. The * multipoint object should comply with the GeoJson specifications described in the documentation. * * @param multiPoint which will make up the LineString geometry * @return a new instance of this class defined by the values passed inside this static factory * method * @since 3.0.0 */ public static LineString fromLngLats(@NonNull MultiPoint multiPoint) { return new AutoValue_LineString(TYPE, null, multiPoint.coordinates()); }
@Test public void fromLngLats_generatedFromMultipoint() throws Exception { List<Point> points = new ArrayList<>(); points.add(Point.fromLngLat(1.0,2.0)); points.add(Point.fromLngLat(4.0,8.0)); MultiPoint multiPoint = MultiPoint.fromLngLats(points); LineString lineString = LineString.fromLngLats(multiPoint); assertEquals("_gayB_c`|@_wemJ_kbvD", lineString.toPolyline(Constants.PRECISION_6)); }
/** * Create a new instance of this class by defining a {@link MultiPoint} object and passing. The * multipoint object should comply with the GeoJson specifications described in the documentation. * * @param multiPoint which will make up the LineString geometry * @return a new instance of this class defined by the values passed inside this static factory * method * @since 3.0.0 */ public static LineString fromLngLats(@NonNull MultiPoint multiPoint) { return new AutoValue_LineString(TYPE, null, multiPoint.coordinates()); }
@Test public void testSerializable() throws Exception { List<Point> points = new ArrayList<>(); points.add(Point.fromLngLat(1.0, 2.0)); points.add(Point.fromLngLat(2.0, 3.0)); BoundingBox bbox = BoundingBox.fromLngLats(1.0, 2.0, 3.0, 4.0); MultiPoint multiPoint = MultiPoint.fromLngLats(points, bbox); byte[] bytes = serialize(multiPoint); assertEquals(multiPoint, deserialize(bytes, MultiPoint.class)); }
/** * Create a new instance of this class by defining a {@link MultiPoint} object and passing. The * multipoint object should comply with the GeoJson specifications described in the documentation. * * @param multiPoint which will make up the LineString geometry * @param bbox optionally include a bbox definition as a double array * @return a new instance of this class defined by the values passed inside this static factory * method * @since 3.0.0 */ public static LineString fromLngLats(@NonNull MultiPoint multiPoint, @Nullable BoundingBox bbox) { return new AutoValue_LineString(TYPE, bbox, multiPoint.coordinates()); }
/** * Create a new instance of this class by defining a {@link MultiPoint} object and passing. The * multipoint object should comply with the GeoJson specifications described in the documentation. * * @param multiPoint which will make up the LineString geometry * @param bbox optionally include a bbox definition as a double array * @return a new instance of this class defined by the values passed inside this static factory * method * @since 3.0.0 */ public static LineString fromLngLats(@NonNull MultiPoint multiPoint, @Nullable BoundingBox bbox) { return new AutoValue_LineString(TYPE, bbox, multiPoint.coordinates()); }