/** * handle the crossroads... * * @param wayList */ private void handleCrossRoads(List<Way> wayList) { int z = 0; List<Way> splittedWay = new ArrayList<Way>(); for (Waypoint waypoint : allWaypoints.values()) { if (waypoint.getAddedWays().size() > 1) { for (Way way : waypoint.getAddedWays()) { if (way.getStart() == waypoint || way.getEnd() == waypoint) { z++; } else { way.addSplitPoint(waypoint); if (!splittedWay.contains(way)) { splittedWay.add(way); } } } } } for (Way way : splittedWay) { effectiveWayList.remove(way); int start = 0; int end = 0; long generatedKey = 0; List<Waypoint> splitWaypointList = sortWaypoints(way.getWaypointList(), way.getSplitPointList()); for (Waypoint waypoint : splitWaypointList) { end = way.getWaypointList().indexOf(waypoint); if (end < start) { int temp = end; end = start; start = temp; } List<Waypoint> newWaypoints = getWaypointSubset(start, end, way.getWaypointList()); Way newWay = new Way(); newWay.setStatus(WayStatusEnum.undefined); generatedKey = way.getWayID() + 1; while (allWays.containsKey(generatedKey)) { generatedKey++; } newWay.setWayID(generatedKey); newWay.setName(way.getWayID() + "Part" + start + "-" + end); Waypoint startPoint = newWaypoints.get(0); Waypoint endPoint = waypoint; newWay.setStart(startPoint); newWay.setEnd(endPoint); newWay.setWaypointList(newWaypoints); effectiveWayList.add(newWay); allWays.put(newWay.getWayID(), newWay); start = end; } if (end != way.getWaypointList().size() - 1) { end = way.getWaypointList().size() - 1; List<Waypoint> newWaypoints = getWaypointSubset(start, end, way.getWaypointList()); Way newWay = new Way(); newWay.setStatus(WayStatusEnum.undefined); newWay.setName(way.getWayID() + "Part" + start + "-" + end); while (allWays.containsKey(generatedKey)) { generatedKey++; } newWay.setWayID(generatedKey); start = 0; end = newWaypoints.size() - 1; Waypoint startPoint = newWaypoints.get(start); Waypoint endPoint = newWaypoints.get(end); newWay.setStart(startPoint); newWay.setEnd(endPoint); newWay.setWaypointList(newWaypoints); effectiveWayList.add(newWay); allWays.put(newWay.getWayID(), newWay); } } }
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; }