Search in sources :

Example 6 with Box

use of org.springframework.data.geo.Box in project spring-data-mongodb by spring-projects.

the class MapReduceTests method mapReduceShouldUseQueryMapper.

// DATAMONGO-938
@Test
public void mapReduceShouldUseQueryMapper() {
    MongoCollection<Document> c = mongoTemplate.getDb().getCollection("jmrWithGeo", Document.class);
    c.insertOne(new Document("x", Arrays.asList("a", "b")).append("loc", Arrays.<Double>asList(0D, 0D)));
    c.insertOne(new Document("x", Arrays.asList("b", "c")).append("loc", Arrays.<Double>asList(0D, 0D)));
    c.insertOne(new Document("x", Arrays.asList("c", "d")).append("loc", Arrays.<Double>asList(0D, 0D)));
    Query query = new Query(where("x").ne(new String[] { "a", "b" }).and("loc").within(new Box(new double[] { 0, 0 }, new double[] { 1, 1 })));
    MapReduceResults<ValueObject> results = template.mapReduce(query, "jmrWithGeo", mapFunction, reduceFunction, ValueObject.class);
    Map<String, Float> m = copyToMap(results);
    assertEquals(3, m.size());
    assertEquals(1, m.get("b").intValue());
    assertEquals(2, m.get("c").intValue());
    assertEquals(1, m.get("d").intValue());
}
Also used : Query(org.springframework.data.mongodb.core.query.Query) Box(org.springframework.data.geo.Box) Document(org.bson.Document) Test(org.junit.Test)

Example 7 with Box

use of org.springframework.data.geo.Box in project spring-data-mongodb by spring-projects.

the class MappingMongoConverterUnitTests method shouldWriteEntityWithGeoBoxCorrectly.

// DATAMONGO-858
@Test
public void shouldWriteEntityWithGeoBoxCorrectly() {
    ClassWithGeoBox object = new ClassWithGeoBox();
    object.box = new Box(new Point(1, 2), new Point(3, 4));
    org.bson.Document document = new org.bson.Document();
    converter.write(object, document);
    assertThat(document, is(notNullValue()));
    assertThat(document.get("box"), is(instanceOf(org.bson.Document.class)));
    assertThat(document.get("box"), is((Object) new org.bson.Document().append("first", toDocument(object.box.getFirst())).append("second", toDocument(object.box.getSecond()))));
}
Also used : Box(org.springframework.data.geo.Box) Point(org.springframework.data.geo.Point) Document(org.springframework.data.mongodb.core.mapping.Document) Test(org.junit.Test)

Example 8 with Box

use of org.springframework.data.geo.Box in project spring-data-mongodb by spring-projects.

the class MongoConvertersUnitTests method convertsBoxToDocumentAndBackCorrectly.

// DATAMONGO-858
@Test
public void convertsBoxToDocumentAndBackCorrectly() {
    Box box = new Box(new Point(1, 2), new Point(3, 4));
    Document document = GeoConverters.BoxToDocumentConverter.INSTANCE.convert(box);
    Shape shape = GeoConverters.DocumentToBoxConverter.INSTANCE.convert(document);
    assertThat(shape, is((org.springframework.data.geo.Shape) box));
}
Also used : Shape(org.springframework.data.geo.Shape) Box(org.springframework.data.geo.Box) Point(org.springframework.data.geo.Point) Document(org.bson.Document) Test(org.junit.Test)

Example 9 with Box

use of org.springframework.data.geo.Box in project nixmash-blog by mintster.

the class SolrLocationTests method testFindByNearWithBox.

@Test
public void testFindByNearWithBox() {
    // locatedinYonkers location: 22.17614, -90.87341
    List<Product> found = repo.findByLocationNear(new Box(new Point(22, -91), new Point(23, -90)));
    locationAsserts(found);
}
Also used : Product(com.nixmash.blog.solr.model.Product) Box(org.springframework.data.geo.Box) Point(org.springframework.data.geo.Point) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)9 Box (org.springframework.data.geo.Box)9 Point (org.springframework.data.geo.Point)7 Document (org.bson.Document)4 Document (org.springframework.data.mongodb.core.mapping.Document)2 Product (com.nixmash.blog.solr.model.Product)1 List (java.util.List)1 Shape (org.springframework.data.geo.Shape)1 Venue (org.springframework.data.mongodb.core.Venue)1 GeoJsonPoint (org.springframework.data.mongodb.core.geo.GeoJsonPoint)1 GeoCommand (org.springframework.data.mongodb.core.query.GeoCommand)1 Query (org.springframework.data.mongodb.core.query.Query)1