Пример #1
0
  @Test
  public void testNeighbourLocationCode() {
    // set up corner case
    hash.bits = 0xc400000000000000l;
    hash.significantBits = 7;

    long[] lonBits = hash.getRightAlignedLongitudeBits();
    assertEquals(0x8, lonBits[0]);
    assertEquals(4, lonBits[1]);

    long[] latBits = hash.getRightAlignedLatitudeBits();
    assertEquals(0x5, latBits[0]);
    assertEquals(3, latBits[1]);

    GeoHash north = hash.getNorthernNeighbour();
    assertEquals(0xd000000000000000l, north.bits);
    assertEquals(7, north.significantBits);

    GeoHash south = hash.getSouthernNeighbour();
    assertEquals(0xc000000000000000l, south.bits);
    assertEquals(7, south.significantBits());

    GeoHash east = hash.getEasternNeighbour();
    assertEquals(0xc600000000000000l, east.bits);

    // NOTE: this is actually a corner case!
    GeoHash west = hash.getWesternNeighbour();
    assertEquals(0x6e00000000000000l, west.bits);

    // NOTE: and now, for the most extreme corner case in 7-bit geohash-land
    hash.bits = 0xfe00000000000000l;

    east = hash.getEasternNeighbour();
    assertEquals(0x5400000000000000l, east.bits);
  }
Пример #2
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());
  }
Пример #3
0
 private void checkMovingInCircle(double latitude, double longitude) {
   GeoHash start;
   GeoHash end;
   start = GeoHash.withCharacterPrecision(latitude, longitude, 12);
   end = start.getEasternNeighbour();
   end = end.getSouthernNeighbour();
   end = end.getWesternNeighbour();
   end = end.getNorthernNeighbour();
   assertEquals(start, end);
   assertEquals(start.getBoundingBox(), end.getBoundingBox());
 }