Пример #1
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;
  }