Search in sources :

Example 6 with CoordinateReferenceSystem

use of com.mongodb.client.model.geojson.CoordinateReferenceSystem in project mongo-java-driver by mongodb.

the class GeometryDecoderHelper method decodeMultiLineString.

private static MultiLineString decodeMultiLineString(final BsonReader reader) {
    String type = null;
    List<List<Position>> coordinates = null;
    CoordinateReferenceSystem crs = null;
    reader.readStartDocument();
    while (reader.readBsonType() != BsonType.END_OF_DOCUMENT) {
        String key = reader.readName();
        if (key.equals("type")) {
            type = reader.readString();
        } else if (key.equals("coordinates")) {
            coordinates = decodeMultiCoordinates(reader);
        } else if (key.equals("crs")) {
            crs = decodeCoordinateReferenceSystem(reader);
        } else {
            throw new CodecConfigurationException(format("Unexpected key '%s' found when decoding a GeoJSON Polygon", key));
        }
    }
    reader.readEndDocument();
    if (type == null) {
        throw new CodecConfigurationException("Invalid MultiLineString, document contained no type information.");
    } else if (!type.equals("MultiLineString")) {
        throw new CodecConfigurationException(format("Invalid MultiLineString, found type '%s'.", type));
    } else if (coordinates == null) {
        throw new CodecConfigurationException("Invalid MultiLineString, missing coordinates.");
    }
    return crs != null ? new MultiLineString(crs, coordinates) : new MultiLineString(coordinates);
}
Also used : MultiLineString(com.mongodb.client.model.geojson.MultiLineString) CodecConfigurationException(org.bson.codecs.configuration.CodecConfigurationException) ArrayList(java.util.ArrayList) List(java.util.List) LineString(com.mongodb.client.model.geojson.LineString) MultiLineString(com.mongodb.client.model.geojson.MultiLineString) CoordinateReferenceSystem(com.mongodb.client.model.geojson.CoordinateReferenceSystem) NamedCoordinateReferenceSystem(com.mongodb.client.model.geojson.NamedCoordinateReferenceSystem)

Example 7 with CoordinateReferenceSystem

use of com.mongodb.client.model.geojson.CoordinateReferenceSystem in project mongo-java-driver by mongodb.

the class GeometryDecoderHelper method decodePolygon.

private static Polygon decodePolygon(final BsonReader reader) {
    String type = null;
    PolygonCoordinates coordinates = null;
    CoordinateReferenceSystem crs = null;
    reader.readStartDocument();
    while (reader.readBsonType() != BsonType.END_OF_DOCUMENT) {
        String key = reader.readName();
        if (key.equals("type")) {
            type = reader.readString();
        } else if (key.equals("coordinates")) {
            coordinates = decodePolygonCoordinates(reader);
        } else if (key.equals("crs")) {
            crs = decodeCoordinateReferenceSystem(reader);
        } else {
            throw new CodecConfigurationException(format("Unexpected key '%s' found when decoding a GeoJSON Polygon", key));
        }
    }
    reader.readEndDocument();
    if (type == null) {
        throw new CodecConfigurationException("Invalid Polygon, document contained no type information.");
    } else if (!type.equals("Polygon")) {
        throw new CodecConfigurationException(format("Invalid Polygon, found type '%s'.", type));
    } else if (coordinates == null) {
        throw new CodecConfigurationException("Invalid Polygon, missing coordinates.");
    }
    return crs != null ? new Polygon(crs, coordinates) : new Polygon(coordinates);
}
Also used : CodecConfigurationException(org.bson.codecs.configuration.CodecConfigurationException) LineString(com.mongodb.client.model.geojson.LineString) MultiLineString(com.mongodb.client.model.geojson.MultiLineString) PolygonCoordinates(com.mongodb.client.model.geojson.PolygonCoordinates) CoordinateReferenceSystem(com.mongodb.client.model.geojson.CoordinateReferenceSystem) NamedCoordinateReferenceSystem(com.mongodb.client.model.geojson.NamedCoordinateReferenceSystem) Polygon(com.mongodb.client.model.geojson.Polygon) MultiPolygon(com.mongodb.client.model.geojson.MultiPolygon)

Example 8 with CoordinateReferenceSystem

use of com.mongodb.client.model.geojson.CoordinateReferenceSystem in project mongo-java-driver by mongodb.

the class GeometryDecoderHelper method decodeGeometryCollection.

private static GeometryCollection decodeGeometryCollection(final BsonReader reader) {
    String type = null;
    List<? extends Geometry> geometries = null;
    CoordinateReferenceSystem crs = null;
    reader.readStartDocument();
    while (reader.readBsonType() != BsonType.END_OF_DOCUMENT) {
        String key = reader.readName();
        if (key.equals("type")) {
            type = reader.readString();
        } else if (key.equals("geometries")) {
            geometries = decodeGeometries(reader);
        } else if (key.equals("crs")) {
            crs = decodeCoordinateReferenceSystem(reader);
        } else {
            throw new CodecConfigurationException(format("Unexpected key '%s' found when decoding a GeoJSON Polygon", key));
        }
    }
    reader.readEndDocument();
    if (type == null) {
        throw new CodecConfigurationException("Invalid GeometryCollection, document contained no type information.");
    } else if (!type.equals("GeometryCollection")) {
        throw new CodecConfigurationException(format("Invalid GeometryCollection, found type '%s'.", type));
    } else if (geometries == null) {
        throw new CodecConfigurationException("Invalid GeometryCollection, missing geometries.");
    }
    return crs != null ? new GeometryCollection(crs, geometries) : new GeometryCollection(geometries);
}
Also used : GeometryCollection(com.mongodb.client.model.geojson.GeometryCollection) CodecConfigurationException(org.bson.codecs.configuration.CodecConfigurationException) LineString(com.mongodb.client.model.geojson.LineString) MultiLineString(com.mongodb.client.model.geojson.MultiLineString) CoordinateReferenceSystem(com.mongodb.client.model.geojson.CoordinateReferenceSystem) NamedCoordinateReferenceSystem(com.mongodb.client.model.geojson.NamedCoordinateReferenceSystem)

Aggregations

CoordinateReferenceSystem (com.mongodb.client.model.geojson.CoordinateReferenceSystem)8 LineString (com.mongodb.client.model.geojson.LineString)7 MultiLineString (com.mongodb.client.model.geojson.MultiLineString)7 NamedCoordinateReferenceSystem (com.mongodb.client.model.geojson.NamedCoordinateReferenceSystem)7 CodecConfigurationException (org.bson.codecs.configuration.CodecConfigurationException)7 Position (com.mongodb.client.model.geojson.Position)3 MultiPoint (com.mongodb.client.model.geojson.MultiPoint)2 MultiPolygon (com.mongodb.client.model.geojson.MultiPolygon)2 PolygonCoordinates (com.mongodb.client.model.geojson.PolygonCoordinates)2 GeometryCollection (com.mongodb.client.model.geojson.GeometryCollection)1 Point (com.mongodb.client.model.geojson.Point)1 Polygon (com.mongodb.client.model.geojson.Polygon)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Codec (org.bson.codecs.Codec)1