コード例 #1
0
ファイル: GeoProcessor.java プロジェクト: yangxi/luceneutil
  public static void rectWithinCircle(Scanner in) {
    boolean postToMap = doPostToMap(in);
    GeoRect rect = getRect(in);
    System.out.println("Enter Center Point: ");
    double[][] cntr = getPoints(in, 1);
    double r = getRadius(in);

    System.out.println(
        " Rectangle "
            + (GeoUtils.rectWithinCircle(
                    rect.minLon,
                    rect.minLat,
                    rect.maxLon,
                    rect.maxLat,
                    cntr[0][LON_INDEX],
                    cntr[0][LAT_INDEX],
                    r)
                ? "within"
                : "not within")
            + " circle");

    if (postToMap) {
      // draw rectangle
      mapPoster.post(GeoMapPoster.toJSON(rect));

      // convert point radius to poly
      List<double[]> polyPoints = GeoUtils.circleToPoly(cntr[0][LON_INDEX], cntr[0][LAT_INDEX], r);
      mapPoster.post(GeoMapPoster.toJSON(polyPoints));
    }
  }
コード例 #2
0
ファイル: GeoProcessor.java プロジェクト: yangxi/luceneutil
  /** OPTION 3 - Compute a Bounding Box from an existing Location and Raidus */
  public static void boundingBoxFromPointRadius(Scanner in) {
    boolean postToMap = doPostToMap(in);
    double[][] point = getPoints(in, 1);
    double radius = getRadius(in);
    GeoRect rect = GeoUtils.circleToBBox(point[0][LON_INDEX], point[0][LAT_INDEX], radius);
    GeoRect[] rects;
    if (rect.maxLon < rect.minLon) {
      rects =
          new GeoRect[] {
            new GeoRect(GeoUtils.MIN_LON_INCL, rect.maxLon, rect.minLat, rect.maxLat),
            new GeoRect(rect.minLon, GeoUtils.MAX_LON_INCL, rect.minLat, rect.maxLat)
          };
    } else {
      rects = new GeoRect[] {rect};
    }

    for (GeoRect r : rects) {
      System.out.println("\n" + r);
      if (postToMap == true) {
        mapPoster.post(GeoMapPoster.toJSON(r));
        try {
          Thread.sleep(500);
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
  }
コード例 #3
0
ファイル: GeoProcessor.java プロジェクト: yangxi/luceneutil
  public static void displayPointRanges(Scanner in) {
    double[][] point = getPoints(in, 1);
    long hash, hashUpper;
    double lon, lat, lonUpper, latUpper;

    for (int i = 63; i >= 45; i -= GeoPointField.PRECISION_STEP) {
      BytesRefBuilder brb = new BytesRefBuilder();
      NumericUtils.longToPrefixCoded(
          GeoUtils.mortonHash(point[0][LON_INDEX], point[0][LAT_INDEX]), i, brb);
      BytesRef br = brb.get();
      hash = NumericUtils.prefixCodedToLong(br);
      hashUpper = hash | ((1L << i) - 1);
      lon = GeoUtils.mortonUnhashLon(hash);
      lat = GeoUtils.mortonUnhashLat(hash);
      lonUpper = GeoUtils.mortonUnhashLon(hashUpper);
      latUpper = GeoUtils.mortonUnhashLat(hashUpper);
      System.out.println(
          i + ": " + br + " " + hash + " (" + lon + "," + lat + ")" + " : " + "(" + lonUpper + ","
              + latUpper + ")");
    }
  }
コード例 #4
0
ファイル: GeoProcessor.java プロジェクト: yangxi/luceneutil
  public static void pointRadiusToPolygon(Scanner in) {
    boolean postToMap = doPostToMap(in);
    double[][] point = getPoints(in, 1);
    double radius = getRadius(in);

    List<double[]> polyPoints =
        GeoUtils.circleToPoly(point[0][LON_INDEX], point[0][LAT_INDEX], radius);

    if (postToMap == true) {
      mapPoster.post(GeoMapPoster.toJSON(polyPoints));
    }
  }
コード例 #5
0
  public static void randomPointIn(
      Random r,
      final double minLon,
      final double minLat,
      final double maxLon,
      final double maxLat,
      double[] pt) {
    assert pt != null && pt.length == 2;

    // normalize min and max
    double[] min = {GeoUtils.normalizeLon(minLon), GeoUtils.normalizeLat(minLat)};
    double[] max = {GeoUtils.normalizeLon(maxLon), GeoUtils.normalizeLat(maxLat)};
    final double[] tMin = new double[2];
    final double[] tMax = new double[2];
    tMin[0] = Math.min(min[0], max[0]);
    tMax[0] = Math.max(min[0], max[0]);
    tMin[1] = Math.min(min[1], max[1]);
    tMax[1] = Math.max(min[1], max[1]);

    pt[0] = tMin[0] + r.nextDouble() * (tMax[0] - tMin[0]);
    pt[1] = tMin[1] + r.nextDouble() * (tMax[1] - tMin[1]);
  }
コード例 #6
0
 public GeoPoint resetFromGeoHash(String geohash) {
   final long hash = GeoHashUtils.mortonEncode(geohash);
   return this.reset(GeoUtils.mortonUnhashLat(hash), GeoUtils.mortonUnhashLon(hash));
 }
コード例 #7
0
 public GeoPoint resetFromIndexHash(long hash) {
   lon = GeoUtils.mortonUnhashLon(hash);
   lat = GeoUtils.mortonUnhashLat(hash);
   return this;
 }
コード例 #8
0
ファイル: GeoProcessor.java プロジェクト: yangxi/luceneutil
  public static void rectPolyRelation(Scanner in) throws Exception {
    boolean postToMap = doPostToMap(in);
    GeoRect rect = getRect(in);
    double[][] poly = getPoly(in);
    double[][] polyTrans = transposePoly(poly);
    GeoRect polyBBox = GeoUtils.polyToBBox(polyTrans[LON_INDEX], polyTrans[LAT_INDEX]);

    boolean within =
        GeoUtils.rectWithinPoly(
            rect.minLon,
            rect.minLat,
            rect.maxLon,
            rect.maxLat,
            polyTrans[LON_INDEX],
            polyTrans[LAT_INDEX],
            polyBBox.minLon,
            polyBBox.minLat,
            polyBBox.maxLon,
            polyBBox.maxLat);
    boolean crosses =
        GeoUtils.rectCrossesPoly(
            rect.minLon,
            rect.minLat,
            rect.maxLon,
            rect.maxLat,
            polyTrans[LON_INDEX],
            polyTrans[LAT_INDEX],
            polyBBox.minLon,
            polyBBox.minLat,
            polyBBox.maxLon,
            polyBBox.maxLat);
    boolean contains =
        GeoUtils.rectContains(
            rect.minLon,
            rect.minLat,
            rect.maxLon,
            rect.maxLat,
            polyBBox.minLon,
            polyBBox.minLat,
            polyBBox.maxLon,
            polyBBox.maxLat);

    System.out.print(" Rectangle ");
    if (within) {
      System.out.println("Within Poly");
    } else if (crosses) {
      System.out.println("Crosses Poly");
    } else if (contains) {
      System.out.println("Contains Poly");
    } else {
      System.out.println("Disjoint from Poly");
    }

    if (postToMap) {
      // draw bbox
      mapPoster.post(GeoMapPoster.toJSON(polyBBox));
      Thread.sleep(500);
      // draw poly
      mapPoster.post(GeoMapPoster.toJSON(true, poly));
      Thread.sleep(500);
      // draw rect
      mapPoster.post(GeoMapPoster.toJSON(rect));
    }
  }