示例#1
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());
 }
示例#2
0
  @Test
  public void testNotWithin() {
    hash.bits = 0x6ff0414000000000l;
    hash.significantBits = 25;
    assertEquals("ezs42", hash.toBase32());

    GeoHash bbox = new GeoHash();
    bbox.bits = 0x6fc0000000000000l;
    bbox.significantBits = 12;

    assertFalse(hash.toBase32() + " should NOT be within " + bbox.toBase32(), hash.within(bbox));
  }
示例#3
0
  @Test
  public void testWithin() {
    hash.bits = 0x6ff0414000000000l;
    hash.significantBits = 25;
    System.out.println(hash.toBase32());
    assertEquals("ezs42", hash.toBase32());

    GeoHash bbox = new GeoHash();
    bbox.bits = 0x6ff0000000000000l;
    bbox.significantBits = 12;

    assertWithin(hash, bbox);
  }
示例#4
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());
  }
示例#5
0
 private void assertEncodingWithCharacterPrecision(
     WGS84Point point, int numberOfCharacters, String stringValue) {
   GeoHash hash =
       GeoHash.withCharacterPrecision(
           point.getLatitude(), point.getLongitude(), numberOfCharacters);
   assertEquals(stringValue, hash.toBase32());
 }
示例#6
0
  @Test
  public void testToBase32() {
    hash.bits = 0x6ff0414000000000l;
    hash.significantBits = 25;

    String base32 = hash.toBase32();
    assertEquals("ezs42", base32);
  }
示例#7
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());
    }
  }
示例#8
0
  @Test
  public void testNextPrev() {
    double lat = 37.7;
    double lon = -122.52;
    GeoHash hash = GeoHash.withBitPrecision(lat, lon, 35);
    GeoHash next = hash.next(2);
    assertTrue(hash.compareTo(next) < 0);
    GeoHash prev1 = next.prev();
    GeoHash prev2 = prev1.next(-1);
    assertTrue(prev1.compareTo(next) < 0);
    System.out.println("hash: " + hash.toBase32());
    System.out.println("next: " + next.toBase32());
    System.out.println("prev1: " + prev1.toBase32());
    System.out.println("prev2: " + prev2.toBase32());

    assertTrue(prev2.compareTo(prev1) < 0);
    assertTrue(prev2.compareTo(hash) == 0);
  }
示例#9
0
 private void assertArrayContainsGeoHash(String check, GeoHash[] hashes) {
   boolean found = false;
   for (GeoHash hash : hashes) {
     if (hash.toBase32().equals(check)) {
       found = true;
       break;
     }
   }
   assertTrue("Array should contain " + check, found);
 }
示例#10
0
 @Test
 public void testToLongAndBack() {
   double lat = 40.390943;
   double lon = -75.9375;
   GeoHash hash = GeoHash.withCharacterPrecision(lat, lon, 10);
   long lv = hash.longValue();
   assertEquals(lv + (1 << (64 - hash.significantBits())), hash.next().longValue());
   GeoHash hashFromLong = GeoHash.fromLongValue(lv, hash.significantBits());
   assertEquals("dr4jb0bn21", hashFromLong.toBase32());
   assertEquals(hash, hashFromLong);
 }
示例#11
0
  @Test
  public void testConstructorWithBitPrecision() {
    GeoHash hash1 = GeoHash.withBitPrecision(45, 120, 20);
    assertEquals(hash1.significantBits, 20);
    System.out.println(hash1);
    System.out.println(hash1.toBase32());

    GeoHash hash2 = GeoHash.withBitPrecision(45, 120, 55);
    assertEquals(hash2.significantBits, 55);
    System.out.println(hash2);
    System.out.println(hash2.toBase32());

    assertTrue(hash2.within(hash1));

    // this should match Dave Troys Codebase. This is also his maximum
    // accuracy (12 5-nibbles).
    GeoHash hash3 = GeoHash.withBitPrecision(20, 31, 60);
    assertEquals("sew1c2vs2q5r", hash3.toBase32());
    System.out.println("--------------");
    String hash4 = new GeoHash().geoHashStringWithCharacterPrecision(45, 120, 64);
    System.out.println(hash4);
  }
示例#12
0
 @Test
 public void testLatLonBoundingBoxes() {
   hash = GeoHash.withBitPrecision(40, 120, 10);
   System.out.println(hash.toBase32());
   printBoundingBox(hash);
 }
示例#13
0
 private void assertWithin(GeoHash hash, GeoHash bbox) {
   assertTrue(hash.toBase32() + " should be within " + bbox.toBase32(), hash.within(bbox));
 }