Example #1
0
  /**
   * Get an OMText label for a segments between the given lat/lon points whose given distance and
   * cumulative distance is specified.
   */
  public OMText createLabel(
      Geo g1, Geo g2, double dist, double cumulativeDist, Length distanceUnits) {
    Geo mid;
    switch (getLineType()) {
      case LINETYPE_STRAIGHT:
        double lat = (g1.getLatitude() + g2.getLatitude()) / 2.0;
        double lon = (g1.getLongitude() + g2.getLongitude()) / 2.0;
        mid = new Geo(lat, lon);
        break;
      case LINETYPE_RHUMB:
        System.err.println("Rhumb distance calculation not implemented.");
      case LINETYPE_GREATCIRCLE:
      case LINETYPE_UNKNOWN:
      default:
        mid = g1.midPoint(g2);
    }

    // String text = ((int)dist) + " (" + ((int)cumulativeDist) +
    // ")";

    String text =
        (df.format(distanceUnits.fromRadians(dist)))
            + " ("
            + (df.format(distanceUnits.fromRadians(cumulativeDist)))
            + ") "
            + distanceUnits.getAbbr();
    OMText omtext = new OMText(mid.getLatitude(), mid.getLongitude(), text, OMText.JUSTIFY_LEFT);
    // omtext.setLinePaint(new Color(200, 200, 255));
    return omtext;
  }
Example #2
0
  public void createLabels() {
    labels.clear();
    points.clear();

    if (rawllpts == null) {
      return;
    }
    if (rawllpts.length < 4) {
      return;
    }

    Geo lastGeo = new Geo(rawllpts[0], rawllpts[1], units == DECIMAL_DEGREES);
    double latpnt = rawllpts[0];
    double lonpnt = rawllpts[1];
    if (units == RADIANS) {
      latpnt = ProjMath.radToDeg(latpnt);
      lonpnt = ProjMath.radToDeg(lonpnt);
    }
    points.add(new OMPoint(latpnt, lonpnt, 1));
    Geo curGeo = null;
    double cumulativeDist = 0.0;
    for (int p = 2; p < rawllpts.length; p += 2) {
      if (curGeo == null) {
        curGeo = new Geo(rawllpts[p], rawllpts[p + 1], units == DECIMAL_DEGREES);
      } else {
        if (units == DECIMAL_DEGREES) {
          curGeo.initialize(rawllpts[p], rawllpts[p + 1]);
        } else {
          curGeo.initializeRadians(rawllpts[p], rawllpts[p + 1]);
        }
      }

      double dist = getDist(lastGeo, curGeo);
      cumulativeDist += dist;

      labels.add(createLabel(lastGeo, curGeo, dist, cumulativeDist, distUnits));
      latpnt = rawllpts[p];
      lonpnt = rawllpts[p + 1];
      if (units == RADIANS) {
        latpnt = ProjMath.radToDeg(latpnt);
        lonpnt = ProjMath.radToDeg(lonpnt);
      }

      points.add(new OMPoint(latpnt, lonpnt, 1));
      lastGeo.initialize(curGeo);
    }
  }
Example #3
0
  /**
   * Return the distance between that lat/lons defined in radians. The returned value is in radians
   * and LINETYPE is taken into consideration. LINETYPE_STRAIGHT returns same as
   * LINETYPE_GREATCIRCLE, the ground distance between all nodes and not the degree distance of the
   * lines.
   */
  public double getDist(Geo g1, Geo g2) {
    switch (getLineType()) {
      case LINETYPE_RHUMB:
        double[] coords =
            new double[] {
              g1.getLatitudeRadians(),
              g1.getLongitudeRadians(),
              g2.getLatitudeRadians(),
              g2.getLongitudeRadians()
            };
        return ProjMath.distance(LineCoordinateGenerator.fromRadians(coords).rhumbLineDoubles());

      case LINETYPE_STRAIGHT:
      case LINETYPE_GREATCIRCLE:
      case LINETYPE_UNKNOWN:
      default:
        return g1.distance(g2);
    }
  }
  private Position findIntersectionBottom(Position newPos) {
    // The mouse can be in 4 different areas
    int lengthMax = 500000;

    double bearing = C.rhumbLineBearingTo(newPos);

    System.out.println("Vertical bearing " + verticalBearing);
    System.out.println("Horizontal bearing " + horizontalBearing);

    Geo intersectionPoint = null;

    if (bearing >= 0 && bearing <= 180) {

      // if (bearing > 90 && bearing < 180){

      // Create a line going from C, in reverse vertical direction eg up
      Position verticalEndPosition = Calculator.findPosition(A, verticalBearing, lengthMax);
      Geo a1 = new Geo(A.getLatitude(), A.getLongitude());
      Geo a2 = new Geo(verticalEndPosition.getLatitude(), verticalEndPosition.getLongitude());

      // Create a line going from newPos in reverse horizontal direction
      // eg left
      Position horizontalEndPosition =
          Calculator.findPosition(
              newPos, Calculator.reverseDirection(horizontalBearing), lengthMax);

      Geo b1 = new Geo(newPos.getLatitude(), newPos.getLongitude());
      Geo b2 = new Geo(horizontalEndPosition.getLatitude(), horizontalEndPosition.getLongitude());

      intersectionPoint = Intersection.segmentsIntersect(a1, a2, b1, b2);
    }

    if (bearing > 180) {

      // Create a line going from C, in reverse vertical direction eg up
      Position verticalEndPosition = Calculator.findPosition(C, verticalBearing, lengthMax);
      Geo a1 = new Geo(C.getLatitude(), C.getLongitude());
      Geo a2 = new Geo(verticalEndPosition.getLatitude(), verticalEndPosition.getLongitude());

      // Create a line going from newPos in horizontal direction eg right
      Position horizontalEndPosition =
          Calculator.findPosition(newPos, horizontalBearing, lengthMax);

      Geo b1 = new Geo(newPos.getLatitude(), newPos.getLongitude());
      Geo b2 = new Geo(horizontalEndPosition.getLatitude(), horizontalEndPosition.getLongitude());

      intersectionPoint = Intersection.segmentsIntersect(a1, a2, b1, b2);
    }

    if (intersectionPoint != null) {

      newPos = Position.create(intersectionPoint.getLatitude(), intersectionPoint.getLongitude());

      return newPos;

    } else {
      System.out.println("something went bad... for mouse bearing " + bearing);

      return null;
    }
  }