Esempio n. 1
0
 /** Constructor for XML Parser */
 public static OSMWay create(long id, XMLStreamReader parser) throws XMLStreamException {
   OSMWay way = new OSMWay(id);
   parser.nextTag();
   way.readNodes(parser);
   way.readTags(parser);
   return way;
 }
Esempio n. 2
0
  /** Special handling for ferry ways. */
  protected long handleFerry(
      OSMWay way, int unknownSpeed, int shortTripsSpeed, int longTripsSpeed) {
    // to hours
    double durationInHours = parseDuration(way.getTag("duration")) / 60d;
    if (durationInHours > 0)
      try { // to km
        double estimatedLength = Double.parseDouble(way.getTag("estimated_distance")) / 1000;

        // If duration AND distance is available we can calculate the speed more precisely
        // and set both speed to the same value. Factor 1.4 slower because of waiting time!
        shortTripsSpeed = (int) Math.round(estimatedLength / durationInHours / 1.4);
        if (shortTripsSpeed > getMaxSpeed()) shortTripsSpeed = getMaxSpeed();
        longTripsSpeed = shortTripsSpeed;
      } catch (Exception ex) {
      }

    if (durationInHours == 0) {
      // unknown speed -> put penalty on ferry transport
      return speedEncoder.setValue(0, unknownSpeed);
    } else if (durationInHours > 1) {
      // lengthy ferries should be faster than short trip ferry
      return speedEncoder.setValue(0, longTripsSpeed);
    } else {
      return speedEncoder.setValue(0, shortTripsSpeed);
    }
  }
  @Override
  public int handleWayTags(int allowed, OSMWay way) {
    if ((allowed & acceptBit) == 0) return 0;

    int encoded;
    if ((allowed & ferryBit) == 0) {
      String sacScale = way.getTag("sac_scale");
      if (sacScale != null) {
        if ("hiking".equals(sacScale)) encoded = speedEncoder.setValue(0, MEAN);
        else encoded = speedEncoder.setValue(0, SLOW);
      } else {
        encoded = speedEncoder.setValue(0, MEAN);
      }
      encoded |= directionBitMask;

      // mark safe ways or ways with cycle lanes
      if (safeHighwayTags.contains(way.getTag("highway")) || way.hasTag("sidewalk", sidewalks)) {
        encoded |= safeWayBit;
      }

    } else {
      int durationInMinutes = parseDuration(way.getTag("duration"));
      if (durationInMinutes == 0) {
        // unknown speed -> put penalty on ferry transport
        encoded = speedEncoder.setValue(0, SLOW);
      } else if (durationInMinutes > 60) {
        // lengthy ferries should be faster than average hiking
        encoded = speedEncoder.setValue(0, FERRY);
      } else {
        encoded = speedEncoder.setValue(0, MEAN);
      }

      encoded |= directionBitMask;
    }

    return encoded;
  }
  /**
   * Some ways are okay but not separate for pedestrians.
   *
   * <p>
   *
   * @param way
   */
  @Override
  public int isAllowed(OSMWay way) {
    String highwayValue = way.getTag("highway");
    if (highwayValue == null) {
      if (way.hasTag("route", ferries)) {
        String footTag = way.getTag("foot");
        if (footTag == null || "yes".equals(footTag)) return acceptBit | ferryBit;
      }
      return 0;
    }

    String sacScale = way.getTag("sac_scale");
    if (sacScale != null) {
      if (!"hiking".equals(sacScale) && !"mountain_hiking".equals(sacScale))
        // other scales are too dangerous, see http://wiki.openstreetmap.org/wiki/Key:sac_scale
        return 0;
    }

    if (way.hasTag("sidewalk", sidewalks)) return acceptBit;

    // no need to evaluate ferries or fords - already included here
    if (way.hasTag("foot", intended)) return acceptBit;

    if (!allowedHighwayTags.contains(highwayValue)) return 0;

    if (way.hasTag("motorroad", "yes")) return 0;

    // do not get our feet wet, "yes" is already included above
    if (way.hasTag("highway", "ford") || way.hasTag("ford")) return 0;

    if (way.hasTag("bicycle", "official")) return 0;

    // check access restrictions
    if (way.hasTag(restrictions, restrictedValues)) return 0;

    // do not accept railways (sometimes incorrectly mapped!)
    if (way.hasTag("railway") && !way.hasTag("railway", acceptedRailways)) return 0;

    return acceptBit;
  }