/** * Creates a Polygon type GeoJson Feature * * @param polygon * geometry * @return a GeoJson Feature */ public GeoJsonObject create(final Polygon polygon) { return this.create(polygon.closedLoop(), GeoJsonType.POLYGON); }
@Override public JsonObject asGeoJsonGeometry() { final JsonArray coordinates = new JsonArray(); final JsonArray subCoordinatesArray = GeoJsonUtils.locationsToCoordinates(closedLoop()); coordinates.add(subCoordinatesArray); return GeoJsonUtils.geometry(GeoJsonUtils.POLYGON, coordinates); }
/** * @return The closed {@link Polygon}, with the end {@link Location} equal to the start * {@link Location}. */ public Polygon getClosedGeometry() { return new Polygon(asPolygon().closedLoop()); }
/** * Creates a JsonObject with GeoJSON geometry representing this multi-polygon. * * @return A JsonObject with GeoJSON geometry */ @Override public JsonObject asGeoJsonGeometry() { // An array of polygons. An OGC polygon is an outer ring with 0..n inner rings. final JsonArray polygons = new JsonArray(); for (final Map.Entry<Polygon, List<Polygon>> entry : this.outerToInners.entrySet()) { final Polygon outer = entry.getKey(); final List<Polygon> inners = entry.getValue(); final JsonArray polygon = new JsonArray(); final JsonArray outerRingCoordinates = GeoJsonUtils .locationsToCoordinates(outer.closedLoop()); polygon.add(outerRingCoordinates); for (final Polygon inner : inners) { final JsonArray innerRingCoordinates = GeoJsonUtils .locationsToCoordinates(inner.closedLoop()); polygon.add(innerRingCoordinates); } polygons.add(polygon); } return GeoJsonUtils.geometry(GeoJsonUtils.MULTIPOLYGON, polygons); }
for (final Polygon polygon : polygons) objects.add(this.create(polygon.closedLoop(), GeoJsonType.MULTI_POLYGON));
for (final Polygon polygon : polygons) objects.add(this.create(polygon.closedLoop(), GeoJsonType.MULTI_POLYGON));
/** * @return The approximate surface area of this polygon if it were projected onto the Earth. Not * valid if the polygon self-intersects, and/or overlaps itself. Uses "Some Algorithms * for Polygons on a Sphere" paper as reference. * @see "https://trs.jpl.nasa.gov/bitstream/handle/2014/41271/07-0286.pdf" */ @Override public Surface surfaceOnSphere() { double dm7 = 0L; final List<Location> locations = Lists.newArrayList(this.closedLoop()); if (locations.size() > 2) { double radians = 0L; for (int index = 0; index < locations.size() - 1; index++) { radians += (locations.get(index + 1).getLongitude().asRadians() - locations.get(index).getLongitude().asRadians()) * (2 + Math.sin(locations.get(index).getLatitude().asRadians()) + Math.sin(locations.get(index + 1).getLatitude().asRadians())); } radians = Math.abs(radians / 2.0); // Calculations are in Radians, convert to Degrees. dm7 = radians * ((double) Angle.DM7_PER_RADIAN * (double) Angle.DM7_PER_RADIAN); } return Surface.forDm7Squared(Math.round(dm7)); }
/** * Default constructor * * @param atlasItem * the {@link AtlasItem} to flag */ public FlaggedPolyline(final AtlasItem atlasItem) { this.atlasItem = atlasItem; if (atlasItem instanceof Area) { // We should actually have a FlaggedPolygon class with a polygon in it instead of just // making polygons be PolyLines. I am not sure why FlaggedPolygon was not implemented. this.polyLine = new PolyLine(((Area) atlasItem).asPolygon().closedLoop()); } else { this.polyLine = new PolyLine(atlasItem.getRawGeometry()); } this.properties = initProperties(atlasItem); this.country = initCountry(atlasItem); }
@Override public Way convert(final AtlasPrimitiveArea object) { return new Way( new CommonEntityData(object.getIdentifier(), 0, new Date(), new OsmUser(0, "osm"), 0, TAG_MAP_TO_TAG_COLLECTION_CONVERTER.convert(object.getTags())), LOCATION_ITERABLE_TO_WAY_NODE_LIST_CONVERTER .convert(object.getPolygon().closedLoop())); } }
@Test public void testClosedLoop() { final Polygon polygon = Polygon.SILICON_VALLEY; final Polygon initialClosedLoop = new Polygon(polygon.closedLoop()); Assert.assertNotEquals( "Last and Last - 1 locations for the polygon should not be duplicate.", initialClosedLoop.last(), initialClosedLoop.get(initialClosedLoop.size() - 2)); final Polygon doubleClosedLoop = new Polygon(initialClosedLoop.closedLoop()); Assert.assertNotEquals("Last and Last - 1 locations for polygon should not be duplicate.", doubleClosedLoop.last(), doubleClosedLoop.get(doubleClosedLoop.size() - 2)); }