use of com.mongodb.client.model.geojson.Position in project mongo-java-driver by mongodb.
the class GeometryDecoderHelper method decodeLineString.
private static LineString decodeLineString(final BsonReader reader) {
String type = null;
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 = decodeCoordinates(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 LineString, document contained no type information.");
} else if (!type.equals("LineString")) {
throw new CodecConfigurationException(format("Invalid LineString, found type '%s'.", type));
} else if (coordinates == null) {
throw new CodecConfigurationException("Invalid LineString, missing coordinates.");
}
return crs != null ? new LineString(crs, coordinates) : new LineString(coordinates);
}
use of com.mongodb.client.model.geojson.Position in project mongo-java-driver by mongodb.
the class GeometryEncoderHelper method encodeLineString.
private static void encodeLineString(final BsonWriter writer, final LineString value) {
writer.writeStartArray();
for (Position position : value.getCoordinates()) {
encodePosition(writer, position);
}
writer.writeEndArray();
}
use of com.mongodb.client.model.geojson.Position in project spring-data-mongodb by spring-projects.
the class MongoTemplateMappingTests method writesAndReadsEntityWithOpenNativeMongoGeoJsonTypesCorrectly.
// DATAMONGO-2357
@Test
public void writesAndReadsEntityWithOpenNativeMongoGeoJsonTypesCorrectly() {
WithOpenMongoGeoJson source = new WithOpenMongoGeoJson();
source.id = "id-2";
source.geometry = new MultiPolygon(Arrays.asList(new PolygonCoordinates(Arrays.asList(new Position(0, 0), new Position(0, 1), new Position(1, 1), new Position(1, 0), new Position(0, 0)))));
template1.save(source);
assertThat(template1.findOne(query(where("id").is(source.id)), WithOpenMongoGeoJson.class)).isEqualTo(source);
}
use of com.mongodb.client.model.geojson.Position in project morphia by mongodb.
the class TestGeoQueries method testWithinRadius2.
@Test
public void testWithinRadius2() {
final Place place1 = new Place("place1", new double[] { 1, 1 });
getDs().save(place1);
final Place found = getDs().find(Place.class).filter(center("loc", new Point(new Position(0.5, 0.5)), 0.77)).iterator(new FindOptions().limit(1)).next();
Assert.assertNotNull(found);
}
use of com.mongodb.client.model.geojson.Position in project morphia by mongodb.
the class TestGeoQueries method testGeoWithinPolygon2.
@Test
public void testGeoWithinPolygon2() {
final Place place1 = new Place("place1", new double[] { 10, 1 });
getDs().save(place1);
final Place found = getDs().find(Place.class).filter(polygon("loc", new Point(new Position(0, 0)), new Point(new Position(0, 5)), new Point(new Position(2, 3)), new Point(new Position(2, 0)))).iterator(new FindOptions().limit(1)).tryNext();
Assert.assertNull(found);
}
Aggregations