org.springframework.data.geo.Circle Java Examples
The following examples show how to use
org.springframework.data.geo.Circle.
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: DerivedQueryCreatorTest.java From spring-data with Apache License 2.0 | 6 votes |
@Test public void findWithinOrNearTest() { final List<Customer> toBeRetrieved = new LinkedList<>(); final Customer customer1 = new Customer("---", "", 0); customer1.setLocation(new int[] { 45, 2 }); toBeRetrieved.add(customer1); final Customer customer2 = new Customer("+++", "", 0); customer2.setLocation(new int[] { 60, 1 }); toBeRetrieved.add(customer2); repository.saveAll(toBeRetrieved); final Customer customer3 = new Customer("---", "", 0); customer3.setLocation(new int[] { 0, 180 }); repository.save(customer3); final double distanceInMeters = convertAngleToDistance(30); final Distance distance = new Distance(distanceInMeters / 1000, Metrics.KILOMETERS); final Circle circle = new Circle(new Point(0, 20), distance); final Iterable<Customer> retrieved = repository.findByLocationWithinOrNameAndLocationNear(circle, "+++", new Point(0, 0)); assertTrue(equals(toBeRetrieved, retrieved, cmp, eq, false)); }
Example #2
Source File: Neo4jQuerySupport.java From sdn-rx with Apache License 2.0 | 5 votes |
private Map<String, Object> convertCircle(Circle circle) { Map<String, Object> map = new HashMap<>(); map.put("x", convertParameter(circle.getCenter().getX())); map.put("y", convertParameter(circle.getCenter().getY())); map.put("radius", convertParameter(calculateDistanceInMeter(circle.getRadius()))); return map; }
Example #3
Source File: QueryIT.java From spring-data-hazelcast with Apache License 2.0 | 5 votes |
@Test public void findByLocationNearWithShape() { final City mumbai = new City("1001", "Mumbai", new Point(19.0990358,72.9612976)); final City pune = new City("1002", "Pune", new Point(18.5247663,73.792756)); final City bangalore = new City("1003", "Bangalore", new Point(12.9542944,77.4905127)); final Point solapur = new Point(17.661548,75.8835121); final Circle circle100 = new Circle(solapur, new Distance(100, Metrics.KILOMETERS)); final Circle circle250 = new Circle(solapur, new Distance(250, Metrics.KILOMETERS)); final Circle circle350 = new Circle(solapur, new Distance(350, Metrics.KILOMETERS)); this.cityMap.put(mumbai.getId(), mumbai); this.cityMap.put(pune.getId(), pune); this.cityMap.put(bangalore.getId(), bangalore); List<City> matches = this.cityRepository.findByLocationWithin(circle100); int len = matches.size(); assertThat("Nothing should returned", len, equalTo(0)); matches = this.cityRepository.findByLocationWithin(circle250); len = matches.size(); assertThat("Pune should return", len, equalTo(1)); assertThat("Pune should return", matches.get(0), equalTo(pune)); matches = this.cityRepository.findByLocationWithin(circle350); len = matches.size(); assertThat("Pune and Mumbai should return", len, equalTo(2)); assertThat("Pune and Mumbai should return", matches, containsInAnyOrder(pune, mumbai)); this.cityMap.remove(mumbai.getId()); this.cityMap.remove(pune.getId()); this.cityMap.remove(bangalore.getId()); }
Example #4
Source File: RedissonConnection.java From redisson with Apache License 2.0 | 5 votes |
@Override public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within, GeoRadiusCommandArgs args) { List<Object> params = new ArrayList<Object>(); params.add(key); params.add(convert(within.getCenter().getX())); params.add(convert(within.getCenter().getY())); params.add(within.getRadius().getValue()); params.add(within.getRadius().getMetric().getAbbreviation()); RedisCommand<GeoResults<GeoLocation<byte[]>>> command; if (args.getFlags().contains(GeoRadiusCommandArgs.Flag.WITHCOORD)) { command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUS", postitionDecoder); params.add("WITHCOORD"); } else { MultiDecoder<GeoResults<GeoLocation<byte[]>>> distanceDecoder = new ListMultiDecoder2(new GeoResultsDecoder(within.getRadius().getMetric()), new GeoDistanceDecoder()); command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUS", distanceDecoder); params.add("WITHDIST"); } if (args.getLimit() != null) { params.add("COUNT"); params.add(args.getLimit()); } if (args.getSortDirection() != null) { params.add(args.getSortDirection().name()); } return read(key, ByteArrayCodec.INSTANCE, command, params.toArray()); }
Example #5
Source File: RedissonConnection.java From redisson with Apache License 2.0 | 5 votes |
@Override public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within) { RedisCommand<GeoResults<GeoLocation<byte[]>>> command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUS", new GeoResultsDecoder()); return read(key, ByteArrayCodec.INSTANCE, command, key, convert(within.getCenter().getX()), convert(within.getCenter().getY()), within.getRadius().getValue(), within.getRadius().getMetric().getAbbreviation()); }
Example #6
Source File: RedissonConnection.java From redisson with Apache License 2.0 | 5 votes |
@Override public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within, GeoRadiusCommandArgs args) { List<Object> params = new ArrayList<Object>(); params.add(key); params.add(convert(within.getCenter().getX())); params.add(convert(within.getCenter().getY())); params.add(within.getRadius().getValue()); params.add(within.getRadius().getMetric().getAbbreviation()); RedisCommand<GeoResults<GeoLocation<byte[]>>> command; if (args.getFlags().contains(GeoRadiusCommandArgs.Flag.WITHCOORD)) { command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUS", postitionDecoder); params.add("WITHCOORD"); } else { MultiDecoder<GeoResults<GeoLocation<byte[]>>> distanceDecoder = new ListMultiDecoder2(new GeoResultsDecoder(within.getRadius().getMetric()), new GeoDistanceDecoder()); command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUS", distanceDecoder); params.add("WITHDIST"); } if (args.getLimit() != null) { params.add("COUNT"); params.add(args.getLimit()); } if (args.getSortDirection() != null) { params.add(args.getSortDirection().name()); } return read(key, ByteArrayCodec.INSTANCE, command, params.toArray()); }
Example #7
Source File: RedissonConnection.java From redisson with Apache License 2.0 | 5 votes |
@Override public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within) { RedisCommand<GeoResults<GeoLocation<byte[]>>> command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUS", new GeoResultsDecoder()); return read(key, ByteArrayCodec.INSTANCE, command, key, convert(within.getCenter().getX()), convert(within.getCenter().getY()), within.getRadius().getValue(), within.getRadius().getMetric().getAbbreviation()); }
Example #8
Source File: RedissonConnection.java From redisson with Apache License 2.0 | 5 votes |
@Override public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within, GeoRadiusCommandArgs args) { List<Object> params = new ArrayList<Object>(); params.add(key); params.add(convert(within.getCenter().getX())); params.add(convert(within.getCenter().getY())); params.add(within.getRadius().getValue()); params.add(within.getRadius().getMetric().getAbbreviation()); RedisCommand<GeoResults<GeoLocation<byte[]>>> command; if (args.getFlags().contains(GeoRadiusCommandArgs.Flag.WITHCOORD)) { command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUS", postitionDecoder); params.add("WITHCOORD"); } else { MultiDecoder<GeoResults<GeoLocation<byte[]>>> distanceDecoder = new ListMultiDecoder2(new GeoResultsDecoder(within.getRadius().getMetric()), new GeoDistanceDecoder()); command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUS", distanceDecoder); params.add("WITHDIST"); } if (args.getLimit() != null) { params.add("COUNT"); params.add(args.getLimit()); } if (args.getSortDirection() != null) { params.add(args.getSortDirection().name()); } return read(key, ByteArrayCodec.INSTANCE, command, params.toArray()); }
Example #9
Source File: RedissonConnection.java From redisson with Apache License 2.0 | 5 votes |
@Override public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within) { RedisCommand<GeoResults<GeoLocation<byte[]>>> command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUS", new GeoResultsDecoder()); return read(key, ByteArrayCodec.INSTANCE, command, key, convert(within.getCenter().getX()), convert(within.getCenter().getY()), within.getRadius().getValue(), within.getRadius().getMetric().getAbbreviation()); }
Example #10
Source File: RedissonConnection.java From redisson with Apache License 2.0 | 5 votes |
@Override public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within, GeoRadiusCommandArgs args) { List<Object> params = new ArrayList<Object>(); params.add(key); params.add(convert(within.getCenter().getX())); params.add(convert(within.getCenter().getY())); params.add(within.getRadius().getValue()); params.add(within.getRadius().getMetric().getAbbreviation()); RedisCommand<GeoResults<GeoLocation<byte[]>>> command; if (args.getFlags().contains(GeoRadiusCommandArgs.Flag.WITHCOORD)) { command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUS", postitionDecoder); params.add("WITHCOORD"); } else { MultiDecoder<GeoResults<GeoLocation<byte[]>>> distanceDecoder = new ListMultiDecoder2(new GeoResultsDecoder(within.getRadius().getMetric()), new GeoDistanceDecoder()); command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUS", distanceDecoder); params.add("WITHDIST"); } if (args.getLimit() != null) { params.add("COUNT"); params.add(args.getLimit()); } if (args.getSortDirection() != null) { params.add(args.getSortDirection().name()); } return read(key, ByteArrayCodec.INSTANCE, command, params.toArray()); }
Example #11
Source File: RedissonConnection.java From redisson with Apache License 2.0 | 5 votes |
@Override public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within) { RedisCommand<GeoResults<GeoLocation<byte[]>>> command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUS", new GeoResultsDecoder()); return read(key, ByteArrayCodec.INSTANCE, command, key, convert(within.getCenter().getX()), convert(within.getCenter().getY()), within.getRadius().getValue(), within.getRadius().getMetric().getAbbreviation()); }
Example #12
Source File: PersonRepositoryTests.java From spring-data-examples with Apache License 2.0 | 5 votes |
/** * Find entity by a {@link GeoIndexed} property on an embedded entity. */ @Test public void findByGeoLocationProperty() { Address winterfell = new Address(); winterfell.setCountry("the north"); winterfell.setCity("winterfell"); winterfell.setLocation(new Point(52.9541053, -1.2401016)); eddard.setAddress(winterfell); Address casterlystein = new Address(); casterlystein.setCountry("Westerland"); casterlystein.setCity("Casterlystein"); casterlystein.setLocation(new Point(51.5287352, -0.3817819)); robb.setAddress(casterlystein); flushTestUsers(); Circle innerCircle = new Circle(new Point(51.8911912, -0.4979756), new Distance(50, Metrics.KILOMETERS)); List<Person> eddardStark = repository.findByAddress_LocationWithin(innerCircle); assertThat(eddardStark).containsOnly(robb); Circle biggerCircle = new Circle(new Point(51.8911912, -0.4979756), new Distance(200, Metrics.KILOMETERS)); List<Person> eddardAndRobbStark = repository.findByAddress_LocationWithin(biggerCircle); assertThat(eddardAndRobbStark).hasSize(2).contains(robb, eddard); }
Example #13
Source File: GeoOperationsTests.java From spring-data-examples with Apache License 2.0 | 5 votes |
/** * Lookup points within a circle around coordinates. */ @Test public void geoRadius() { Circle circle = new Circle(new Point(13.583333, 37.316667), // new Distance(100, DistanceUnit.KILOMETERS)); GeoResults<GeoLocation<String>> result = geoOperations.geoRadius("Sicily", circle); assertThat(result).hasSize(2).extracting("content.name").contains("Arigento", "Palermo"); }
Example #14
Source File: BindParameterBinding.java From spring-data with Apache License 2.0 | 5 votes |
public int bindCircle( final Object value, final boolean shouldIgnoreCase, final UniqueCheck uniqueCheck, final int startIndex) { int index = startIndex; final Circle circle = (Circle) ignoreArgumentCase(value, shouldIgnoreCase); final Point center = circle.getCenter(); uniqueCheck.check(center); bind(index++, center.getY()); bind(index++, center.getX()); bind(index++, convertDistanceToMeters(circle.getRadius())); return index; }
Example #15
Source File: CypherQueryCreator.java From sdn-rx with Apache License 2.0 | 5 votes |
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 #16
Source File: Neo4jQuerySupport.java From sdn-rx with Apache License 2.0 | 5 votes |
/** * 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 #17
Source File: TracingRedisConnection.java From java-redis-client with Apache License 2.0 | 4 votes |
@Override public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within, GeoRadiusCommandArgs args) { return helper .doInScope(RedisCommand.GEORADIUS, key, () -> connection.geoRadius(key, within, args)); }
Example #18
Source File: TracingRedisConnection.java From java-redis-client with Apache License 2.0 | 4 votes |
@Override public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within) { return helper.doInScope(RedisCommand.GEORADIUS, key, () -> connection.geoRadius(key, within)); }
Example #19
Source File: TracingRedisConnection.java From java-redis-client with Apache License 2.0 | 4 votes |
@Override public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within, GeoRadiusCommandArgs args) { return helper .doInScope(RedisCommand.GEORADIUS, key, () -> connection.geoRadius(key, within, args)); }
Example #20
Source File: TracingRedisConnection.java From java-redis-client with Apache License 2.0 | 4 votes |
@Override public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within) { return helper.doInScope(RedisCommand.GEORADIUS, key, () -> connection.geoRadius(key, within)); }
Example #21
Source File: Criteria.java From dubbox with Apache License 2.0 | 2 votes |
/** * Creates new {@link Criteria.Predicate} for {@code !circle} for a * specified distance. The difference between this and * {@link #within(org.springframework.data.geo.Circle)} is this is * approximate while {@code within} is exact. * * @param circle * @return * @since 1.2 */ public Criteria near(Circle circle) { Assert.notNull(circle, "Circle for 'near' must not be 'null'."); return near(circle.getCenter(), circle.getRadius()); }
Example #22
Source File: Criteria.java From dubbox with Apache License 2.0 | 2 votes |
/** * Creates new {@link Criteria.Predicate} for {@code !geodist}. * * @param circle * @return * @since 1.2 */ public Criteria within(Circle circle) { Assert.notNull(circle, "Circle for 'within' must not be 'null'."); return within(circle.getCenter(), circle.getRadius()); }
Example #23
Source File: PersonRepository.java From spring-data-examples with Apache License 2.0 | votes |
List<Person> findByAddress_LocationWithin(Circle circle);
Example #24
Source File: CustomerRepository.java From spring-data with Apache License 2.0 | votes |
Iterable<Customer> findByLocationWithinOrNameAndLocationNear(Circle circle, String name, Point location2);
Example #25
Source File: PersonRepository.java From sdn-rx with Apache License 2.0 | votes |
List<PersonWithAllConstructor> findAllByPlaceWithin(Circle circle);
Example #26
Source File: CityRepository.java From spring-data-hazelcast with Apache License 2.0 | votes |
public List<City> findByLocationWithin(Circle circle);