/** * Creates a GeoJson FeatureCollection from an iterable of GeoJsonObject * * @param geoJsonObjects * a iterable of GeoJsonObject * @return a GeoJson FeatureCollection */ public GeoJsonObject createFromGeoJson(final Iterable<GeoJsonObject> geoJsonObjects) { final JsonObject result = new JsonObject(); result.addProperty(TYPE, FEATURE_COLLECTION); final JsonArray features = new JsonArray(); int counter = 0; for (final GeoJsonObject object : geoJsonObjects) { if (this.logFrequency > 0 && ++counter % this.logFrequency == 0) { logger.info("Processed {} features.", counter); } features.add(object.jsonObject()); } result.add(FEATURES, features); return new GeoJsonObject(result); }
/** * Creates a GeoJson FeatureCollection containing a list of Features * * @param geometriesWithProperties * associated geometries and properties used to build each Feature * @return a GeoJson FeatureCollection */ public GeoJsonObject createFromGeometriesWithProperties( final Iterable<GeometryWithProperties> geometriesWithProperties) { final JsonObject result = new JsonObject(); result.addProperty(TYPE, FEATURE_COLLECTION); final JsonArray features = new JsonArray(); int counter = 0; for (final GeometryWithProperties geometryWithProperties : geometriesWithProperties) { if (this.logFrequency > 0 && ++counter % this.logFrequency == 0) { logger.info("Processed {} features.", counter); } features.add(create(geometryWithProperties)); } result.add(FEATURES, features); return new GeoJsonObject(result); }
/** * Creates a MultiLineString type GeoJson Feature * * @param polyLines * geometry * @return a GeoJson Feature */ public GeoJsonObject createMultiLineStrings(final Iterable<PolyLine> polyLines) { // Create the coordinates for each polyline final List<GeoJsonObject> objects = new ArrayList<>(); for (final PolyLine polygon : polyLines) { objects.add(this.create(polygon, GeoJsonType.MULTI_LINESTRING)); } final JsonObject result = new JsonObject(); result.addProperty(TYPE, FEATURE); final JsonArray coordinates = new JsonArray(); // Add the coordinates back for the entire object for (final GeoJsonObject object : objects) { coordinates .add(object.jsonObject().getAsJsonObject(GEOMETRY).getAsJsonArray(COORDINATES)); } final JsonObject geometry = new JsonObject(); geometry.addProperty(TYPE, GeoJsonType.MULTI_LINESTRING.getType()); geometry.add(COORDINATES, coordinates); result.add(GEOMETRY, geometry); return new GeoJsonObject(result); }
/** * Creates a GeoJson FeatureCollection containing a list of GeoJsonObject Features * * @param objects * the features * @return a GeoJson FeatureCollection */ public GeoJsonObject createFeatureCollection(final Iterable<GeoJsonObject> objects) { final JsonObject result = new JsonObject(); result.addProperty(TYPE, FEATURE_COLLECTION); final JsonArray features = new JsonArray(); int counter = 0; for (final GeoJsonObject object : objects) { if (this.logFrequency > 0 && ++counter % this.logFrequency == 0) { logger.info("Processed {} features.", counter); } if (!Optional.ofNullable(object.jsonObject().get(TYPE)) .filter(jsonObject -> jsonObject.getAsString().equals(FEATURE)).isPresent()) { throw new CoreException("Illegal GeoJson Type for Feature collection"); } features.add(object.jsonObject()); } result.add(FEATURES, features); return new GeoJsonObject(result); }
geometry.add(COORDINATES, coordinates); result.add(GEOMETRY, geometry); return new GeoJsonObject(result);
result.add(GEOMETRY, geometry); result.add(PROPERTIES, new JsonObject()); return new GeoJsonObject(result);
geometry.add(COORDINATES, coordinates); result.add(GEOMETRY, geometry); return new GeoJsonObject(result);
return new GeoJsonObject(result);
result.add(GEOMETRY, geometryCollection); return new GeoJsonObject(result);