コード例 #1
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();
  }
コード例 #2
0
 public void build(OsmIterator iterator) throws IOException {
   graph = undirected ? new UndirectedGraph<Long>() : new Graph<Long>();
   for (EntityContainer container : iterator) {
     if (container.getType() != EntityType.Relation) {
       continue;
     }
     OsmRelation relation = (OsmRelation) container.getEntity();
     process(relation);
   }
 }
コード例 #3
0
  public static void main(String[] args)
      throws IOException, ParserConfigurationException, SAXException {
    String url =
        "http://www.overpass-api.de/api/xapi?map?bbox=" + "13.465661,52.504055,13.469817,52.506204";
    InputStream input = new URL(url).openStream();

    OsmIterator iterator = new OsmXmlIterator(input, true);

    OsmXmlOutputStream writer = new OsmXmlOutputStream(System.out, true);

    for (EntityContainer container : iterator) {
      if (container.getType() == EntityType.Node) {
        writer.write((OsmNode) container.getEntity());
      }
    }

    writer.complete();
  }