Search in sources :

Example 1 with GeoJSONPoint

use of org.geotoolkit.internal.geojson.binding.GeoJSONGeometry.GeoJSONPoint in project geotoolkit by Geomatys.

the class GeoJSONWriter method writeGeoJSONGeometry.

/**
 * Write a GeoJSONGeometry
 *
 * @param jsonGeometry
 * @throws IOException
 */
private void writeGeoJSONGeometry(GeoJSONGeometry jsonGeometry) throws IOException {
    writer.writeStartObject();
    writer.writeStringField(TYPE, jsonGeometry.getType());
    if (jsonGeometry instanceof GeoJSONGeometryCollection) {
        List<GeoJSONGeometry> geometries = ((GeoJSONGeometryCollection) jsonGeometry).getGeometries();
        // "geometries" : [
        writer.writeArrayFieldStart(GEOMETRIES);
        for (GeoJSONGeometry geometry : geometries) {
            writeGeoJSONGeometry(geometry);
        }
        // "]"
        writer.writeEndArray();
    } else {
        // "coordinates" : [
        writer.writeArrayFieldStart(COORDINATES);
        if (jsonGeometry instanceof GeoJSONPoint) {
            writeArray(((GeoJSONPoint) jsonGeometry).getCoordinates());
        } else if (jsonGeometry instanceof GeoJSONLineString) {
            writeArray(((GeoJSONLineString) jsonGeometry).getCoordinates());
        } else if (jsonGeometry instanceof GeoJSONPolygon) {
            writeArray(((GeoJSONPolygon) jsonGeometry).getCoordinates());
        } else if (jsonGeometry instanceof GeoJSONMultiPoint) {
            writeArray(((GeoJSONMultiPoint) jsonGeometry).getCoordinates());
        } else if (jsonGeometry instanceof GeoJSONMultiLineString) {
            writeArray(((GeoJSONMultiLineString) jsonGeometry).getCoordinates());
        } else if (jsonGeometry instanceof GeoJSONMultiPolygon) {
            writeArray(((GeoJSONMultiPolygon) jsonGeometry).getCoordinates());
        } else {
            throw new IllegalArgumentException("Unsupported geometry type : " + jsonGeometry);
        }
        // "]"
        writer.writeEndArray();
    }
    writer.writeEndObject();
}
Also used : GeoJSONMultiLineString(org.geotoolkit.internal.geojson.binding.GeoJSONGeometry.GeoJSONMultiLineString) GeoJSONPoint(org.geotoolkit.internal.geojson.binding.GeoJSONGeometry.GeoJSONPoint) GeoJSONGeometryCollection(org.geotoolkit.internal.geojson.binding.GeoJSONGeometry.GeoJSONGeometryCollection) GeoJSONPolygon(org.geotoolkit.internal.geojson.binding.GeoJSONGeometry.GeoJSONPolygon) GeoJSONLineString(org.geotoolkit.internal.geojson.binding.GeoJSONGeometry.GeoJSONLineString) GeoJSONGeometry(org.geotoolkit.internal.geojson.binding.GeoJSONGeometry) GeoJSONMultiPoint(org.geotoolkit.internal.geojson.binding.GeoJSONGeometry.GeoJSONMultiPoint) GeoJSONMultiPolygon(org.geotoolkit.internal.geojson.binding.GeoJSONGeometry.GeoJSONMultiPolygon)

Aggregations

GeoJSONGeometry (org.geotoolkit.internal.geojson.binding.GeoJSONGeometry)1 GeoJSONGeometryCollection (org.geotoolkit.internal.geojson.binding.GeoJSONGeometry.GeoJSONGeometryCollection)1 GeoJSONLineString (org.geotoolkit.internal.geojson.binding.GeoJSONGeometry.GeoJSONLineString)1 GeoJSONMultiLineString (org.geotoolkit.internal.geojson.binding.GeoJSONGeometry.GeoJSONMultiLineString)1 GeoJSONMultiPoint (org.geotoolkit.internal.geojson.binding.GeoJSONGeometry.GeoJSONMultiPoint)1 GeoJSONMultiPolygon (org.geotoolkit.internal.geojson.binding.GeoJSONGeometry.GeoJSONMultiPolygon)1 GeoJSONPoint (org.geotoolkit.internal.geojson.binding.GeoJSONGeometry.GeoJSONPoint)1 GeoJSONPolygon (org.geotoolkit.internal.geojson.binding.GeoJSONGeometry.GeoJSONPolygon)1