本文整理了Java中org.springframework.data.geo.Distance
类的一些代码示例,展示了Distance
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Distance
类的具体详情如下:
包路径:org.springframework.data.geo.Distance
类名称:Distance
[英]Value object to represent distances in a given metric.
[中]
代码示例来源:origin: spring-projects/spring-data-redis
@Override
public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, Distance radius) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(member, "Member must not be null!");
Assert.notNull(radius, "Radius must not be null!");
GeoUnit geoUnit = JedisConverters.toGeoUnit(radius.getMetric());
try {
return JedisConverters.geoRadiusResponseToGeoResultsConverter(radius.getMetric())
.convert(connection.getCluster().georadiusByMember(key, member, radius.getValue(), geoUnit));
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
}
代码示例来源:origin: spring-projects/spring-data-mongodb
/**
* Sets the maximum distance supplied in a given metric. Will normalize the distance but not reconfigure the query's
* result {@link Metric} if one was configured before.
*
* @param maxDistance
* @param metric must not be {@literal null}.
* @return
*/
public NearQuery maxDistance(double maxDistance, Metric metric) {
Assert.notNull(metric, "Metric must not be null!");
return maxDistance(new Distance(maxDistance, metric));
}
代码示例来源:origin: spring-projects/spring-data-mongodb
@Override
public Document convert(Circle source) {
if (source == null) {
return null;
}
Document result = new Document();
result.put("center", PointToDocumentConverter.INSTANCE.convert(source.getCenter()));
result.put("radius", source.getRadius().getNormalizedValue());
result.put("metric", source.getRadius().getMetric().toString());
return result;
}
}
代码示例来源:origin: redisson/redisson
@Override
public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, Distance radius) {
return read(key, ByteArrayCodec.INSTANCE, GEORADIUSBYMEMBER, key, member, radius.getValue(), radius.getMetric().getAbbreviation());
}
代码示例来源:origin: redisson/redisson
@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());
}
代码示例来源:origin: spring-projects/spring-data-redis
@Override
public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(within, "Within must not be null!");
try {
return JedisConverters.geoRadiusResponseToGeoResultsConverter(within.getRadius().getMetric())
.convert(connection.getCluster().georadius(key, within.getCenter().getX(), within.getCenter().getY(),
within.getRadius().getValue(), JedisConverters.toGeoUnit(within.getRadius().getMetric())));
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
}
代码示例来源:origin: spring-projects/spring-data-mongodb
/**
* Creates a Sphere around the given center {@link Point} with the given radius.
*
* @param center must not be {@literal null}.
* @param radius must not be {@literal null}.
*/
@PersistenceConstructor
public Sphere(Point center, Distance radius) {
Assert.notNull(center, "Center point must not be null!");
Assert.notNull(radius, "Radius must not be null!");
Assert.isTrue(radius.getValue() >= 0, "Radius must not be negative!");
this.center = center;
this.radius = radius;
}
代码示例来源:origin: apache/servicemix-bundles
/**
* Adds the given distance to the current one. The resulting {@link Distance} will be in the same metric as the
* current one.
*
* @param other must not be {@literal null}.
* @return
*/
public Distance add(Distance other) {
Assert.notNull(other, "Distance to add must not be null!");
double newNormalizedValue = getNormalizedValue() + other.getNormalizedValue();
return new Distance(newNormalizedValue * metric.getMultiplier(), metric);
}
代码示例来源:origin: spring-projects/spring-data-mongodb
@Override
public Circle convert(Document source) {
if (source == null) {
return null;
}
Document center = (Document) source.get("center");
Number radius = (Number) source.get("radius");
Assert.notNull(center, "Center must not be null!");
Assert.notNull(radius, "Radius must not be null!");
Distance distance = new Distance(toPrimitiveDoubleValue(radius));
if (source.containsKey("metric")) {
String metricString = (String) source.get("metric");
Assert.notNull(metricString, "Metric must not be null!");
distance = distance.in(Metrics.valueOf(metricString));
}
return new Circle(DocumentToPointConverter.INSTANCE.convert(center), distance);
}
}
代码示例来源:origin: spring-projects/spring-data-mongodb
/**
* Sets the maximum distance to the given {@link Distance}. Will set the returned {@link Metric} to be the one of the
* given {@link Distance} if {@link Metric} was {@link Metrics#NEUTRAL} before.
*
* @param distance must not be {@literal null}.
* @return
*/
public NearQuery maxDistance(Distance distance) {
Assert.notNull(distance, "Distance must not be null!");
if (distance.getMetric() != Metrics.NEUTRAL) {
this.spherical(true);
}
if (ObjectUtils.nullSafeEquals(Metrics.NEUTRAL, this.metric)) {
in(distance.getMetric());
}
this.maxDistance = distance;
return this;
}
代码示例来源:origin: spring-projects/spring-data-mongodb
@Override
public Sphere convert(Document source) {
if (source == null) {
return null;
}
Document center = (Document) source.get("center");
Number radius = (Number) source.get("radius");
Assert.notNull(center, "Center must not be null!");
Assert.notNull(radius, "Radius must not be null!");
Distance distance = new Distance(toPrimitiveDoubleValue(radius));
if (source.containsKey("metric")) {
String metricString = (String) source.get("metric");
Assert.notNull(metricString, "Metric must not be null!");
distance = distance.in(Metrics.valueOf(metricString));
}
return new Sphere(DocumentToPointConverter.INSTANCE.convert(center), distance);
}
}
代码示例来源:origin: spring-projects/spring-data-redis
@Override
public Flux<CommandResponse<GeoRadiusCommand, Flux<GeoResult<GeoLocation<ByteBuffer>>>>> geoRadius(
Publisher<GeoRadiusCommand> commands) {
return connection.execute(cmd -> Flux.from(commands).concatMap(command -> {
Assert.notNull(command.getKey(), "Key must not be null!");
Assert.notNull(command.getPoint(), "Point must not be null!");
Assert.notNull(command.getDistance(), "Distance must not be null!");
GeoArgs geoArgs = command.getArgs().isPresent() ? LettuceConverters.toGeoArgs(command.getArgs().get())
: new GeoArgs();
Flux<GeoResult<GeoLocation<ByteBuffer>>> result = cmd
.georadius(command.getKey(), command.getPoint().getX(), command.getPoint().getY(),
command.getDistance().getValue(), LettuceConverters.toGeoArgsUnit(command.getDistance().getMetric()),
geoArgs) //
.map(converter(command.getDistance().getMetric())::convert);
return Mono.just(new CommandResponse<>(command, result));
}));
}
代码示例来源:origin: spring-projects/spring-data-redis
@Override
public Flux<CommandResponse<GeoRadiusByMemberCommand, Flux<GeoResult<GeoLocation<ByteBuffer>>>>> geoRadiusByMember(
Publisher<GeoRadiusByMemberCommand> commands) {
return connection.execute(cmd -> Flux.from(commands).concatMap(command -> {
Assert.notNull(command.getKey(), "Key must not be null!");
Assert.notNull(command.getMember(), "Member must not be null!");
Assert.notNull(command.getDistance(), "Distance must not be null!");
GeoArgs geoArgs = command.getArgs().isPresent() ? LettuceConverters.toGeoArgs(command.getArgs().get())
: new GeoArgs();
Flux<GeoResult<GeoLocation<ByteBuffer>>> result = cmd
.georadiusbymember(command.getKey(), command.getMember(), command.getDistance().getValue(),
LettuceConverters.toGeoArgsUnit(command.getDistance().getMetric()), geoArgs)
.map(converter(command.getDistance().getMetric())::convert);
return Mono.just(new CommandResponse<>(command, result));
}));
}
代码示例来源:origin: spring-projects/spring-data-redis
@Override
public GeoResult<GeoLocation<byte[]>> convert(redis.clients.jedis.GeoRadiusResponse source) {
Point point = GEO_COORDINATE_TO_POINT_CONVERTER.convert(source.getCoordinate());
return new GeoResult<>(new GeoLocation<>(source.getMember(), point),
new Distance(source.getDistance(), metric));
}
}
代码示例来源:origin: org.springframework.data/spring-data-couchbase
@Override
public boolean pointInCircle(Point p, Circle c) {
Point2D center = new Point2D.Double(c.getCenter().getX(), c.getCenter().getY());
return pointNear(p, center, c.getRadius().getNormalizedValue());
}
代码示例来源:origin: spring-projects/spring-data-mongodb
document.put("maxDistance", maxDistance.getNormalizedValue());
document.put("minDistance", minDistance.getNormalizedValue());
document.put("near", Arrays.asList(point.getX(), point.getY()));
代码示例来源:origin: spring-projects/spring-data-mongodb
/**
* Returns the {@link Shape} as a list of usually {@link Double} or {@link List}s of {@link Double}s. Wildcard bound
* to allow implementations to return a more concrete element type.
*
* @return
*/
public List<? extends Object> asList() {
return Arrays.asList(Arrays.asList(center.getX(), center.getY()), this.radius.getValue());
}
代码示例来源:origin: redisson/redisson
@Override
public Distance convert(Object obj) {
return new Distance((Double)obj, metric);
}
代码示例来源:origin: spring-projects/spring-data-redis
point = ((Circle) o).getCenter();
distance = ((Circle) o).getRadius();
} else if (o instanceof Point) {
distance = (Distance) distObject;
} else if (distObject instanceof Number) {
distance = new Distance(((Number) distObject).doubleValue(), Metrics.KILOMETERS);
} else {
throw new InvalidDataAccessApiUsageException(String
代码示例来源:origin: spring-projects/spring-data-mongodb
argument.add(toList(((Circle) shape).getCenter()));
argument.add(((Circle) shape).getRadius().getNormalizedValue());
argument.add(toList(((Circle) shape).getCenter()));
argument.add(((Circle) shape).getRadius());
argument.add(((Sphere) shape).getRadius().getNormalizedValue());
内容来源于网络,如有侵权,请联系作者删除!