コード例 #1
0
ファイル: BaseRoute.java プロジェクト: gitsnaf/RouteConverter
  public void ensureIncreasingTime() {
    if (getPositionCount() < 2) return;

    long completeTime = getTime(); // ms
    double completeDistance = getDistance(); // m
    double averageSpeed = completeTime > 0 ? completeDistance / completeTime * 1000 : 1.0; // m/s

    List<P> positions = getPositions();
    P first = positions.get(0);
    if (!first.hasTime()) first.setTime(fromCalendar(Calendar.getInstance(UTC)));

    P previous = first;
    for (int i = 1; i < positions.size(); i++) {
      P next = positions.get(i);
      CompactCalendar time = next.getTime();
      if (time == null || time.equals(previous.getTime())) {
        Double distance = next.calculateDistance(previous);
        Long millis = distance != null ? (long) (distance / averageSpeed * 1000) : null;
        if (millis == null || millis < 1000) millis = 1000L;
        next.setTime(
            fromMillisAndTimeZone(
                previous.getTime().getTimeInMillis() + millis, previous.getTime().getTimeZoneId()));
      }
      previous = next;
    }
  }
コード例 #2
0
ファイル: BaseRoute.java プロジェクト: gitsnaf/RouteConverter
 private void move(int index, int upOrDown) {
   List<P> positions = getPositions();
   P move = positions.get(index);
   P replace = positions.get(index + upOrDown);
   positions.set(index + upOrDown, move);
   positions.set(index, replace);
 }
コード例 #3
0
ファイル: BaseRoute.java プロジェクト: gitsnaf/RouteConverter
 public void sort(Comparator<P> comparator) {
   List<P> positions = getPositions();
   @SuppressWarnings({"SuspiciousToArrayCall", "unchecked"})
   P[] sorted = (P[]) positions.toArray(new BaseNavigationPosition[positions.size()]);
   Arrays.sort(sorted, comparator);
   //noinspection unchecked
   order(asList(sorted));
 }
コード例 #4
0
ファイル: BaseRoute.java プロジェクト: gitsnaf/RouteConverter
 public int[] getContainedPositions(BoundingBox boundingBox) {
   List<Integer> result = new ArrayList<>();
   List<P> positions = getPositions();
   for (int i = 0; i < positions.size(); i++) {
     P position = positions.get(i);
     if (position.hasCoordinates() && boundingBox.contains(position)) result.add(i);
   }
   return toArray(result);
 }
コード例 #5
0
ファイル: BaseRoute.java プロジェクト: gitsnaf/RouteConverter
  @SuppressWarnings("UnusedDeclaration")
  public ViaMichelinRoute asViaMichelinFormat() {
    if (getFormat() instanceof ViaMichelinFormat) return (ViaMichelinRoute) this;

    List<Wgs84Position> wgs84Positions = new ArrayList<>();
    for (P position : getPositions()) {
      wgs84Positions.add(position.asWgs84Position());
    }
    return new ViaMichelinRoute(getName(), wgs84Positions);
  }
コード例 #6
0
ファイル: BaseRoute.java プロジェクト: gitsnaf/RouteConverter
  @SuppressWarnings("UnusedDeclaration")
  public GarminFlightPlanRoute asGarminFlightPlanFormat() {
    if (getFormat() instanceof GarminFlightPlanFormat) return (GarminFlightPlanRoute) this;

    List<GarminFlightPlanPosition> flightPlanPositions = new ArrayList<>();
    for (P position : getPositions()) {
      flightPlanPositions.add(position.asGarminFlightPlanPosition());
    }
    return new GarminFlightPlanRoute(getName(), getDescription(), flightPlanPositions);
  }
コード例 #7
0
ファイル: BaseRoute.java プロジェクト: gitsnaf/RouteConverter
  @SuppressWarnings("UnusedDeclaration")
  public MagicMapsIktRoute asMagicMapsIktFormat() {
    if (getFormat() instanceof MagicMapsIktFormat) return (MagicMapsIktRoute) this;

    List<Wgs84Position> wgs84Positions = new ArrayList<>();
    for (P position : getPositions()) {
      wgs84Positions.add(position.asWgs84Position());
    }
    return new MagicMapsIktRoute(getName(), getDescription(), wgs84Positions);
  }
コード例 #8
0
ファイル: BaseRoute.java プロジェクト: gitsnaf/RouteConverter
 public double getElevationDelta(int index) {
   List<P> positions = getPositions();
   NavigationPosition previous = index > 0 ? positions.get(index - 1) : null;
   NavigationPosition current = index < positions.size() ? positions.get(index) : null;
   if (previous != null && current != null) {
     Double elevation = previous.calculateElevation(current);
     if (elevation != null) return elevation;
   }
   return 0;
 }
コード例 #9
0
ファイル: BaseRoute.java プロジェクト: gitsnaf/RouteConverter
  @SuppressWarnings("UnusedDeclaration")
  public OvlRoute asOvlFormat() {
    if (getFormat() instanceof OvlFormat) return (OvlRoute) this;

    List<Wgs84Position> ovlPositions = new ArrayList<>();
    for (P position : getPositions()) {
      ovlPositions.add(position.asOvlPosition());
    }
    return new OvlRoute(getCharacteristics(), getName(), ovlPositions);
  }
コード例 #10
0
ファイル: BaseRoute.java プロジェクト: gitsnaf/RouteConverter
  @SuppressWarnings("UnusedDeclaration")
  public TourRoute asTourFormat() {
    if (getFormat() instanceof TourFormat) return (TourRoute) this;

    List<TourPosition> tourPositions = new ArrayList<>();
    for (P position : getPositions()) {
      tourPositions.add(position.asTourPosition());
    }
    return new TourRoute(getName(), tourPositions);
  }
コード例 #11
0
ファイル: BaseRoute.java プロジェクト: gitsnaf/RouteConverter
  @SuppressWarnings("UnusedDeclaration")
  public MagicMapsPthRoute asMagicMapsPthFormat() {
    if (getFormat() instanceof MagicMapsPthFormat) return (MagicMapsPthRoute) this;

    List<GkPosition> gkPositions = new ArrayList<>();
    for (P position : getPositions()) {
      gkPositions.add(position.asGkPosition());
    }
    return new MagicMapsPthRoute(getCharacteristics(), gkPositions);
  }
コード例 #12
0
ファイル: BaseRoute.java プロジェクト: gitsnaf/RouteConverter
  @SuppressWarnings("UnusedDeclaration")
  public NokiaLandmarkExchangeRoute asNokiaLandmarkExchangeFormat() {
    if (getFormat() instanceof NokiaLandmarkExchangeFormat)
      return (NokiaLandmarkExchangeRoute) this;

    List<Wgs84Position> wgs84Positions = new ArrayList<>();
    for (P position : getPositions()) {
      wgs84Positions.add(position.asWgs84Position());
    }
    return new NokiaLandmarkExchangeRoute(getName(), getDescription(), wgs84Positions);
  }
コード例 #13
0
ファイル: BaseRoute.java プロジェクト: gitsnaf/RouteConverter
 /**
  * Removes duplicate adjacent {@link #getPositions() positions} from this route, leaving only
  * distinct neighbours
  */
 public void removeDuplicates() {
   List<P> positions = getPositions();
   P previous = null;
   int index = 0;
   while (index < positions.size()) {
     P next = positions.get(index);
     if (previous != null && (!next.hasCoordinates() || next.calculateDistance(previous) <= 0.0)) {
       positions.remove(index);
     } else index++;
     previous = next;
   }
 }
コード例 #14
0
ファイル: BaseRoute.java プロジェクト: gitsnaf/RouteConverter
 public double getDistance(int startIndex, int endIndex) {
   double result = 0;
   List<P> positions = getPositions();
   NavigationPosition previous = null;
   for (int i = startIndex; i <= endIndex; i++) {
     NavigationPosition next = positions.get(i);
     if (previous != null) {
       Double distance = previous.calculateDistance(next);
       if (distance != null) result += distance;
     }
     previous = next;
   }
   return result;
 }
コード例 #15
0
ファイル: BaseRoute.java プロジェクト: gitsnaf/RouteConverter
 public double getElevationDescend(int startIndex, int endIndex) {
   double result = 0;
   List<P> positions = getPositions();
   NavigationPosition previous = null;
   for (int i = startIndex; i <= endIndex; i++) {
     NavigationPosition next = positions.get(i);
     if (previous != null) {
       Double elevation = previous.calculateElevation(next);
       if (elevation != null && elevation < 0) result += abs(elevation);
     }
     previous = next;
   }
   return result;
 }
コード例 #16
0
ファイル: BaseRoute.java プロジェクト: gitsnaf/RouteConverter
  public void revert() {
    List<P> positions = getPositions();
    List<P> reverted = new ArrayList<>();
    for (P position : positions) {
      reverted.add(0, position);
    }
    order(reverted);

    String routeName = getName();
    if (!routeName.endsWith(REVERSE_ROUTE_NAME_POSTFIX))
      routeName = routeName + REVERSE_ROUTE_NAME_POSTFIX;
    else
      routeName = routeName.substring(0, routeName.length() - REVERSE_ROUTE_NAME_POSTFIX.length());
    setName(routeName);
  }
コード例 #17
0
ファイル: BaseRoute.java プロジェクト: gitsnaf/RouteConverter
  public int getClosestPosition(double longitude, double latitude, double threshold) {
    int closestIndex = -1;
    double closestDistance = MAX_VALUE;

    List<P> positions = getPositions();
    for (int i = 0; i < positions.size(); ++i) {
      P point = positions.get(i);
      Double distance = point.calculateDistance(longitude, latitude);
      if (distance != null && distance < closestDistance && distance < threshold) {
        closestDistance = distance;
        closestIndex = i;
      }
    }
    return closestIndex;
  }
コード例 #18
0
ファイル: BaseRoute.java プロジェクト: gitsnaf/RouteConverter
 public double[] getDistancesFromStart(int startIndex, int endIndex) {
   double[] result = new double[endIndex - startIndex + 1];
   List<P> positions = getPositions();
   int index = 0;
   double distance = 0.0;
   NavigationPosition previous = positions.size() > 0 ? positions.get(0) : null;
   while (index <= endIndex) {
     NavigationPosition next = positions.get(index);
     if (previous != null) {
       Double delta = previous.calculateDistance(next);
       if (delta != null) distance += delta;
       if (index >= startIndex) result[index - startIndex] = distance;
     }
     index++;
     previous = next;
   }
   return result;
 }
コード例 #19
0
ファイル: BaseRoute.java プロジェクト: gitsnaf/RouteConverter
 public int[] getPositionsWithinDistanceToPredecessor(double distance) {
   List<Integer> result = new ArrayList<>();
   List<P> positions = getPositions();
   if (positions.size() <= 2) return new int[0];
   P previous = positions.get(0);
   for (int i = 1; i < positions.size() - 1; i++) {
     P next = positions.get(i);
     if (!next.hasCoordinates() || next.calculateDistance(previous) <= distance) result.add(i);
     else previous = next;
   }
   return toArray(result);
 }
コード例 #20
0
ファイル: BaseRoute.java プロジェクト: gitsnaf/RouteConverter
  public double[] getDistancesFromStart(int[] indices) {
    double[] result = new double[indices.length];
    if (indices.length > 0 && getPositionCount() > 0) {
      Arrays.sort(indices);
      int endIndex = min(indices[indices.length - 1], getPositionCount() - 1);

      int index = 0;
      double distance = 0.0;
      List<P> positions = getPositions();
      NavigationPosition previous = positions.get(0);
      while (index <= endIndex) {
        NavigationPosition next = positions.get(index);
        if (previous != null) {
          Double delta = previous.calculateDistance(next);
          if (delta != null) distance += delta;
          int indexInIndices = binarySearch(indices, index);
          if (indexInIndices >= 0) result[indexInIndices] = distance;
        }
        index++;
        previous = next;
      }
    }
    return result;
  }
コード例 #21
0
ファイル: BaseRoute.java プロジェクト: gitsnaf/RouteConverter
 public void order(List<P> positions) {
   List<P> existing = getPositions();
   for (int i = 0; i < positions.size(); i++) {
     existing.set(i, positions.get(i));
   }
 }
コード例 #22
0
ファイル: BaseRoute.java プロジェクト: gitsnaf/RouteConverter
 public P getSuccessor(P position) {
   List<P> positions = getPositions();
   int index = positions.indexOf(position);
   return index != -1 && index < positions.size() - 1 ? positions.get(index + 1) : null;
 }
コード例 #23
0
ファイル: BaseRoute.java プロジェクト: gitsnaf/RouteConverter
 public P remove(int index) {
   List<P> positions = getPositions();
   return positions.remove(index);
 }