コード例 #1
0
ファイル: OsmReader.java プロジェクト: sbrunner/josm
  protected Way parseWay() throws XMLStreamException {
    WayData wd = new WayData();
    readCommon(wd);
    Way w = new Way(wd.getId(), wd.getVersion());
    w.setVisible(wd.isVisible());
    w.load(wd);
    externalIdMap.put(wd.getPrimitiveId(), w);

    Collection<Long> nodeIds = new ArrayList<Long>();
    while (true) {
      int event = parser.next();
      if (event == XMLStreamConstants.START_ELEMENT) {
        if (parser.getLocalName().equals("nd")) {
          nodeIds.add(parseWayNode(w));
        } else if (parser.getLocalName().equals("tag")) {
          parseTag(w);
        } else {
          parseUnknown();
        }
      } else if (event == XMLStreamConstants.END_ELEMENT) {
        break;
      }
    }
    if (w.isDeleted() && nodeIds.size() > 0) {
      System.out.println(tr("Deleted way {0} contains nodes", w.getUniqueId()));
      nodeIds = new ArrayList<Long>();
    }
    ways.put(wd.getUniqueId(), nodeIds);
    return w;
  }
コード例 #2
0
 public void visit(Way w) {
   if (w.isNewOrUndeleted() || w.isModified() || w.isDeleted()) {
     // upload new ways as well as modified and deleted ones
     hull.add(w);
     for (Node n : w.getNodes()) {
       // we upload modified nodes even if they aren't in the current
       // selection.
       n.visit(this);
     }
   }
 }
コード例 #3
0
  /**
   * Create OSM graph for routing
   *
   * @return
   */
  public void createGraph() {

    logger.debug("Creating Graph...");
    graph = new DirectedWeightedMultigraph<>(OsmEdge.class);
    rgDelegator = new RoutingGraphDelegator(graph);
    rgDelegator.setRouteType(this.routeType);
    // iterate all ways and segments for all nodes:
    for (Way way : data.getWays()) {

      // skip way if not suitable for routing.
      if (way == null || way.isDeleted() || !this.isvalidWay(way) || way.getNodes().size() < 1)
        continue;

      // INIT
      Node from = null;
      Node to = null;
      List<Node> nodes = way.getNodes();
      int nodes_count = nodes.size();

      /*
       * Assume node is A B C D E. The procedure should be
       *
       *  case 1 - bidirectional ways:
       *  1) Add vertex A B C D E
       *  2) Link A<->B, B<->C, C<->D, D<->E as Edges
       *
       *  case 2 - oneway reverse:
       *  1) Add vertex A B C D E
       *  2) Link B->A,C->B,D->C,E->D as Edges. result: A<-B<-C<-D<-E
       *
       *  case 3 - oneway normal:
       *  1) Add vertex A B C D E
       *  2) Link A->B, B->C, C->D, D->E as Edges. result: A->B->C->D->E
       *
       *
       */

      String oneway_val = way.get("oneway"); /*   get (oneway=?) tag for this way.   */
      String junction_val = way.get("junction"); /*   get (junction=?) tag for this way.   */

      from = nodes.get(0); /*   1st node A  */
      graph.addVertex(from); /*   add vertex A */

      for (int i = 1; i < nodes_count; i++) {
        /*   loop from B until E */

        to = nodes.get(i); /*   2nd node B   */

        if (to != null && !to.isDeleted()) {
          graph.addVertex(to); /*   add vertex B */

          // this is where we link the vertices
          if (!routingProfile.isOnewayUsed()) {
            // "Ignore oneways" is selected
            addEdgeBidirectional(way, from, to);

          } else if (oneway_val == null && junction_val == "roundabout") {
            // Case (roundabout): oneway=implicit yes
            addEdgeNormalOneway(way, from, to);

          } else if (oneway_val == null
              || oneway_val == "false"
              || oneway_val == "no"
              || oneway_val == "0") {
            // Case (bi-way): oneway=false OR oneway=unset OR oneway=0 OR oneway=no
            addEdgeBidirectional(way, from, to);

          } else if (oneway_val == "-1") {
            // Case (oneway reverse): oneway=-1
            addEdgeReverseOneway(way, from, to);

          } else if (oneway_val == "1" || oneway_val == "yes" || oneway_val == "true") {
            // Case (oneway normal): oneway=yes OR 1 OR true
            addEdgeNormalOneway(way, from, to);
          }

          from = to; /*   we did A<->B, next loop we will do B<->C, so from=B,to=C for next loop. */
        }
      } // end of looping thru nodes
    } // end of looping thru ways

    logger.debug("End Create Graph");
    logger.debug("Vertex: " + graph.vertexSet().size());
    logger.debug("Edges: " + graph.edgeSet().size());
  }