コード例 #1
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++;
    }
  }
コード例 #2
0
  private void extract(Path path) throws IOException {
    Path pathWays = path.resolve(fileNamesWays);
    Path pathNodeIds = path.resolve(fileNamesNodeIds);

    InputStream input = StreamUtil.bufferedInputStream(pathWays.toFile());
    OsmIterator osmIterator = OsmIoUtils.setupOsmIterator(input, inputFormat, false);

    OutputStream outputNodeIds = StreamUtil.bufferedOutputStream(pathNodeIds.toFile());
    IdListOutputStream idOutputNodeIds = new IdListOutputStream(outputNodeIds);

    TLongSet nodeIdsSet = new TLongHashSet();

    for (EntityContainer container : osmIterator) {
      if (container.getType() != EntityType.Way) {
        continue;
      }
      OsmWay way = (OsmWay) container.getEntity();
      for (long id : OsmModelUtil.nodesAsList(way).toArray()) {
        nodeIdsSet.add(id);
      }
    }

    input.close();

    long[] nodesIds = nodeIdsSet.toArray();
    Arrays.sort(nodesIds);
    for (long id : nodesIds) {
      idOutputNodeIds.write(id);
    }
    idOutputNodeIds.close();
  }