@Override
  public int addEdge(TLongList osmIds, int flags) {
    PointList pointList = new PointList(osmIds.size());
    int successfullyAdded = 0;
    int firstNode = -1;
    int lastIndex = osmIds.size() - 1;
    int lastInBoundsPillarNode = -1;
    for (int i = 0; i < osmIds.size(); i++) {
      long osmId = osmIds.get(i);
      int tmpNode = osmIdToIndexMap.get(osmId);
      if (tmpNode == EMPTY) continue;
      // skip osmIds with no associated pillar or tower id (e.g. !OSMReader.isBounds)
      if (tmpNode == TOWER_NODE) continue;
      if (tmpNode == PILLAR_NODE) {
        // In some cases no node information is saved for the specified osmId.
        // ie. a way references a <node> which does not exist in the current file.
        // => if the node before was a pillar node then convert into to tower node (as it is also
        // end-standing).
        if (!pointList.isEmpty() && lastInBoundsPillarNode > -TOWER_NODE) {
          // transform the pillar node to a tower node
          tmpNode = lastInBoundsPillarNode;
          tmpNode = handlePillarNode(tmpNode, osmId, null, true);
          tmpNode = -tmpNode - 3;
          if (pointList.size() > 1 && firstNode >= 0) {
            // TOWER node
            successfullyAdded += addEdge(firstNode, tmpNode, pointList, flags);
            pointList.clear();
            pointList.add(g.getLatitude(tmpNode), g.getLongitude(tmpNode));
          }
          firstNode = tmpNode;
          lastInBoundsPillarNode = -1;
        }
        continue;
      }

      if (tmpNode <= -TOWER_NODE && tmpNode >= TOWER_NODE)
        throw new AssertionError("Mapped index not in correct bounds " + tmpNode + ", " + osmId);

      if (tmpNode > -TOWER_NODE) {
        boolean convertToTowerNode = i == 0 || i == lastIndex;
        if (!convertToTowerNode) lastInBoundsPillarNode = tmpNode;

        // PILLAR node, but convert to towerNode if end-standing
        tmpNode = handlePillarNode(tmpNode, osmId, pointList, convertToTowerNode);
      }

      if (tmpNode < TOWER_NODE) {
        // TOWER node
        tmpNode = -tmpNode - 3;
        pointList.add(g.getLatitude(tmpNode), g.getLongitude(tmpNode));
        if (firstNode >= 0) {
          successfullyAdded += addEdge(firstNode, tmpNode, pointList, flags);
          pointList.clear();
          pointList.add(g.getLatitude(tmpNode), g.getLongitude(tmpNode));
        }
        firstNode = tmpNode;
      }
    }
    return successfullyAdded;
  }
Example #2
0
  private void process(OsmRelation relation) {
    boolean hasChildRelations = false;
    TLongList childRelationMembers = new TLongArrayList();
    for (OsmRelationMember member : OsmModelUtil.membersAsList(relation)) {
      if (member.getType() == EntityType.Relation) {
        hasChildRelations = true;
        idsIsChildRelation.add(member.getId());
        childRelationMembers.add(member.getId());
        if (storeSimpleRelations) {
          idsSimpleRelations.remove(member.getId());
        }
      }
    }
    long id = relation.getId();
    if (hasChildRelations) {
      idsHasChildRelations.add(id);
      if (!graph.getNodes().contains(id)) {
        graph.addNode(id);
      }

      TLongIterator iterator = childRelationMembers.iterator();
      while (iterator.hasNext()) {
        long member = iterator.next();
        if (!graph.getNodes().contains(member)) {
          graph.addNode(member);
        }
        graph.addEdge(id, member);
      }
    } else {
      if (storeSimpleRelations && !idsIsChildRelation.contains(id)) {
        idsSimpleRelations.add(id);
      }
      numNoChildren++;
    }
  }
 /** @return null when not found */
 public TLongList listLabelIds(long bukmak2_id) {
   TLongList res = null;
   Cursor cursor =
       helper
           .getReadableDatabase()
           .rawQuery(
               "select "
                   + Db.TABEL_Bukmak2_Label
                   + "."
                   + Db.Bukmak2_Label.label_id
                   + " from "
                   + Db.TABEL_Bukmak2_Label
                   + " where "
                   + Db.TABEL_Bukmak2_Label
                   + "."
                   + Db.Bukmak2_Label.bukmak2_id
                   + "=?",
               new String[] {
                 String.valueOf(bukmak2_id)
               }); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$//$NON-NLS-5$//$NON-NLS-6$
   try {
     int col_label_id = cursor.getColumnIndexOrThrow(Db.Bukmak2_Label.label_id);
     while (cursor.moveToNext()) {
       if (res == null) res = new TLongArrayList();
       res.add(cursor.getLong(col_label_id));
     }
   } finally {
     cursor.close();
   }
   return res;
 }
  @Override
  public int addEdge(TLongList nodes, int flags) {
    PointList pointList = new PointList(nodes.size());
    int successfullyAdded = 0;
    int firstNode = -1;
    int lastIndex = nodes.size() - 1;
    int lastInBoundsPillarNode = -1;
    for (int i = 0; i < nodes.size(); i++) {
      long osmId = nodes.get(i);
      int tmpNode = osmIdToIndexMap.get(osmId);
      if (tmpNode == EMPTY) continue;
      // skip osmIds with no associated pillar or tower id (e.g. !OSMReader.isBounds)
      if (tmpNode == TOWER_NODE) continue;
      if (tmpNode == PILLAR_NODE) {
        // no pillarLats,pillarLons was saved for tmpNode
        // so if there are any existing pillar nodes we need to create an edge out of them
        if (!pointList.isEmpty() && lastInBoundsPillarNode >= 3) {
          // transform the pillar node to a tower node
          tmpNode = lastInBoundsPillarNode;
          tmpNode = handlePillarNode(tmpNode, osmId, null, true);
          tmpNode = -tmpNode - 3;
          if (pointList.size() > 1 && firstNode >= 0) {
            // TOWER node
            successfullyAdded += addEdge(firstNode, tmpNode, pointList, flags);
            pointList.clear();
            pointList.add(g.getLatitude(tmpNode), g.getLongitude(tmpNode));
          }
          firstNode = tmpNode;
          lastInBoundsPillarNode = -1;
        }
        continue;
      }

      if (tmpNode <= -TOWER_NODE && tmpNode >= TOWER_NODE)
        throw new AssertionError("Mapped index not in correct bounds " + tmpNode);

      if (tmpNode > -TOWER_NODE) {
        lastInBoundsPillarNode = tmpNode;
        // PILLAR node, but convert to towerNode if end-standing
        tmpNode = handlePillarNode(tmpNode, osmId, pointList, i == 0 || i == lastIndex);
      }

      if (tmpNode < TOWER_NODE) {
        // TOWER node
        tmpNode = -tmpNode - 3;
        pointList.add(g.getLatitude(tmpNode), g.getLongitude(tmpNode));
        if (firstNode >= 0) {
          successfullyAdded += addEdge(firstNode, tmpNode, pointList, flags);
          pointList.clear();
          pointList.add(g.getLatitude(tmpNode), g.getLongitude(tmpNode));
        }
        firstNode = tmpNode;
      }
    }
    return successfullyAdded;
  }
Example #5
0
 @Override
 public IdContainer next() {
   long id = ids.get(pointer);
   pointer += 1;
   available -= 1;
   return new IdContainer(entityType, id);
 }
Example #6
0
  protected void readNodes(XMLStreamReader parser) throws XMLStreamException {
    int event = parser.getEventType();
    while (event != XMLStreamConstants.END_DOCUMENT && parser.getLocalName().equals("nd")) {
      if (event == XMLStreamConstants.START_ELEMENT) {
        // read node reference
        String ref = parser.getAttributeValue(null, "ref");
        nodes.add(Long.parseLong(ref));
      }

      event = parser.nextTag();
    }
  }
Example #7
0
 @Override
 public String toString() {
   return "Way (" + getId() + ", " + nodes.size() + " nodes)";
 }