Search in sources :

Example 1 with Circle

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

the class GeoConvertersUnitTests method convertsCircleToDocumentAndBackCorrectlyMilesDistance.

// DATAMONGO-858
@Test
public void convertsCircleToDocumentAndBackCorrectlyMilesDistance() {
    Distance radius = new Distance(3, Metrics.MILES);
    Circle circle = new Circle(new Point(1, 2), radius);
    Document document = CircleToDocumentConverter.INSTANCE.convert(circle);
    Circle result = DocumentToCircleConverter.INSTANCE.convert(document);
    assertThat(result).isEqualTo(circle);
    assertThat(result.getRadius()).isEqualTo(radius);
}
Also used : Circle(org.springframework.data.geo.Circle) Point(org.springframework.data.geo.Point) Document(org.bson.Document) Distance(org.springframework.data.geo.Distance) Test(org.junit.jupiter.api.Test)

Example 2 with Circle

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

the class GeoConvertersUnitTests method convertsCircleCorrectlyWhenUsingNonDoubleForCoordinates.

// DATAMONGO-1607
@Test
public void convertsCircleCorrectlyWhenUsingNonDoubleForCoordinates() {
    Document circle = new Document();
    circle.put("center", new Document().append("x", 1).append("y", 2));
    circle.put("radius", 3L);
    assertThat(DocumentToCircleConverter.INSTANCE.convert(circle)).isEqualTo(new Circle(new Point(1, 2), new Distance(3)));
}
Also used : Circle(org.springframework.data.geo.Circle) Point(org.springframework.data.geo.Point) Document(org.bson.Document) Distance(org.springframework.data.geo.Distance) Test(org.junit.jupiter.api.Test)

Example 3 with Circle

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

the class MongoConvertersUnitTests method convertsCircleToDocumentAndBackCorrectly.

// DATAMONGO-858
@Test
void convertsCircleToDocumentAndBackCorrectly() {
    Circle circle = new Circle(new Point(1, 2), 3);
    Document document = GeoConverters.CircleToDocumentConverter.INSTANCE.convert(circle);
    Shape shape = GeoConverters.DocumentToCircleConverter.INSTANCE.convert(document);
    assertThat(shape).isEqualTo(circle);
}
Also used : Circle(org.springframework.data.geo.Circle) Shape(org.springframework.data.geo.Shape) Point(org.springframework.data.geo.Point) Document(org.bson.Document) Test(org.junit.jupiter.api.Test)

Example 4 with Circle

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

the class AbstractGeoSpatialTests method withinCenter.

@Test
public void withinCenter() {
    Circle circle = new Circle(-73.99171, 40.738868, 0.01);
    Query query = query(where("location").within(circle));
    List<Venue> venues = template.find(query, Venue.class);
    assertThat(venues).hasSize(7);
    assertThat(template.count(query, Venue.class)).isEqualTo(7);
}
Also used : Circle(org.springframework.data.geo.Circle) NearQuery(org.springframework.data.mongodb.core.query.NearQuery) Query(org.springframework.data.mongodb.core.query.Query) Venue(org.springframework.data.mongodb.core.Venue) Test(org.junit.Test)

Example 5 with Circle

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

the class AbstractGeoSpatialTests method withinCenterSphere.

@Test
public void withinCenterSphere() {
    Circle circle = new Circle(-73.99171, 40.738868, 0.003712240453784);
    Query query = query(where("location").withinSphere(circle));
    List<Venue> venues = template.find(query, Venue.class);
    assertThat(venues).hasSize(11);
    assertThat(template.count(query, Venue.class)).isEqualTo(11);
}
Also used : Circle(org.springframework.data.geo.Circle) NearQuery(org.springframework.data.mongodb.core.query.NearQuery) Query(org.springframework.data.mongodb.core.query.Query) Venue(org.springframework.data.mongodb.core.Venue) Test(org.junit.Test)

Aggregations

Circle (org.springframework.data.geo.Circle)12 Point (org.springframework.data.geo.Point)10 Test (org.junit.jupiter.api.Test)9 Document (org.bson.Document)4 Test (org.junit.Test)3 Distance (org.springframework.data.geo.Distance)3 Venue (org.springframework.data.mongodb.core.Venue)2 Document (org.springframework.data.mongodb.core.mapping.Document)2 NearQuery (org.springframework.data.mongodb.core.query.NearQuery)2 Query (org.springframework.data.mongodb.core.query.Query)2 StepVerifier (reactor.test.StepVerifier)2 Shape (org.springframework.data.geo.Shape)1 GeoJsonPoint (org.springframework.data.mongodb.core.geo.GeoJsonPoint)1 RedisGeoCommands (org.springframework.data.redis.connection.RedisGeoCommands)1 RedisTemplate (org.springframework.data.redis.core.RedisTemplate)1