@Override public JsonObject asGeoJsonGeometry() { return GeoJsonUtils.geometry(GeoJsonUtils.POINT, GeoJsonUtils.coordinate(this)); }
@Override public JsonObject asGeoJsonGeometry() { return GeoJsonUtils.geometry(GeoJsonUtils.LINESTRING, GeoJsonUtils.locationsToCoordinates(this.points)); }
return GeoJsonUtils.geometry(GeoJsonUtils.POINT, GeoJsonUtils.coordinate(0.0, 0.0)); return GeoJsonUtils.boundsToPolygonGeometry(bounds);
logger.warn("Unable to recreate multipolygon for relation {}.", getIdentifier(), message); geometry = GeoJsonUtils.boundsToPolygonGeometry(bounds()); geometry = GeoJsonUtils.boundsToPolygonGeometry(bounds()); return GeoJsonUtils.feature(geometry, properties);
public JsonObject asGeoJsonFeature() { final JsonObject geometry = boundsGeoJsonGeometry(); final JsonObject properties = new JsonObject(); properties.addProperty("flag:type", CheckFlag.class.getSimpleName()); properties.addProperty("flag:id", getIdentifier()); properties.addProperty("flag:instructions", getInstructions()); // The legacy GeoJSON FeatureCollection doesn't actually provide this, // but I figure this might be useful to know about if it's there... if (challengeName != null) { properties.addProperty("flag:challenge", challengeName); } return GeoJsonUtils.feature(geometry, properties); }
/** * An iterable of locations will turn into a JsonArray of Longitude, Latitude coordinates. * * @param locations * An iterable of locations * @return A JsonArray of Longitude, Latitude coordinates. */ public static JsonArray locationsToCoordinates(final Iterable<Location> locations) { final JsonArray coordinates = new JsonArray(); for (final Location point : locations) { coordinates.add(coordinate(point)); } return coordinates; }
@Test public void testBoundsToPolygonGeometry() { final Rectangle rectangle = Rectangle.TEST_RECTANGLE; final JsonObject polygonGeometry = GeoJsonUtils.boundsToPolygonGeometry(rectangle); Assert.assertEquals(BOUNDS_POLYGON_GEOJSON, polygonGeometry.toString()); }
case MULTI_POLYGON: coordinates = GeoJsonUtils.locationsToCoordinates(locations); break; final JsonArray locationArray = GeoJsonUtils.locationsToCoordinates(locations); coordinates.add(locationArray); break;
@Override public JsonObject asGeoJsonFeature(final String flagIdentifier) { final JsonObject feature; final JsonObject properties; if (locationItem != null) { feature = locationItem.asGeoJsonGeometry(); properties = feature.getAsJsonObject("properties"); } else { properties = new JsonObject(); feature = GeoJsonUtils.feature(point.asGeoJsonGeometry(), properties); } properties.addProperty("flag:id", flagIdentifier); properties.addProperty("flag:type", FlaggedPoint.class.getSimpleName()); return feature; }
/** * From a location, we get a Latitude / Longitude Json Array [ latitude, longitude ] * * @param location * An atlas location * @return JsonArray [ longitude, latitude ] coordinate. */ public static JsonArray coordinate(final Location location) { return coordinate(location.getLongitude().asDegrees(), location.getLatitude().asDegrees()); }
@Override public JsonObject asGeoJsonGeometry() { return GeoJsonUtils.feature(getLocation().asGeoJsonGeometry(), geoJsonProperties()); }
/** * Creates a GeoJSON Polygon geometry from a bounds. * * @param bounds * A bounds. * @return A GeoJSON Polygon geometry JsonObject. */ public static JsonObject boundsToPolygonGeometry(final Rectangle bounds) { final JsonArray outerRing = new JsonArray(); final Iterable<Location> locations = bounds.closedLoop(); for (final Location location : locations) { outerRing.add(coordinate(location)); } final JsonArray coordinates = new JsonArray(); coordinates.add(outerRing); return geometry(POLYGON, coordinates); }
@Override public JsonObject asGeoJsonGeometry() { final JsonArray coordinates = new JsonArray(); final JsonArray subCoordinatesArray = GeoJsonUtils.locationsToCoordinates(closedLoop()); coordinates.add(subCoordinatesArray); return GeoJsonUtils.geometry(GeoJsonUtils.POLYGON, coordinates); }
@Test public void testCoordinate() { final JsonArray coordinate = GeoJsonUtils.coordinate(LONGITUDE, LATITUDE); Assert.assertEquals(COORDINATE, coordinate.toString()); } }
@Override public JsonObject asGeoJsonGeometry() { return GeoJsonUtils.feature(asPolygon().asGeoJsonGeometry(), geoJsonProperties()); }
/** * 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); }
@Override public JsonObject asGeoJsonGeometry() { return GeoJsonUtils.feature(asPolyLine().asGeoJsonGeometry(), geoJsonProperties()); }
@Test public void testFeature() { final JsonParser parser = new JsonParser(); final JsonObject geometry = parser.parse(GEOMETRY).getAsJsonObject(); final JsonObject properties = parser.parse(PROPERTIES).getAsJsonObject(); final JsonObject feature = GeoJsonUtils.feature(geometry, properties); Assert.assertEquals(FEATURE, feature.toString()); }