use of com.mongodb.client.model.geojson.Geometry in project mongo-java-driver by mongodb.
the class GeometryDecoderHelper method decodeGeometry.
private static Geometry decodeGeometry(final BsonReader reader) {
String type = null;
BsonReaderMark mark = reader.getMark();
validateIsDocument(reader);
reader.readStartDocument();
while (reader.readBsonType() != BsonType.END_OF_DOCUMENT) {
String key = reader.readName();
if (key.equals("type")) {
type = reader.readString();
break;
} else {
reader.skipValue();
}
}
mark.reset();
if (type == null) {
throw new CodecConfigurationException("Invalid Geometry item, document contained no type information.");
}
Geometry geometry = null;
if (type.equals("Point")) {
geometry = decodePoint(reader);
} else if (type.equals("MultiPoint")) {
geometry = decodeMultiPoint(reader);
} else if (type.equals("Polygon")) {
geometry = decodePolygon(reader);
} else if (type.equals("MultiPolygon")) {
geometry = decodeMultiPolygon(reader);
} else if (type.equals("LineString")) {
geometry = decodeLineString(reader);
} else if (type.equals("MultiLineString")) {
geometry = decodeMultiLineString(reader);
} else if (type.equals("GeometryCollection")) {
geometry = decodeGeometryCollection(reader);
} else {
throw new CodecConfigurationException(format("Invalid Geometry item, found type '%s'.", type));
}
return geometry;
}
use of com.mongodb.client.model.geojson.Geometry in project mongo-java-driver by mongodb.
the class GeometryCollectionCodec method encode.
@Override
public void encode(final BsonWriter writer, final GeometryCollection value, final EncoderContext encoderContext) {
writer.writeStartDocument();
encodeType(writer, value);
writer.writeName("geometries");
writer.writeStartArray();
for (Geometry geometry : value.getGeometries()) {
encodeGeometry(writer, geometry, encoderContext);
}
writer.writeEndArray();
encodeCoordinateReferenceSystem(writer, value, encoderContext, registry);
writer.writeEndDocument();
}
use of com.mongodb.client.model.geojson.Geometry in project mongo-java-driver by mongodb.
the class GeometryDecoderHelper method decodeGeometries.
private static List<? extends Geometry> decodeGeometries(final BsonReader reader) {
validateIsArray(reader);
reader.readStartArray();
List<Geometry> values = new ArrayList<Geometry>();
while (reader.readBsonType() != BsonType.END_OF_DOCUMENT) {
Geometry geometry = decodeGeometry(reader);
values.add(geometry);
}
reader.readEndArray();
return values;
}
use of com.mongodb.client.model.geojson.Geometry in project mongo-java-driver by mongodb.
the class GeometryEncoderHelper method encodeGeometryCollection.
private static void encodeGeometryCollection(final BsonWriter writer, final GeometryCollection value, final EncoderContext encoderContext, final CodecRegistry registry) {
writer.writeStartArray();
for (Geometry geometry : value.getGeometries()) {
encodeGeometry(writer, geometry, encoderContext, registry);
}
writer.writeEndArray();
}
Aggregations