Example #1
0
 private void assertAdjacentHashesAre(String centerString, String[] adjacentStrings) {
   GeoHash center = GeoHash.fromGeohashString(centerString);
   GeoHash[] adjacent = center.getAdjacent();
   for (String check : adjacentStrings) {
     assertArrayContainsGeoHash(check, adjacent);
   }
 }
Example #2
0
 @Test
 public void testNeibouringHashesNearMeridian() {
   GeoHash hash = GeoHash.fromGeohashString("sp2j");
   GeoHash west = hash.getWesternNeighbour();
   assertEquals("ezrv", west.toBase32());
   west = west.getWesternNeighbour();
   assertEquals("ezrt", west.toBase32());
 }
Example #3
0
 @Test
 public void testThatAdjacentHashesHavePointInitialized() {
   String center = "dqcjqc";
   GeoHash geohash = GeoHash.fromGeohashString(center);
   GeoHash[] adjacentHashes = geohash.getAdjacent();
   for (GeoHash adjacentHash : adjacentHashes) {
     assertNotNull(adjacentHash.getBoundingBox());
     assertNotNull(adjacentHash.getBoundingBoxCenterPoint());
     assertNotNull(adjacentHash.getPoint());
   }
 }
Example #4
0
  @Test
  public void testKnownNeighbouringHashes() {
    GeoHash h1 = GeoHash.fromGeohashString("u1pb");
    assertEquals("u0zz", h1.getSouthernNeighbour().toBase32());
    assertEquals("u1pc", h1.getNorthernNeighbour().toBase32());
    assertEquals("u300", h1.getEasternNeighbour().toBase32());
    assertEquals("u302", h1.getEasternNeighbour().getEasternNeighbour().toBase32());
    assertEquals("u1p8", h1.getWesternNeighbour().toBase32());

    assertEquals("sp2j", GeoHash.withCharacterPrecision(41.7, 0.08, 4).toBase32());
  }
Example #5
0
  @Test
  public void testIssue1() {
    double lat = 40.390943;
    double lon = -75.9375;
    GeoHash hash = GeoHash.withCharacterPrecision(lat, lon, 12);

    String base32 = "dr4jb0bn2180";
    GeoHash fromRef = GeoHash.fromGeohashString(base32);
    assertEquals(hash, fromRef);
    assertEquals(base32, hash.toBase32());
    assertEquals(base32, fromRef.toBase32());

    hash = GeoHash.withCharacterPrecision(lat, lon, 10);
    assertEquals("dr4jb0bn21", hash.toBase32());
  }
Example #6
0
  @Test
  public void testDecode() {
    // for all lat/lon pairs check decoded point is in the same bbox as the
    // geohash formed by encoder
    for (GeoHash gh : RandomGeohashes.fullRange()) {
      BoundingBox bbox = gh.getBoundingBox();
      GeoHash decodedHash = GeoHash.fromGeohashString(gh.toBase32());
      WGS84Point decodedCenter = decodedHash.getBoundingBoxCenterPoint();

      assertTrue(
          "bbox " + bbox + " should contain the decoded center value " + decodedCenter,
          bbox.contains(decodedCenter));
      BoundingBox decodedBoundingBox = decodedHash.getBoundingBox();
      assertEquals(bbox, decodedBoundingBox);
      assertEquals(gh, decodedHash);
      assertEquals(gh.toBase32(), decodedHash.toBase32());
    }
  }
Example #7
0
 @Test
 public void testAdjacentHashes() {
   GeoHash[] adjacent = GeoHash.fromGeohashString("dqcw4").getAdjacent();
   assertEquals(8, adjacent.length);
 }