View Javadoc
1   import java.io.FileNotFoundException;
2   import java.net.MalformedURLException;
3   import java.net.URISyntaxException;
4   import java.util.ArrayList;
5   import java.util.Map;
6   
7   import org.opentrafficsim.road.network.factory.osm.OSMNetwork;
8   import org.opentrafficsim.road.network.factory.osm.OSMNode;
9   import org.opentrafficsim.road.network.factory.osm.OSMTag;
10  import org.opentrafficsim.road.network.factory.osm.OSMWay;
11  import org.opentrafficsim.road.network.factory.osm.events.ProgressEvent;
12  import org.opentrafficsim.road.network.factory.osm.events.ProgressListener;
13  import org.opentrafficsim.road.network.factory.osm.input.ReadOSMFile;
14  
15  /**
16   * Dump an OSM file.
17   * <p>
18   * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
19   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
20   * <p>
21   * @version $Revision$, $LastChangedDate$, by $Author$, initial version Sep 12, 2018 <br>
22   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
23   */
24  public class DumpOSM implements ProgressListener
25  {
26  
27      /**
28       * Program execution entry point.
29       * @param args String[]; command line arguments (not used)
30       * @throws FileNotFoundException ...
31       * @throws MalformedURLException ...
32       * @throws URISyntaxException ...
33       */
34      public static void main(final String[] args) throws FileNotFoundException, MalformedURLException, URISyntaxException
35      {
36          String fileName = "file:///D:/TUD.osm";
37          ArrayList<OSMTag> wantedTags = new ArrayList<>();
38          // wantedTags.add(new OSMTag("highway", "primary"));
39          // wantedTags.add(new OSMTag("highway", "secondary"));
40          // wantedTags.add(new OSMTag("highway", "tertiary"));
41          // wantedTags.add(new OSMTag("highway", "cycleway"));
42          // wantedTags.add(new OSMTag("highway", "trunk"));
43          // wantedTags.add(new OSMTag("highway", "path"));
44          // wantedTags.add(new OSMTag("cycleway", "lane"));
45          // wantedTags.add(new OSMTag("highway", "residential"));
46          // wantedTags.add(new OSMTag("highway", "service"));
47          // wantedTags.add(new OSMTag("highway", "motorway"));
48          // wantedTags.add(new OSMTag("highway", "bus_stop"));
49          // wantedTags.add(new OSMTag("highway", "motorway_link"));
50          // wantedTags.add(new OSMTag("highway", "unclassified"));
51          // wantedTags.add(new OSMTag("highway", "footway"));
52          // wantedTags.add(new OSMTag("cycleway", "track"));
53          // wantedTags.add(new OSMTag("highway", "road"));
54          // wantedTags.add(new OSMTag("highway", "pedestrian"));
55          // wantedTags.add(new OSMTag("highway", "track"));
56          // wantedTags.add(new OSMTag("highway", "living_street"));
57          // wantedTags.add(new OSMTag("highway", "tertiary_link"));
58          // wantedTags.add(new OSMTag("highway", "secondary_link"));
59          // wantedTags.add(new OSMTag("highway", "primary_link"));
60          // wantedTags.add(new OSMTag("highway", "trunk_link"));
61          ArrayList<String> filteredKeys = new ArrayList<>();
62          ProgressListener listener = new DumpOSM();
63          ReadOSMFile osmf = new ReadOSMFile(fileName, wantedTags, filteredKeys, listener);
64          OSMNetwork net = osmf.getNetwork();
65          Map<Long, OSMNode> nodeMap = net.getNodes();
66          for (Long key : nodeMap.keySet())
67          {
68              OSMNode node = nodeMap.get(key);
69              System.out.println(node);
70          }
71          Map<Long, OSMWay> wayMap = net.getWays();
72          for (Long key : wayMap.keySet())
73          {
74              OSMWay way = wayMap.get(key);
75              System.out.println(way);
76          }
77      }
78  
79      /** {@inheritDoc} */
80      @Override
81      public void progress(ProgressEvent progressEvent)
82      {
83          System.out.println(progressEvent.getProgress());
84      }
85  }