示例#1
0
  /**
   * get all ways
   *
   * @param allWaypoints
   * @param document
   * @param xpath
   * @return
   * @throws Exception
   */
  private List<Way> getSelectedWays(byte[] array, Map<Long, Waypoint> allWaypoints)
      throws IOException {
    List<Way> matchingWayList = new ArrayList<Way>();
    effectiveWayList = new ArrayList<Way>();

    VTDGen vg = new VTDGen();
    vg.setDoc(array);
    try {
      vg.parse(false);
    } catch (EncodingException e) {
      logger.fatal(e);
      throw new RuntimeException(e);
    } catch (EOFException e) {
      logger.fatal(e);
      throw new RuntimeException(e);
    } catch (EntityException e) {
      logger.fatal(e);
      throw new RuntimeException(e);
    } catch (ParseException e) {
      logger.fatal(e);
      throw new RuntimeException(e);
    }

    VTDNav vn = vg.getNav();

    AutoPilot ap = new AutoPilot(vn);
    ap.selectElement("way");

    try {
      while (ap.iterate()) {
        int idPos = vn.getAttrVal("id");

        long wayId = Long.parseLong(vn.toString(idPos));

        Way way = new Way(wayId);
        way.setStatus(WayStatusEnum.undefined);

        vn.toElement(VTDNav.FIRST_CHILD, "nd");
        do {
          int wpIdPos = vn.getAttrVal("ref");
          long wpId = Long.parseLong(vn.toString(wpIdPos));
          way.addWaypoint(allWaypoints.get(wpId));
          allWaypoints.get(wpId).addWay(way);
        } while (vn.toElement(VTDNav.NEXT_SIBLING, "nd"));

        // get start and end waypoint
        Waypoint tempStartWaypoint = way.getWaypointList().get(0);
        int lastTempWaypoint = way.getWaypointList().size() - 1;
        Waypoint tempEndWaypoint = way.getWaypointList().get(lastTempWaypoint);

        // set start and end for the way
        way.setStart(tempStartWaypoint);
        way.setEnd(tempEndWaypoint);

        allWays.put(way.getWayID(), way);
        matchingWayList.add(way);
      }
    } catch (PilotException e) {
      logger.fatal(e);
      throw new RuntimeException(e);
    } catch (NumberFormatException e) {
      logger.fatal(e);
      throw new RuntimeException(e);
    } catch (NavException e) {
      logger.fatal(e);
      throw new RuntimeException(e);
    }

    effectiveWayList.addAll(matchingWayList);

    return matchingWayList;
  }
示例#2
0
  private Map<Long, Waypoint> getAllWaypointFromDocument(byte[] array) {

    allWaypoints = new HashMap<Long, Waypoint>();

    VTDGen vg = new VTDGen();
    vg.setDoc(array);
    try {
      vg.parse(false);
    } catch (EncodingException e) {
      logger.fatal(e);
    } catch (EOFException e) {
      logger.fatal(e);
      throw new RuntimeException(e);
    } catch (EntityException e) {
      logger.fatal(e);
      throw new RuntimeException(e);
    } catch (ParseException e) {
      logger.fatal(e);
      throw new RuntimeException(e);
    }

    VTDNav vn = vg.getNav();

    AutoPilot ap = new AutoPilot(vn);

    ap.selectElement("node");

    try {
      while (ap.iterate()) {

        int latPos = vn.getAttrVal("lat");
        int lonPos = vn.getAttrVal("lon");
        int idPos = vn.getAttrVal("id");

        double lat = Double.parseDouble(vn.toString(latPos));

        double lon = Double.parseDouble(vn.toString(lonPos));

        long id = Long.parseLong(vn.toString(idPos));

        Waypoint waypoint = new Waypoint();

        waypoint.setWaypointID(id);

        // set latitude and longitude for waypoint
        waypoint.setLat(lat);
        waypoint.setLon(lon);

        // set position (lon and lat in one value)
        Angle latAngle = Angle.fromDegreesLatitude(lat);
        Angle lonAngle = Angle.fromDegreesLatitude(lon);
        Position pos = new Position(latAngle, lonAngle, 0);
        waypoint.setCenter(pos);

        allWaypoints.put(id, waypoint);
      }
    } catch (PilotException e) {
      logger.fatal(e);
      throw new RuntimeException(e);
    } catch (NavException e) {
      logger.fatal(e);
      throw new RuntimeException(e);
    }

    return allWaypoints;
  }