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);
}
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);
}
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);
}
Aggregations