org.springframework.data.geo.Polygon Java Examples

The following examples show how to use org.springframework.data.geo.Polygon. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BoundingBoxTest.java    From sdn-rx with Apache License 2.0 6 votes vote down vote up
private static Stream<Arguments> polygonsToTest() {
	return Stream.of(
		Arguments.of(
			new Polygon(new Point(1, 1), new Point(5, 1), new Point(5, 5), new Point(5, 1)),
			new Point(1, 1), new Point(5, 5)
		),
		Arguments.of(
			new Polygon(new Point(3, 6), new Point(6, 2), new Point(8, 3), new Point(8, 6), new Point(2, 9)),
			new Point(2, 2), new Point(8, 9)
		),
		Arguments.of(
			new Polygon(new Point(3, 4), new Point(7, 1), new Point(9, 4), new Point(10, 8), new Point(8, 10)),
			new Point(3, 1), new Point(10, 10)
		)
	);
}
 
Example #2
Source File: DerivedQueryCreatorTest.java    From spring-data with Apache License 2.0 6 votes vote down vote up
@Test
public void polygonTest() {
	final int[][] locations = { { 11, 31 }, { 20, 20 }, { 20, 40 }, { 70, 30 }, { 40, 10 }, { -10, -10 },
			{ -10, 20 }, { -10, 60 }, { 30, 50 }, { 10, 20 }, { 5, 30 } };
	final Customer[] customers = new Customer[11];
	final List<Customer> toBeRetrieved = new LinkedList<>();
	for (int i = 0; i < customers.length; ++i) {
		customers[i] = new Customer("", "", 0);
		customers[i].setLocation(locations[i]);
		repository.save(customers[i]);
		if (i < 3) {
			toBeRetrieved.add(customers[i]);
		}
	}
	final Polygon polygon = new Polygon(new Point(0, 0), new Point(30, 60), new Point(50, 0), new Point(30, 10),
			new Point(30, 20));
	final List<Customer> retrieved = repository.findByLocationWithin(polygon);
	assertTrue(equals(toBeRetrieved, retrieved, cmp, eq, false));
}
 
Example #3
Source File: CypherQueryCreator.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
private Condition createWithinCondition(Neo4jPersistentProperty persistentProperty,
	Iterator<Object> actualParameters) {
	Parameter area = nextRequiredParameter(actualParameters);
	if (area.hasValueOfType(Circle.class)) {
		// We don't know the CRS of the point, so we assume the same as the reference toCypherProperty
		Expression referencePoint = point(Cypher.mapOf(
			"x", createCypherParameter(area.nameOrIndex + ".x", false),
			"y", createCypherParameter(area.nameOrIndex + ".y", false),
			"srid", Cypher.property(toCypherProperty(persistentProperty, false), "srid"))
		);
		Expression distanceFunction = Functions
			.distance(toCypherProperty(persistentProperty, false), referencePoint);
		return distanceFunction.lte(createCypherParameter(area.nameOrIndex + ".radius", false));
	} else if (area.hasValueOfType(BoundingBox.class) || area.hasValueOfType(Box.class)) {
		Expression llx = createCypherParameter(area.nameOrIndex + ".llx", false);
		Expression lly = createCypherParameter(area.nameOrIndex + ".lly", false);
		Expression urx = createCypherParameter(area.nameOrIndex + ".urx", false);
		Expression ury = createCypherParameter(area.nameOrIndex + ".ury", false);

		Expression x = Cypher.property(toCypherProperty(persistentProperty, false), "x");
		Expression y = Cypher.property(toCypherProperty(persistentProperty, false), "y");

		return llx.lte(x).and(x.lte(urx)).and(lly.lte(y)).and(y.lte(ury));
	} else if (area.hasValueOfType(Polygon.class)) {
		throw new IllegalArgumentException(String.format("The WITHIN operation does not support a %s. You might want to pass a bounding box instead: %s.of(polygon).", Polygon.class, BoundingBox.class));
	} else {
		throw new IllegalArgumentException(String.format("The WITHIN operation requires an area of type %s or %s.", Circle.class, Box.class));
	}
}
 
Example #4
Source File: BoundingBoxTest.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@ParameterizedTest
@MethodSource("polygonsToTest")
void builderShouldWorkForPolygons(Polygon p, Point ll, Point ur) {

	BoundingBox boundingBox = BoundingBox.of(p);
	assertThat(boundingBox.getLowerLeft()).isEqualTo(ll);
	assertThat(boundingBox.getUpperRight()).isEqualTo(ur);
}
 
Example #5
Source File: BindParameterBinding.java    From spring-data with Apache License 2.0 5 votes vote down vote up
public int bindPolygon(final Object value, final boolean shouldIgnoreCase, final int startIndex) {
	int index = startIndex;
	final Polygon polygon = (Polygon) ignoreArgumentCase(value, shouldIgnoreCase);
	final List<List<Double>> points = new LinkedList<>();
	polygon.forEach(p -> {
		final List<Double> point = new LinkedList<>();
		point.add(p.getY());
		point.add(p.getX());
		points.add(point);
	});
	bind(index++, points);
	return index;
}
 
Example #6
Source File: BoundingBox.java    From sdn-rx with Apache License 2.0 2 votes vote down vote up
public static BoundingBox of(Polygon p) {

		return buildFrom(p.getPoints());
	}
 
Example #7
Source File: StoreRepository.java    From spring-data-examples with Apache License 2.0 2 votes vote down vote up
/**
 * Returns all {@link Store}s located withing the given {@link Polygon}.
 *
 * @param polygon must not be {@literal null}.
 * @return
 */
List<Store> findByLocationWithin(Polygon polygon);
 
Example #8
Source File: StoreRepositoryTests.java    From spring-data-examples with Apache License 2.0 2 votes vote down vote up
/**
 * The legacy format alternative to {@link #findWithinGeoJsonPolygon()}.
 *
 * <pre>
 * <code>
 * {
 *   "location" : {
 *     "$geoWithin" : {
 *        "$polygon" : [ [ -73.992514, 40.758934 ] , [ -73.961138, 40.760348 ] , [ -73.991658, 40.730006 ] ]
 *     }
 *   }
 * }
 * </code>
 *
 * <pre>
 */
@Test
public void findWithinLegacyPolygon() {
	repository.findByLocationWithin(new Polygon(new Point(-73.992514, 40.758934), new Point(-73.961138, 40.760348),
			new Point(-73.991658, 40.730006))).forEach(System.out::println);
}
 
Example #9
Source File: PersonRepository.java    From sdn-rx with Apache License 2.0 votes vote down vote up
List<PersonWithAllConstructor> findAllByPlaceWithin(Polygon polygon); 
Example #10
Source File: CustomerRepository.java    From spring-data with Apache License 2.0 votes vote down vote up
List<Customer> findByLocationWithin(Polygon polygon);