/** * Returns a list of polygons which make up this MultiPolygon instance. * * @return a list of {@link Polygon}s which make up this MultiPolygon instance * @since 3.0.0 */ public List<Polygon> polygons() { List<List<List<Point>>> coordinates = coordinates(); List<Polygon> polygons = new ArrayList<>(coordinates.size()); for (List<List<Point>> points : coordinates) { polygons.add(Polygon.fromLngLats(points)); } return polygons; }
/** * Returns a list of polygons which make up this MultiPolygon instance. * * @return a list of {@link Polygon}s which make up this MultiPolygon instance * @since 3.0.0 */ public List<Polygon> polygons() { List<List<List<Point>>> coordinates = coordinates(); List<Polygon> polygons = new ArrayList<>(coordinates.size()); for (List<List<Point>> points : coordinates) { polygons.add(Polygon.fromLngLats(points)); } return polygons; }
/** * Takes a {@link Point} and calculates the circle polygon given a radius in degrees, radians, * miles, or kilometers; and steps for precision. * * @param center a {@link Point} which the circle will center around * @param radius the radius of the circle * @param steps number of steps which make up the circle parameter * @param units one of the units found inside {@link TurfConstants.TurfUnitCriteria} * @return a {@link Polygon} which represents the newly created circle * @since 3.0.0 */ public static Polygon circle(@NonNull Point center, double radius, int steps, @TurfConstants.TurfUnitCriteria String units) { List<Point> coordinates = new ArrayList<>(); for (int i = 0; i < steps; i++) { coordinates.add(TurfMeasurement.destination(center, radius, i * 360d / steps, units)); } coordinates.add(coordinates.get(0)); List<List<Point>> coordinate = new ArrayList<>(); coordinate.add(coordinates); return Polygon.fromLngLats(coordinate); } }
@Test public void passingInSinglePolygon_doesHandleCorrectly() throws Exception { List<Point> points = new ArrayList<>(); points.add(Point.fromLngLat(1.0, 2.0)); points.add(Point.fromLngLat(3.0, 4.0)); List<List<Point>> pointsList = new ArrayList<>(); pointsList.add(points); Polygon geometry = Polygon.fromLngLats(pointsList); MultiPolygon multiPolygon = MultiPolygon.fromPolygon(geometry); assertNotNull(multiPolygon); assertEquals(1, multiPolygon.polygons().size()); assertEquals(2.0, multiPolygon.polygons().get(0).coordinates().get(0).get(0).latitude(), DELTA); }
@Test public void fromLngLats_tripleDoubleArray() throws Exception { double[][][] coordinates = new double[][][] { {{100.0, 0.0}, {101.0, 0.0}, {101.0, 1.0}, {100.0, 1.0}, {100.0, 0.0}} }; Polygon polygon = Polygon.fromLngLats(coordinates); assertEquals(0, polygon.inner().size()); assertEquals(Point.fromLngLat(100.0, 0.0), polygon.coordinates().get(0).get(0)); }
List<List<Point>> coordinates = new ArrayList<>(); coordinates.add(pointList); Polygon poly = Polygon.fromLngLats(coordinates); coordinates = new ArrayList<>(); coordinates.add(pointList); Polygon concavePoly = Polygon.fromLngLats(coordinates);
ArrayList<List<Point>> coordinates = new ArrayList<>(); coordinates.add(pointList); Polygon poly = Polygon.fromLngLats(coordinates); Polygon poly1 = Polygon.fromLngLats(Arrays.asList(Arrays.asList( Point.fromLngLat(0, 0), Point.fromLngLat(10, 0), Point.fromLngLat(0, 0)))); Polygon poly2 = Polygon.fromLngLats(Arrays.asList(Arrays.asList( Point.fromLngLat(10, 0), Point.fromLngLat(20, 10),