use of com.mongodb.client.model.geojson.Point in project morphia by mongodb.
the class TestGeoQueries method minDistance.
@Test
public void minDistance() {
// given
Datastore datastore = getDs();
City london = new City("London", new Point(new Position(51.5286416, -0.1015987)));
datastore.save(london);
datastore.save(List.of(new City("Manchester", new Point(new Position(53.4722454, -2.2235922))), new City("Sevilla", new Point(new Position(37.3753708, -5.9550582)))));
getDs().ensureIndexes();
final Point searchPoint = new Point(new Position(50, 0.1278));
assertThat(datastore.find(City.class).filter(near("location", searchPoint).maxDistance(200000D).minDistance(195000D)).iterator().toList().size(), is(0));
assertThat(datastore.find(City.class).filter(nearSphere("location", searchPoint).maxDistance(200000D).minDistance(195000D)).iterator().toList().size(), is(0));
}
use of com.mongodb.client.model.geojson.Point in project morphia by mongodb.
the class TestGeoQueries method testWithinRadiusSphere.
@Test
public void testWithinRadiusSphere() {
final Place place1 = new Place("place1", new double[] { 1, 1 });
getDs().save(place1);
final Place found = getDs().find(Place.class).filter(centerSphere("loc", new Point(new Position(0, 1)), 1)).iterator(new FindOptions().limit(1)).next();
Assert.assertNotNull(found);
}
use of com.mongodb.client.model.geojson.Point in project morphia by mongodb.
the class TestIndexes method shouldErrorWhenCreatingA2dIndexOnGeoJson.
@Test(expectedExceptions = MongoCommandException.class)
public void shouldErrorWhenCreatingA2dIndexOnGeoJson() {
// given
Place2D pointB = new Place2D(new Point(new Position(3.1, 7.5)), "Point B");
getDs().save(pointB);
// when
getDs().ensureIndexes();
// "location object expected, location array not in correct format", code : 13654
}
use of com.mongodb.client.model.geojson.Point in project mongo-java-driver by mongodb.
the class GeometryEncoderHelper method encodeGeometry.
@SuppressWarnings("unchecked")
static void encodeGeometry(final BsonWriter writer, final Geometry value, final EncoderContext encoderContext, final CodecRegistry registry) {
writer.writeStartDocument();
writer.writeString("type", value.getType().getTypeName());
if (value instanceof GeometryCollection) {
writer.writeName("geometries");
encodeGeometryCollection(writer, (GeometryCollection) value, encoderContext, registry);
} else {
writer.writeName("coordinates");
if (value instanceof Point) {
encodePoint(writer, (Point) value);
} else if (value instanceof MultiPoint) {
encodeMultiPoint(writer, (MultiPoint) value);
} else if (value instanceof Polygon) {
encodePolygon(writer, (Polygon) value);
} else if (value instanceof MultiPolygon) {
encodeMultiPolygon(writer, (MultiPolygon) value);
} else if (value instanceof LineString) {
encodeLineString(writer, (LineString) value);
} else if (value instanceof MultiLineString) {
encodeMultiLineString(writer, (MultiLineString) value);
} else {
throw new CodecConfigurationException(format("Unsupported Geometry: %s", value));
}
}
encodeCoordinateReferenceSystem(writer, value, encoderContext, registry);
writer.writeEndDocument();
}
use of com.mongodb.client.model.geojson.Point 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);
}
Aggregations