org.springframework.data.geo.Box Java Examples

The following examples show how to use org.springframework.data.geo.Box. 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> boxesToTest() {
	return Stream.of(
		Arguments.of(
			new Box(new Point(1, 1), new Point(5, 5)),
			new Point(1, 1), new Point(5, 5)
		),
		Arguments.of(
			new Box(new Point(8, 3), new Point(2, 9)),
			new Point(2, 3), new Point(8, 9)
		),
		Arguments.of(
			new Box(new Point(3, 4), new Point(10, 8)),
			new Point(3, 4), new Point(10, 8)
		)
	);
}
 
Example #2
Source File: Neo4jQuerySupport.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
/**
 * Converts parameter as needed by the query generated, which is not covered by standard conversion services.
 *
 * @param parameter The parameter to fit into the generated query.
 * @return A parameter that fits the place holders of a generated query
 */
final Object convertParameter(Object parameter) {

	if (parameter == null) {
		// According to https://neo4j.com/docs/cypher-manual/current/syntax/working-with-null/#cypher-null-intro
		// it does not make any sense to continue if a `null` value gets into a comparison
		// but we just warn the users and do not throw an exception on `null`.
		log.warn("Do not use `null` as a property value for comparison."
			+ " It will always be false and return an empty result.");

		return Values.NULL;
	}

	// Maybe move all of those into Neo4jConverter at some point.
	if (parameter instanceof Range) {
		return convertRange((Range) parameter);
	} else if (parameter instanceof Distance) {
		return calculateDistanceInMeter((Distance) parameter);
	} else if (parameter instanceof Circle) {
		return convertCircle((Circle) parameter);
	} else if (parameter instanceof Instant) {
		return ((Instant) parameter).atOffset(ZoneOffset.UTC);
	} else if (parameter instanceof Box) {
		return convertBox((Box) parameter);
	} else if (parameter instanceof BoundingBox) {
		return convertBoundingBox((BoundingBox) parameter);
	}

	// Good hook to check the NodeManager whether the thing is an entity and we replace the value with a known id.
	return mappingContext.getConverter()
		.writeValueFromProperty(parameter, ClassTypeInformation.from(parameter.getClass()));
}
 
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("boxesToTest")
void builderShouldWorkForBoxes(Box b, Point ll, Point ur) {

	BoundingBox boundingBox = BoundingBox.of(b);
	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 bindBox(final Object value, final boolean shouldIgnoreCase, final int startIndex) {
	int index = startIndex;
	final Box box = (Box) ignoreArgumentCase(value, shouldIgnoreCase);
	final Point first = box.getFirst();
	final Point second = box.getSecond();
	final double minLatitude = Math.min(first.getY(), second.getY());
	final double maxLatitude = Math.max(first.getY(), second.getY());
	final double minLongitude = Math.min(first.getX(), second.getX());
	final double maxLongitude = Math.max(first.getX(), second.getX());
	bind(index++, minLatitude);
	bind(index++, maxLatitude);
	bind(index++, minLongitude);
	bind(index++, maxLongitude);
	return index;
}
 
Example #6
Source File: DerivedQueryCreatorTest.java    From spring-data with Apache License 2.0 5 votes vote down vote up
@Test
public void findByLocationWithinBoxTest() {
	final List<Customer> toBeRetrieved = new LinkedList<>();
	final Customer customer1 = new Customer("", "", 0);
	customer1.setLocation(new int[] { 10, 10 });
	toBeRetrieved.add(customer1);
	repository.saveAll(toBeRetrieved);
	final Customer customer2 = new Customer("", "", 0);
	customer2.setLocation(new int[] { 0, 0 });
	repository.save(customer2);
	final Customer customer3 = new Customer("", "", 0);
	customer3.setLocation(new int[] { 0, 10 });
	repository.save(customer3);
	final Customer customer4 = new Customer("", "", 0);
	customer4.setLocation(new int[] { 0, 20 });
	repository.save(customer4);
	final Customer customer5 = new Customer("", "", 0);
	customer5.setLocation(new int[] { 10, 0 });
	repository.save(customer5);
	final Customer customer6 = new Customer("", "", 0);
	customer6.setLocation(new int[] { 10, 20 });
	repository.save(customer6);
	final Customer customer7 = new Customer("", "", 0);
	customer7.setLocation(new int[] { 20, 0 });
	repository.save(customer7);
	final Customer customer8 = new Customer("", "", 0);
	customer8.setLocation(new int[] { 20, 10 });
	repository.save(customer8);
	final Customer customer9 = new Customer("", "", 0);
	customer9.setLocation(new int[] { 20, 20 });
	repository.save(customer9);
	final List<Customer> retrieved = repository.findByLocationWithin(new Box(new Point(5, 5), new Point(15, 15)));
	assertTrue(equals(toBeRetrieved, retrieved, cmp, eq, false));
}
 
Example #7
Source File: SolrQueryCreator.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private Criteria createNearCriteria(Iterator<?> parameters, Criteria criteria) {
	Object value = getBindableValue((BindableSolrParameter) parameters.next());
	if (value instanceof Box) {
		return criteria.near((Box) value);
	} else {
		return criteria.near((Point) value, (Distance) getBindableValue((BindableSolrParameter) parameters.next()));
	}
}
 
Example #8
Source File: QueryParserBase.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Override
public Object doProcess(Predicate predicate, Field field) {
	String nearFragment;
	Object[] args = (Object[]) predicate.getValue();
	if (args[0] instanceof Box) {
		Box box = (Box) args[0];
		nearFragment = field.getName() + ":[";
		nearFragment += createRangeFragment(box.getFirst(), box.getSecond());
		nearFragment += "]";
	} else {
		nearFragment = createSpatialFunctionFragment(field.getName(),
				(org.springframework.data.geo.Point) args[0], (Distance) args[1], "bbox");
	}
	return nearFragment;
}
 
Example #9
Source File: Neo4jQuerySupport.java    From sdn-rx with Apache License 2.0 4 votes vote down vote up
private Map<String, Object> convertBox(Box box) {

		BoundingBox boundingBox = BoundingBox.of(box);
		return convertBoundingBox(boundingBox);
	}
 
Example #10
Source File: Crotch.java    From dubbox with Apache License 2.0 4 votes vote down vote up
@Override
public Crotch near(Box box) {
	mostRecentSibling.near(box);
	return this;
}
 
Example #11
Source File: BoundingBox.java    From sdn-rx with Apache License 2.0 2 votes vote down vote up
public static BoundingBox of(Box b) {

		return buildFrom(Arrays.asList(b.getFirst(), b.getSecond()));
	}
 
Example #12
Source File: Criteria.java    From dubbox with Apache License 2.0 2 votes vote down vote up
/**
 * Creates new {@link Criteria.Predicate} for {@code !bbox} with exact
 * coordinates
 *
 * @param box
 * @return
 */
public Criteria near(Box box) {
	predicates.add(new Predicate(OperationKey.NEAR, new Object[] { box }));
	return this;
}
 
Example #13
Source File: PersonRepository.java    From sdn-rx with Apache License 2.0 votes vote down vote up
List<PersonWithAllConstructor> findAllByPlaceWithin(Box box); 
Example #14
Source File: CustomerRepository.java    From spring-data with Apache License 2.0 votes vote down vote up
List<Customer> findByLocationWithin(Box box); 
Example #15
Source File: Node.java    From dubbox with Apache License 2.0 votes vote down vote up
public abstract Node near(Box box);