Package ch.hsr.geohash

Examples of ch.hsr.geohash.BoundingBox


* Created by IntelliJ IDEA. User: kevin Date: Jan 6, 2011 Time: 3:05:43 PM
*/
public class BoundingBoxGeoHashIteratorTest {
  @Test
  public void testIter() {
    BoundingBox box = new BoundingBox(37.7, 37.84, -122.52, -122.35);
    BoundingBoxGeoHashIterator iter = new BoundingBoxGeoHashIterator(
        TwoGeoHashBoundingBox.withBitPrecision(box, 10));
    BoundingBox newBox = iter.getBoundingBox().getBoundingBox();
    List<GeoHash> hashes = new ArrayList<GeoHash>();
    while (iter.hasNext()) {
      hashes.add(iter.next());
    }
    GeoHash prev = null;
    for (GeoHash gh : hashes) {
      if (prev != null) {
        Assert.assertTrue(prev.compareTo(gh) < 0);
      }
      Assert.assertTrue(newBox.contains(gh.getPoint()));
      prev = gh;
    }

  }
View Full Code Here


  }

  @Test
  public void testIter2() {
    BoundingBox box = new BoundingBox(37.7, 37.84, -122.52, -122.35);
    BoundingBoxGeoHashIterator iter = new BoundingBoxGeoHashIterator(
        TwoGeoHashBoundingBox.withBitPrecision(box, 35));
    BoundingBox newBox = iter.getBoundingBox().getBoundingBox();
    List<GeoHash> hashes = new ArrayList<GeoHash>();
    while (iter.hasNext()) {
      hashes.add(iter.next());
    }
    GeoHash prev = null;
    for (GeoHash gh : hashes) {
      if (prev != null) {
        Assert.assertTrue(prev.compareTo(gh) < 0);
      }
      Assert.assertTrue(newBox.contains(gh.getPoint()));
      prev = gh;
    }

  }
View Full Code Here

    checkWithGenerator(new OnlyOneALittleTooLargeVerifier());
  }

  private void checkWithGenerator(BoundingBoxSizeTableVerifier generator) {
    for (int bits = 4; bits < 64; bits++) {
      BoundingBox bbox = generator.generate(bits);
      assertEquals(generator.getExpectedBits(bits), GeoHashSizeTable.numberOfBitsForOverlappingGeoHash(bbox));
    }
  }
View Full Code Here

    @Override
    public BoundingBox generate(int bits) {
      // make the bounding box a little smaller than dLat/dLon
      double dLat = GeoHashSizeTable.dLat(bits) - DELTA;
      double dLon = GeoHashSizeTable.dLon(bits) - DELTA;
      return new BoundingBox(45 - dLat, 45, 30, 30 - dLon);
    }
View Full Code Here

    @Override
    public BoundingBox generate(int bits) {
      double dLat = GeoHashSizeTable.dLat(bits);
      double dLon = GeoHashSizeTable.dLon(bits);
      return new BoundingBox(0, dLat + DELTA, 0, dLon + DELTA);
    }
View Full Code Here

      if (latitudeAffected = rand.nextBoolean()) {
        dLat += DELTA;
      } else {
        dLon += DELTA;
      }
      return new BoundingBox(0, dLat, 0, dLon);
    }
View Full Code Here

* Created by IntelliJ IDEA. User: kevin Date: Jan 17, 2011 Time: 12:48:55 PM
*/
public class BoundingBoxSamplerTest {
  @Test
  public void testSampler() {
    BoundingBox bbox = new BoundingBox(37.7, 37.84, -122.52, -122.35);
    BoundingBoxSampler sampler = new BoundingBoxSampler(TwoGeoHashBoundingBox.withBitPrecision(bbox, 35), 1179);
    bbox = sampler.getBoundingBox().getBoundingBox();
    GeoHash gh = sampler.next();
    Set<String> hashes = new HashSet<String>();
    int sumOfComp = 0;
    int crossingZero = 0;

    GeoHash prev = null;
    while (gh != null) {
      assertTrue(bbox.contains(gh.getPoint()));
      assertFalse(hashes.contains(gh.toBase32()));
      hashes.add(gh.toBase32());
      if (prev != null) {
        sumOfComp += prev.compareTo(gh);
      }
View Full Code Here

    this.center = center;
    WGS84Point northEast = VincentyGeodesy.moveInDirection(VincentyGeodesy.moveInDirection(center, 0, radius), 90,
        radius);
    WGS84Point southWest = VincentyGeodesy.moveInDirection(VincentyGeodesy.moveInDirection(center, 180, radius),
        270, radius);
    BoundingBox bbox = new BoundingBox(northEast, southWest);
    query = new GeoHashBoundingBoxQuery(bbox);
  }
View Full Code Here

    }
  }

  private void addSearchHash(GeoHash hash) {
    if (boundingBox == null) {
      boundingBox = new BoundingBox(hash.getBoundingBox());
    } else {
      boundingBox.expandToInclude(hash.getBoundingBox());
    }
    searchHashes.add(hash);
  }
View Full Code Here

  private void expandSearch(GeoHash centerHash, BoundingBox bbox) {
    addSearchHash(centerHash);

    for (GeoHash adjacent : centerHash.getAdjacent()) {
      BoundingBox adjacentBox = adjacent.getBoundingBox();
      if (adjacentBox.intersects(bbox) && !searchHashes.contains(adjacent)) {
        addSearchHash(adjacent);
      }
    }
  }
View Full Code Here

TOP

Related Classes of ch.hsr.geohash.BoundingBox

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.