Package ch.hsr.geohash

Examples of ch.hsr.geohash.GeoHash


        Random rand = new Random();
        List<GeoHash> hashes = new ArrayList<GeoHash>();
        for (double lat = -90; lat <= 90; lat += rand.nextDouble() + 1.45) {
          for (double lon = -180; lon <= 180; lon += rand.nextDouble() + 1.54) {
            for (int precisionChars = 6; precisionChars <= 12; precisionChars++) {
              GeoHash gh = GeoHash.withCharacterPrecision(lat, lon, precisionChars);
              hashes.add(gh);
            }
          }
        }
        return hashes.iterator();
View Full Code Here


    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

    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 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);
      }
      prev = gh;
      if (sumOfComp == 0) {
        crossingZero++;
      }
View Full Code Here

  private BoundingBox boundingBox;

  public GeoHashBoundingBoxQuery(BoundingBox bbox) {
    int fittingBits = GeoHashSizeTable.numberOfBitsForOverlappingGeoHash(bbox);
    WGS84Point center = bbox.getCenterPoint();
    GeoHash centerHash = GeoHash.withBitPrecision(center.getLatitude(), center.getLongitude(), fittingBits);

    if (hashFits(centerHash, bbox)) {
      addSearchHash(centerHash);
    } else {
      expandSearch(centerHash, bbox);
View Full Code Here

  private BoundingBox boundingBox;
  private GeoHash bottomLeft;
  private GeoHash topRight;

  public static TwoGeoHashBoundingBox withCharacterPrecision(BoundingBox bbox, int numberOfCharacters) {
    GeoHash bottomLeft = GeoHash.withCharacterPrecision(bbox.getMinLat(), bbox.getMinLon(), numberOfCharacters);
    GeoHash topRight = GeoHash.withCharacterPrecision(bbox.getMaxLat(), bbox.getMaxLon(), numberOfCharacters);
    return new TwoGeoHashBoundingBox(bottomLeft, topRight);
  }
View Full Code Here

    GeoHash topRight = GeoHash.withCharacterPrecision(bbox.getMaxLat(), bbox.getMaxLon(), numberOfCharacters);
    return new TwoGeoHashBoundingBox(bottomLeft, topRight);
  }

  public static TwoGeoHashBoundingBox withBitPrecision(BoundingBox bbox, int numberOfBits) {
    GeoHash bottomLeft = GeoHash.withBitPrecision(bbox.getMinLat(), bbox.getMinLon(), numberOfBits);
    GeoHash topRight = GeoHash.withBitPrecision(bbox.getMaxLat(), bbox.getMaxLon(), numberOfBits);
    return new TwoGeoHashBoundingBox(bottomLeft, topRight);
  }
View Full Code Here

    int idx = rand.nextInt(maxSamples + 1);
    while (alreadyUsed.contains(idx)) {
      idx = rand.nextInt(maxSamples + 1);
    }
    alreadyUsed.add(idx);
    GeoHash gh = boundingBox.getBottomLeft().next(idx);
    if (!boundingBox.getBoundingBox().contains(gh.getPoint())) {
      return next();
    }
    return gh;
  }
View Full Code Here

    return current.compareTo(boundingBox.getTopRight()) <= 0;
  }

  @Override
  public GeoHash next() {
    GeoHash rv = current;
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    current = rv.next();
    while (hasNext() && !boundingBox.getBoundingBox().contains(current.getPoint())) {
      current = current.next();
    }
    return rv;
  }
View Full Code Here

TOP

Related Classes of ch.hsr.geohash.GeoHash

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.