use of org.springframework.data.geo.Polygon in project spring-data-mongodb by spring-projects.
the class MongoQueryCreatorUnitTests method shouldCreateWithinQueryCorrectly.
// DATAMONGO-1136
@Test
public void shouldCreateWithinQueryCorrectly() {
Point first = new Point(1, 1);
Point second = new Point(2, 2);
Point third = new Point(3, 3);
Shape shape = new Polygon(first, second, third);
PartTree tree = new PartTree("findByAddress_GeoWithin", User.class);
MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, shape), context);
Query query = creator.createQuery();
assertThat(query, is(query(where("address.geo").within(shape))));
}
use of org.springframework.data.geo.Polygon in project spring-data-mongodb by spring-projects.
the class AbstractGeoSpatialTests method withinPolygon.
@Test
public void withinPolygon() {
Point first = new Point(-73.99756, 40.73083);
Point second = new Point(-73.99756, 40.741404);
Point third = new Point(-73.988135, 40.741404);
Point fourth = new Point(-73.988135, 40.73083);
Polygon polygon = new Polygon(first, second, third, fourth);
List<Venue> venues = template.find(query(where("location").within(polygon)), Venue.class);
assertThat(venues.size(), is(4));
}
use of org.springframework.data.geo.Polygon in project spring-data-mongodb by spring-projects.
the class GeoConvertersUnitTests method convertsPolygonToDocumentAndBackCorrectly.
// DATAMONGO-858
@Test
public void convertsPolygonToDocumentAndBackCorrectly() {
Polygon polygon = new Polygon(new Point(1, 2), new Point(2, 3), new Point(3, 4), new Point(5, 6));
Document document = PolygonToDocumentConverter.INSTANCE.convert(polygon);
Polygon result = DocumentToPolygonConverter.INSTANCE.convert(document);
assertThat(result, is(polygon));
assertThat(result.getClass().equals(Polygon.class), is(true));
}
use of org.springframework.data.geo.Polygon in project spring-data-mongodb by spring-projects.
the class AbstractPersonRepositoryIntegrationTests method findsPeopleByLocationWithinPolygon.
@Test
public void findsPeopleByLocationWithinPolygon() {
Point point = new Point(-73.99171, 40.738868);
dave.setLocation(point);
repository.save(dave);
Point first = new Point(-78.99171, 35.738868);
Point second = new Point(-78.99171, 45.738868);
Point third = new Point(-68.99171, 45.738868);
Point fourth = new Point(-68.99171, 35.738868);
List<Person> result = repository.findByLocationWithin(new Polygon(first, second, third, fourth));
assertThat(result.size(), is(1));
assertThat(result, hasItem(dave));
}
use of org.springframework.data.geo.Polygon in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method shouldWriteEntityWithGeoPolygonCorrectly.
// DATAMONGO-858
@Test
public void shouldWriteEntityWithGeoPolygonCorrectly() {
ClassWithGeoPolygon object = new ClassWithGeoPolygon();
object.polygon = new Polygon(new Point(1, 2), new Point(3, 4), new Point(4, 5));
org.bson.Document document = new org.bson.Document();
converter.write(object, document);
assertThat(document, is(notNullValue()));
assertThat(document.get("polygon"), is(instanceOf(org.bson.Document.class)));
org.bson.Document polygonDoc = (org.bson.Document) document.get("polygon");
@SuppressWarnings("unchecked") List<org.bson.Document> points = (List<org.bson.Document>) polygonDoc.get("points");
assertThat(points, hasSize(3));
assertThat(points, Matchers.<org.bson.Document>hasItems(toDocument(object.polygon.getPoints().get(0)), toDocument(object.polygon.getPoints().get(1)), toDocument(object.polygon.getPoints().get(2))));
}
Aggregations