GeohashBinningStrategy implements AggregationBinningStrategy<T> { @Override public String[] binEntry(T entry) { Geometry geometry = this.getGeometry(entry); return geometry == null ? null : new String[] {encodeToGeohash(geometry, this.precision)}; } GeohashBinningStrategy(int precision); int getPrecision(); @Override String[] binEntry(T entry); @Override byte[] toBinary(); @Override void fromBinary(byte[] bytes);  }
@Test public void testNoGeometry() throws SchemaException { SimpleFeatureType noGeoType = DataUtilities.createType("testNoGeo", "name:String"); SimpleFeature noGeoFeature = SimpleFeatureBuilder.build(noGeoType, new Object[] {"NAME!"}, "NAME!"); GeohashBinningStrategy<SimpleFeature> sfStrat = new GeohashSimpleFeatureBinningStrategy(4); String[] bin = sfStrat.binEntry(noGeoFeature); assertNull(bin); GeohashBinningStrategy<CommonIndexedPersistenceEncoding> ciStrat = new GeohashCommonIndexedBinningStrategy(4, "NotTheGeoField"); bin = ciStrat.binEntry(createCommonIndexData(new Coordinate(1, 1, 1))); assertNull(bin); }
@Test public void testBinSimpleFeature() { SimpleFeature feature1 = createSimpleFeature(new Coordinate(0, 0)); SimpleFeature feature2 = createSimpleFeature(new Coordinate(40, 40)); SimpleFeature feature3 = createSimpleFeature(new Coordinate(40, 40)); GeohashBinningStrategy<SimpleFeature> strat = new GeohashSimpleFeatureBinningStrategy(4); String bin1 = strat.binEntry(feature1)[0]; String bin2 = strat.binEntry(feature2)[0]; String bin3 = strat.binEntry(feature3)[0]; assertThat(bin1, is(not(bin2))); assertThat(bin2, is(bin3)); strat = new GeohashSimpleFeatureBinningStrategy(1); feature1 = createSimpleFeature(new Coordinate(0, 0)); feature2 = createSimpleFeature(new Coordinate(0.01, 0.01)); bin1 = strat.binEntry(feature1)[0]; bin2 = strat.binEntry(feature2)[0]; assertThat(bin1, is(bin2)); }
@Test public void testBinCommonIndexModel() { GeohashBinningStrategy<CommonIndexedPersistenceEncoding> strat = new GeohashCommonIndexedBinningStrategy(4); CommonIndexedPersistenceEncoding data1 = createCommonIndexData(new Coordinate(0, 0)); CommonIndexedPersistenceEncoding data2 = createCommonIndexData(new Coordinate(40, 40)); String bin1 = strat.binEntry(data1)[0]; String bin2 = strat.binEntry(data2)[0]; assertThat(bin1, is(not(bin2))); strat = new GeohashCommonIndexedBinningStrategy(1); data1 = createCommonIndexData(new Coordinate(0, 0)); data2 = createCommonIndexData(new Coordinate(0.01, 0.01)); bin1 = strat.binEntry(data1)[0]; bin2 = strat.binEntry(data2)[0]; assertThat(bin1, is(bin2)); }