Search in sources :

Example 16 with Position

use of com.mongodb.client.model.geojson.Position 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));
}
Also used : Datastore(dev.morphia.Datastore) Position(com.mongodb.client.model.geojson.Position) Point(com.mongodb.client.model.geojson.Point) Test(org.testng.annotations.Test)

Example 17 with Position

use of com.mongodb.client.model.geojson.Position 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);
}
Also used : FindOptions(dev.morphia.query.FindOptions) Position(com.mongodb.client.model.geojson.Position) Point(com.mongodb.client.model.geojson.Point) Test(org.testng.annotations.Test)

Example 18 with Position

use of com.mongodb.client.model.geojson.Position 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
}
Also used : Position(com.mongodb.client.model.geojson.Position) Point(com.mongodb.client.model.geojson.Point) Test(org.testng.annotations.Test)

Example 19 with Position

use of com.mongodb.client.model.geojson.Position in project spring-data-mongodb by spring-projects.

the class MongoTemplateMappingTests method writesAndReadsEntityWithNativeMongoGeoJsonTypesCorrectly.

// DATAMONGO-2357
@Test
public void writesAndReadsEntityWithNativeMongoGeoJsonTypesCorrectly() {
    WithMongoGeoJson source = new WithMongoGeoJson();
    source.id = "id-2";
    source.multiPolygon = 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)), WithMongoGeoJson.class)).isEqualTo(source);
}
Also used : MultiPolygon(com.mongodb.client.model.geojson.MultiPolygon) Position(com.mongodb.client.model.geojson.Position) PolygonCoordinates(com.mongodb.client.model.geojson.PolygonCoordinates) Test(org.junit.Test)

Example 20 with Position

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

the class GeometryCodecHelper method encodeLinearRing.

private static void encodeLinearRing(final List<Position> ring, final BsonWriter writer) {
    writer.writeStartArray();
    for (Position position : ring) {
        encodePosition(writer, position);
    }
    writer.writeEndArray();
}
Also used : Position(com.mongodb.client.model.geojson.Position)

Aggregations

Position (com.mongodb.client.model.geojson.Position)35 Point (com.mongodb.client.model.geojson.Point)23 Test (org.testng.annotations.Test)23 FindOptions (dev.morphia.query.FindOptions)16 CodecConfigurationException (org.bson.codecs.configuration.CodecConfigurationException)5 CoordinateReferenceSystem (com.mongodb.client.model.geojson.CoordinateReferenceSystem)3 LineString (com.mongodb.client.model.geojson.LineString)3 MultiLineString (com.mongodb.client.model.geojson.MultiLineString)3 NamedCoordinateReferenceSystem (com.mongodb.client.model.geojson.NamedCoordinateReferenceSystem)3 PolygonCoordinates (com.mongodb.client.model.geojson.PolygonCoordinates)3 MultiPoint (com.mongodb.client.model.geojson.MultiPoint)2 MultiPolygon (com.mongodb.client.model.geojson.MultiPolygon)2 Polygon (com.mongodb.client.model.geojson.Polygon)2 Datastore (dev.morphia.Datastore)2 GeoCity (dev.morphia.test.models.geo.GeoCity)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 List (java.util.List)1