@Test public void geopos() { prepareGeoData(); List<GeoCoordinate> coordinates = jedis.geopos("foo", "a", "b", "notexist"); assertEquals(3, coordinates.size()); assertTrue(equalsWithinEpsilon(3.0, coordinates.get(0).getLongitude())); assertTrue(equalsWithinEpsilon(4.0, coordinates.get(0).getLatitude())); assertTrue(equalsWithinEpsilon(2.0, coordinates.get(1).getLongitude())); assertTrue(equalsWithinEpsilon(3.0, coordinates.get(1).getLatitude())); assertNull(coordinates.get(2)); List<GeoCoordinate> bcoordinates = jedis.geopos(bfoo, bA, bB, bNotexist); assertEquals(3, bcoordinates.size()); assertTrue(equalsWithinEpsilon(3.0, bcoordinates.get(0).getLongitude())); assertTrue(equalsWithinEpsilon(4.0, bcoordinates.get(0).getLatitude())); assertTrue(equalsWithinEpsilon(2.0, bcoordinates.get(1).getLongitude())); assertTrue(equalsWithinEpsilon(3.0, bcoordinates.get(1).getLatitude())); assertNull(bcoordinates.get(2)); }
private void prepareGeoData() { Map<String, GeoCoordinate> coordinateMap = new HashMap<String, GeoCoordinate>(); coordinateMap.put("a", new GeoCoordinate(3, 4)); coordinateMap.put("b", new GeoCoordinate(2, 3)); coordinateMap.put("c", new GeoCoordinate(3.314, 2.3241)); long size = jedis.geoadd("foo", coordinateMap); assertEquals(3, size); Map<byte[], GeoCoordinate> bcoordinateMap = new HashMap<byte[], GeoCoordinate>(); bcoordinateMap.put(bA, new GeoCoordinate(3, 4)); bcoordinateMap.put(bB, new GeoCoordinate(2, 3)); bcoordinateMap.put(bC, new GeoCoordinate(3.314, 2.3241)); size = jedis.geoadd(bfoo, bcoordinateMap); assertEquals(3, size); }
public long geoadd(String key, Map<String, GeoCoordinate> geopositions) { try { redis = pool.getResource(); setDatabase(); _logNode.debug("GEOADD " + key + " + count geo: " + geopositions.size()); return redis.geoadd(key, geopositions); } catch (JedisConnectionException e) { if (redis != null) { redis.close(); } throw e; } finally { if (redis != null) { redis.close(); } } }
@Test public void geoadd() { long size = jedis.geoadd("foo", 1, 2, "a"); assertEquals(1, size); size = jedis.geoadd("foo", 2, 3, "a"); assertEquals(0, size); Map<String, GeoCoordinate> coordinateMap = new HashMap<String, GeoCoordinate>(); coordinateMap.put("a", new GeoCoordinate(3, 4)); coordinateMap.put("b", new GeoCoordinate(2, 3)); coordinateMap.put("c", new GeoCoordinate(3.314, 2.3241)); size = jedis.geoadd("foo", coordinateMap); assertEquals(2, size); // binary size = jedis.geoadd(bfoo, 1, 2, bA); assertEquals(1, size); size = jedis.geoadd(bfoo, 2, 3, bA); assertEquals(0, size); Map<byte[], GeoCoordinate> bcoordinateMap = new HashMap<byte[], GeoCoordinate>(); bcoordinateMap.put(bA, new GeoCoordinate(3, 4)); bcoordinateMap.put(bB, new GeoCoordinate(2, 3)); bcoordinateMap.put(bC, new GeoCoordinate(3.314, 2.3241)); size = jedis.geoadd(bfoo, bcoordinateMap); assertEquals(2, size); }
@Test public void georadius() { // prepare datas Map<String, GeoCoordinate> coordinateMap = new HashMap<String, GeoCoordinate>(); coordinateMap.put("Palermo", new GeoCoordinate(13.361389, 38.115556)); coordinateMap.put("Catania", new GeoCoordinate(15.087269, 37.502669)); jedis.geoadd("Sicily", coordinateMap); List<GeoRadiusResponse> members = jedis.georadius("Sicily", 15, 37, 200, GeoUnit.KM); assertEquals(2, members.size()); // sort members = jedis.georadius("Sicily", 15, 37, 200, GeoUnit.KM, GeoRadiusParam.geoRadiusParam() .sortAscending()); assertEquals(2, members.size()); assertEquals("Catania", members.get(0).getMemberByString()); assertEquals("Palermo", members.get(1).getMemberByString()); // sort, count 1 members = jedis.georadius("Sicily", 15, 37, 200, GeoUnit.KM, GeoRadiusParam.geoRadiusParam() .sortAscending().count(1)); assertEquals(1, members.size()); // sort, count 1, withdist, withcoord members = jedis.georadius("Sicily", 15, 37, 200, GeoUnit.KM, GeoRadiusParam.geoRadiusParam() .sortAscending().count(1).withCoord().withDist()); assertEquals(1, members.size()); GeoRadiusResponse response = members.get(0); assertTrue(equalsWithinEpsilon(56.4413, response.getDistance())); assertTrue(equalsWithinEpsilon(15.087269, response.getCoordinate().getLongitude())); assertTrue(equalsWithinEpsilon(37.502669, response.getCoordinate().getLatitude())); }
@Test public void georadiusBinary() { // prepare datas Map<byte[], GeoCoordinate> bcoordinateMap = new HashMap<byte[], GeoCoordinate>(); bcoordinateMap.put(bA, new GeoCoordinate(13.361389, 38.115556)); bcoordinateMap.put(bB, new GeoCoordinate(15.087269, 37.502669)); jedis.geoadd(bfoo, bcoordinateMap); List<GeoRadiusResponse> members = jedis.georadius(bfoo, 15, 37, 200, GeoUnit.KM); assertEquals(2, members.size()); // sort members = jedis.georadius(bfoo, 15, 37, 200, GeoUnit.KM, GeoRadiusParam.geoRadiusParam() .sortAscending()); assertEquals(2, members.size()); assertArrayEquals(bB, members.get(0).getMember()); assertArrayEquals(bA, members.get(1).getMember()); // sort, count 1 members = jedis.georadius(bfoo, 15, 37, 200, GeoUnit.KM, GeoRadiusParam.geoRadiusParam() .sortAscending().count(1)); assertEquals(1, members.size()); // sort, count 1, withdist, withcoord members = jedis.georadius(bfoo, 15, 37, 200, GeoUnit.KM, GeoRadiusParam.geoRadiusParam() .sortAscending().count(1).withCoord().withDist()); assertEquals(1, members.size()); GeoRadiusResponse response = members.get(0); assertTrue(equalsWithinEpsilon(56.4413, response.getDistance())); assertTrue(equalsWithinEpsilon(15.087269, response.getCoordinate().getLongitude())); assertTrue(equalsWithinEpsilon(37.502669, response.getCoordinate().getLatitude())); }
@Test public void testGeo() { GeoCoordinate gc1 = new GeoCoordinate(104.072329, 30.66342); GeoCoordinate gc2 = new GeoCoordinate(116.404168, 39.909677); Map<String, GeoCoordinate> gcs = new HashMap<>(); gcs.put("Chengdu", gc1); gcs.put("Beijing", gc2); jedisProxy.geoadd("cities", gcs); double meters = jedisProxy.geodist("cities", "Chengdu", "Beijing"); assertEquals(1517000, meters, 10000); }
@Override public Long geoadd(byte[] key, Map<byte[], GeoCoordinate> memberCoordinateMap) { Span span = helper.buildSpan("geoadd", key); span.setTag("memberCoordinateMap", TracingHelper.toStringMap2(memberCoordinateMap)); try { return super.geoadd(key, memberCoordinateMap); } catch (Exception e) { onError(e, span); throw e; } finally { span.finish(); } }
@Override public List<GeoCoordinate> geopos(byte[] key, byte[]... members) { Span span = helper.buildSpan("geopos", key); span.setTag("members", Arrays.toString(members)); try { return super.geopos(key, members); } catch (Exception e) { onError(e, span); throw e; } finally { span.finish(); } }
@Override public Long geoadd(String key, Map<String, GeoCoordinate> memberCoordinateMap) { Span span = helper.buildSpan("geoadd"); span.setTag("memberCoordinateMap", TracingHelper.toString(memberCoordinateMap)); try { return super.geoadd(key, memberCoordinateMap); } catch (Exception e) { onError(e, span); throw e; } finally { span.finish(); } }
@Override public List<GeoCoordinate> geopos(String key, String... members) { Span span = helper.buildSpan("geopos", key); span.setTag("members", Arrays.toString(members)); try { return super.geopos(key, members); } catch (Exception e) { onError(e, span); throw e; } finally { span.finish(); } }
public IMendixObject geopos(IContext context, String Key, String Member) throws Exception { try { _logNode.debug("GEOPOS " + Key + " Member: " + Member); redis = pool.getResource(); setDatabase(); List<GeoCoordinate> result = redis.geopos(Key, Member); if (result.size() > 0) { GeoPosition geoPosition = new GeoPosition(context); geoPosition.setLatitude(new BigDecimal(result.get(0).getLatitude(), MathContext.DECIMAL64)); geoPosition.setLongitude(new BigDecimal(result.get(0).getLongitude(), MathContext.DECIMAL64)); return geoPosition.getMendixObject(); } else { return null; } } catch (JedisConnectionException e) { if (redis != null) { redis.close(); } throw e; } finally { if (redis != null) { redis.close(); } } }
@Override public Long geoadd(String arg0, Map<String, GeoCoordinate> arg1) { // TODO Auto-generated method stub return null; }
@Override public List<GeoCoordinate> geopos(String arg0, String... arg1) { // TODO Auto-generated method stub return null; }