Exemplo n.º 1
0
  /* computes the distance, in meters, along a geometry */
  protected static double distanceAlongGeometry(
      Geometry geometry, LinearLocation startIndex, LinearLocation endIndex) {

    if (endIndex == null) {
      endIndex = LinearLocation.getEndLocation(geometry);
    }
    double total = 0;
    LinearIterator it = new LinearIterator(geometry, startIndex);
    LinearLocation index = startIndex;
    Coordinate previousCoordinate = startIndex.getCoordinate(geometry);

    it.next();
    index = it.getLocation();
    while (index.compareTo(endIndex) < 0) {
      Coordinate thisCoordinate = index.getCoordinate(geometry);
      double distance = SphericalDistanceLibrary.fastDistance(previousCoordinate, thisCoordinate);
      total += distance;
      previousCoordinate = thisCoordinate;
      if (!it.hasNext()) break;
      it.next();
      index = it.getLocation();
    }
    // now, last bit of last segment
    Coordinate finalCoordinate = endIndex.getCoordinate(geometry);
    total += SphericalDistanceLibrary.distance(previousCoordinate, finalCoordinate);

    return total;
  }
  /** calculate the length of this street segement from its geometry */
  protected void calculateLengthFromGeometry() {
    double accumulatedMeters = 0;

    LineString geom = getGeometry();

    for (int i = 1; i < geom.getNumPoints(); i++) {
      accumulatedMeters +=
          SphericalDistanceLibrary.distance(geom.getCoordinateN(i - 1), geom.getCoordinateN(i));
    }

    length_mm = (int) (accumulatedMeters * 1000);
  }
Exemplo n.º 3
0
 /**
  * Find transfer candidates for profile routing. TODO replace with an on-street search using the
  * existing profile router functions.
  */
 public Map<StopCluster, Double> findNearbyStopClusters(StopCluster sc, double radius) {
   Map<StopCluster, Double> ret = Maps.newHashMap();
   Envelope env = new Envelope(new Coordinate(sc.lon, sc.lat));
   env.expandBy(
       SphericalDistanceLibrary.metersToLonDegrees(radius, sc.lat),
       SphericalDistanceLibrary.metersToDegrees(radius));
   for (StopCluster cluster : stopClusterSpatialIndex.query(env)) {
     // TODO this should account for area-like nature of clusters. Use size of bounding boxes.
     double distance = SphericalDistanceLibrary.distance(sc.lat, sc.lon, cluster.lat, cluster.lon);
     if (distance < radius) ret.put(cluster, distance);
   }
   return ret;
 }