/** * Convert a list of polygons to a list of polygon descriptions. * @param polygons is the list of polygons to convert. * @return the list of polygon descriptions. */ private static List<GeoPolygonFactory.PolygonDescription> convertToDescription(final Polygon... polygons) { final List<GeoPolygonFactory.PolygonDescription> descriptions = new ArrayList<>(polygons.length); for (final Polygon polygon : polygons) { final Polygon[] theHoles = polygon.getHoles(); final List<GeoPolygonFactory.PolygonDescription> holes = convertToDescription(theHoles); // Now do the polygon itself final double[] polyLats = polygon.getPolyLats(); final double[] polyLons = polygon.getPolyLons(); // I presume the arguments have already been checked final List<GeoPoint> points = new ArrayList<>(polyLats.length-1); // We skip the last point anyway because the API requires it to be repeated, and geo3d doesn't repeat it. for (int i = 0; i < polyLats.length - 1; i++) { final int index = polyLats.length - 2 - i; points.add(new GeoPoint(PlanetModel.WGS84, fromDegrees(polyLats[index]), fromDegrees(polyLons[index]))); } descriptions.add(new GeoPolygonFactory.PolygonDescription(points, holes)); } return descriptions; }
description.add(new PolygonDescription(pointList)); return makeLargeGeoPolygon(planetModel, description);
@SuppressWarnings("unchecked") @Override public Shape build() { GeoPolygonFactory.PolygonDescription description = new GeoPolygonFactory.PolygonDescription(points, polyHoles); GeoPolygon polygon = GeoPolygonFactory.makeGeoPolygon(planetModel, description); if (polygon == null) { throw new InvalidShapeException("Invalid polygon, all points are coplanar"); } return new Geo3dShape<>(polygon, context); }
@Override public PolygonBuilder endHole() { polyHoles.add(new GeoPolygonFactory.PolygonDescription(points)); return Geo3dPolygonBuilder.this; } }