Пример #1
0
  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
  public static void configureOptions(Scanner in) {
    String option;
    while (true) {
      System.out.println("********************");
      System.out.println("*      Settings    *");
      System.out.println("********************");
      System.out.println("* a. Set Map Host  *");
      System.out.println("* b. Set Map Port  *");
      System.out.println("* q. EXIT SETTINGS *");
      System.out.println("********************");
      System.out.print("Enter option: ");
      option = in.next();

      if (option.equalsIgnoreCase("a")) {
        System.out.print(" Enter Map Host: ");
        mapPoster.setHost(in.next());
      } else if (option.equalsIgnoreCase("b")) {
        System.out.print(" Enter Map Port: ");
        mapPoster.setPort(in.next());
      } else if (option.equalsIgnoreCase("q")) {
        return;
      } else {
        System.out.println("\n\n!!!!!!ERROR: Invalid Option!!!!!!!!!\n");
      }
    }
  }
Пример #3
0
  public static void closestPtOnCircle(Scanner in) {
    boolean postToMap = doPostToMap(in);
    System.out.println("Enter start point:");
    double[][] cntr = getPoints(in, 1);
    //    GeoRect rect = getRect(in);
    System.out.println("Enter lower left and upper right of rectangle:");
    double[][] pt = getPoints(in, 2);

    double[] closestPt = new double[2];
    GeoDistanceUtils.closestPointOnBBox(
        pt[0][LON_INDEX],
        pt[0][LAT_INDEX],
        pt[1][LON_INDEX],
        pt[1][LAT_INDEX],
        cntr[0][LON_INDEX],
        cntr[0][LAT_INDEX],
        closestPt);

    System.out.println(" Closest Point: " + closestPt[LON_INDEX] + " " + closestPt[LAT_INDEX]);

    if (postToMap) {
      double[][] pts = new double[][] {{cntr[0][LON_INDEX], cntr[0][LAT_INDEX]}, closestPt};
      // draw both points
      mapPoster.post(GeoMapPoster.toJSON(pts));
      // draw a line
      mapPoster.post(GeoMapPoster.toJSON(true, pts));
    }
  }
Пример #4
0
  /** 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();
        }
      }
    }
  }
Пример #5
0
  public static void polygonTermsEnum(Scanner in) throws Exception {
    boolean postToMap = doPostToMap(in);
    System.out.print(" Enter number of points for polygon: ");
    int numPts = in.nextInt();
    double[][] pts = getPoints(in, numPts);
    double[][] poly = transposePoly(pts);

    //        double[] lons = new double[pts.length];
    //        double[] lats = new double[pts.length];
    //        for (int i=0; i<pts.length; ++i) {
    //            lons[i] = pts[i][LON_INDEX];
    //            lats[i] = pts[i][LAT_INDEX];
    //        }
    GeoRangeComputer[] grc = GeoRangeComputer.polygon(poly[LON_INDEX], poly[LAT_INDEX]);
    System.out.print("Check target point (y/n): ");
    if (in.next().equalsIgnoreCase("y")) {
      double[][] qPoint = getPoints(in, 1);
      for (GeoRangeComputer c : grc) {
        c.contains(qPoint[0][LON_INDEX], qPoint[0][LAT_INDEX]);
      }
    }

    if (postToMap) {
      // draw polygon
      mapPoster.post(GeoMapPoster.toJSON(true, pts));
      Thread.sleep(500);
      // draw terms enum
      postTermsEnumToMap(grc);
    }
  }
Пример #6
0
  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));
    }
  }
Пример #7
0
  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));
    }
  }
Пример #8
0
 public static void mapBBox(Scanner in) {
   GeoRect rect = getRect(in);
   mapPoster.post(GeoMapPoster.toJSON(rect));
 }
Пример #9
0
 public static void mapLine(Scanner in) {
   System.out.print(" Number of points: ");
   double[][] points = getPoints(in, in.nextInt());
   mapPoster.post(GeoMapPoster.toJSON(true, points));
 }
Пример #10
0
 public static void mapPoints(Scanner in) {
   double[][] point = getPoints(in, 1);
   mapPoster.post(GeoMapPoster.toJSON(point));
 }