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();
  }
예제 #2
0
  public List<Group> buildGroupsDirected() {
    List<Group> groups = new LinkedList<>();

    // First determine 'start' relations, i.e. relations without incoming
    // edges in the relation graph
    TLongSet starts = new TLongHashSet();
    Collection<Long> ids = graph.getNodes();
    for (long id : ids) {
      if (graph.getEdgesIn(id).isEmpty()) {
        starts.add(id);
      }
    }
    // Build sub-graphs reachable from 'start' relations
    logger.debug("Number of start relations: " + starts.size());
    for (long start : starts.toArray()) {
      groups.add(build(start));
    }

    // In case of circles within the relation graph that are not reachable
    // from any start relation, there may be some relations left, that have
    // not been put into groups yet.
    TLongSet remaining = new TLongHashSet();
    remaining.addAll(ids);
    for (Group group : groups) {
      remaining.removeAll(group.getRelationIds());
    }
    if (remaining.size() > 0) {
      logger.debug("remaining: " + remaining.size());
      while (!remaining.isEmpty()) {
        long id = any(remaining);

        TLongSet reachable = reachable(graph, id);
        remaining.removeAll(reachable);

        long lowest = IdUtil.lowestId(reachable);
        groups.add(new Group(lowest, reachable));
      }
    }

    return groups;
  }
 @Override
 public long[] getPriorStepExecutionIds() {
   return priorStepExecutionIds.toArray();
 }