Java Code Examples for org.springframework.data.geo.Distance#getMetric()

The following examples show how to use org.springframework.data.geo.Distance#getMetric() . 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: Neo4jQuerySupport.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
private static double calculateDistanceInMeter(Distance distance) {

		if (distance.getMetric() == Metrics.KILOMETERS) {
			double kilometersDivisor = 0.001d;
			return distance.getValue() / kilometersDivisor;

		} else if (distance.getMetric() == Metrics.MILES) {
			double milesDivisor = 0.00062137d;
			return distance.getValue() / milesDivisor;

		} else {
			return distance.getValue();
		}
	}
 
Example 2
Source File: RedissonConnection.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, Distance radius,
        GeoRadiusCommandArgs args) {
    List<Object> params = new ArrayList<Object>();
    params.add(key);
    params.add(member);
    params.add(radius.getValue());
    params.add(radius.getMetric().getAbbreviation());
    
    RedisCommand<GeoResults<GeoLocation<byte[]>>> command;
    if (args.getFlags().contains(GeoRadiusCommandArgs.Flag.WITHCOORD)) {
        command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUSBYMEMBER", postitionDecoder);
        params.add("WITHCOORD");
    } else {
        MultiDecoder<GeoResults<GeoLocation<byte[]>>> distanceDecoder = new ListMultiDecoder2(new GeoResultsDecoder(radius.getMetric()), new GeoDistanceDecoder());
        command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUSBYMEMBER", 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 3
Source File: RedissonConnection.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, Distance radius,
        GeoRadiusCommandArgs args) {
    List<Object> params = new ArrayList<Object>();
    params.add(key);
    params.add(member);
    params.add(radius.getValue());
    params.add(radius.getMetric().getAbbreviation());
    
    RedisCommand<GeoResults<GeoLocation<byte[]>>> command;
    if (args.getFlags().contains(GeoRadiusCommandArgs.Flag.WITHCOORD)) {
        command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUSBYMEMBER", postitionDecoder);
        params.add("WITHCOORD");
    } else {
        MultiDecoder<GeoResults<GeoLocation<byte[]>>> distanceDecoder = new ListMultiDecoder2(new GeoResultsDecoder(radius.getMetric()), new GeoDistanceDecoder());
        command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUSBYMEMBER", 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 4
Source File: RedissonConnection.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, Distance radius,
        GeoRadiusCommandArgs args) {
    List<Object> params = new ArrayList<Object>();
    params.add(key);
    params.add(member);
    params.add(radius.getValue());
    params.add(radius.getMetric().getAbbreviation());
    
    RedisCommand<GeoResults<GeoLocation<byte[]>>> command;
    if (args.getFlags().contains(GeoRadiusCommandArgs.Flag.WITHCOORD)) {
        command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUSBYMEMBER", postitionDecoder);
        params.add("WITHCOORD");
    } else {
        MultiDecoder<GeoResults<GeoLocation<byte[]>>> distanceDecoder = new ListMultiDecoder2(new GeoResultsDecoder(radius.getMetric()), new GeoDistanceDecoder());
        command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUSBYMEMBER", 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 vote down vote up
@Override
public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, Distance radius,
        GeoRadiusCommandArgs args) {
    List<Object> params = new ArrayList<Object>();
    params.add(key);
    params.add(member);
    params.add(radius.getValue());
    params.add(radius.getMetric().getAbbreviation());
    
    RedisCommand<GeoResults<GeoLocation<byte[]>>> command;
    if (args.getFlags().contains(GeoRadiusCommandArgs.Flag.WITHCOORD)) {
        command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUSBYMEMBER", postitionDecoder);
        params.add("WITHCOORD");
    } else {
        MultiDecoder<GeoResults<GeoLocation<byte[]>>> distanceDecoder = new ListMultiDecoder2(new GeoResultsDecoder(radius.getMetric()), new GeoDistanceDecoder());
        command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUSBYMEMBER", 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());
}