1 package osm;
2
3 import java.io.IOException;
4 import java.net.URISyntaxException;
5 import java.util.ArrayList;
6 import java.util.List;
7
8 import org.opentrafficsim.importexport.osm.Network;
9 import org.opentrafficsim.importexport.osm.Tag;
10 import org.opentrafficsim.importexport.osm.input.ReadOSMFile;
11
12 /**
13 * Import an OpenStreetMap file.
14 * <p>
15 * Copyright (c) 2013-2014 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
16 * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
17 * <p>.
18 * @version 31 dec. 2014 <br>
19 * @author <a>Moritz Bergmann</a>
20 */
21 public class ReadOSM
22 {
23 /** */
24 private static String loc = "duesseldorf_germany.osm.bz2";
25 //private static String loc = "Mettmann.osm";
26 //private static String loc = "TUD.osm";// "amsterdam_netherlands.osm.bz2";// "munich.osm.bz2";
27
28 /** */
29 private static List<Tag> wt;
30
31 /** */
32 private static List<String> ft;
33
34 /**
35 *
36 */
37 private static void makeWanted()
38 {
39 Tag t1 = new Tag("highway", "primary");
40 wt.add(t1);
41 Tag t2 = new Tag("highway", "secondary");
42 wt.add(t2);
43 Tag t3 = new Tag("highway", "tertiary");
44 wt.add(t3);
45 Tag t4 = new Tag("highway", "cycleway");
46 wt.add(t4);
47 Tag t5 = new Tag("highway", "trunk");
48 wt.add(t5);
49 Tag t6 = new Tag("highway", "path");
50 wt.add(t6);
51 Tag t8 = new Tag("cyclway", "lane");
52 wt.add(t8);
53 Tag t9 = new Tag("highway", "residental");
54 wt.add(t9);
55 Tag t10 = new Tag("highway", "service");
56 wt.add(t10);
57 Tag t11 = new Tag("highway", "motorway");
58 wt.add(t11);
59 Tag t12 = new Tag("highway", "bus_stop");
60 wt.add(t12);
61 }
62
63 /**
64 *
65 */
66 private static void makeFilter()
67 {
68 ft.add("highway");
69 ft.add("cycleway");
70 ft.add("lanes");
71 ft.add("name");
72 ft.add("maxspeed");
73 ft.add("junction");
74 ft.add("oneway");
75 ft.add("sidewalk");
76 ft.add("busway");
77 ft.add("junction");
78 ft.add("service");
79 ft.add("ele"); //Altitude/elevation
80 ft.add("location"); //underground, overground, underwater etc.
81 ft.add("layer"); // -5 to 5. 0 not explicitly used.
82 ft.add("bridge");
83 ft.add("tunnel");
84 }
85
86 /**
87 * @param args
88 */
89 public static void main(final String[] args)
90 {
91 ft = new ArrayList<String>();
92 wt = new ArrayList<Tag>();
93 makeWanted();
94 makeFilter();
95 try
96 {
97 System.out.println("Parsing " + loc);
98 String prefix = "file:///D:/";
99 ReadOSMFile osmf = new ReadOSMFile(prefix + loc, wt, ft);
100 while (!osmf.checkisReaderThreadDead())
101 {
102 System.out.println("Processing");
103 }
104 Network net = osmf.getNetwork();
105 System.out.println("Got Network. Start Conversion");
106 System.out.println("Making links");
107 net.makeLinks();
108 System.out.println("Made " + net.getLinks().size() + " links");
109 System.out.println("Removing redundancies");
110 net.removeRedundancy();
111 System.out.println(net.getLinks().size() + " links after redudancy removal");
112 System.out.println("Not yet converting to OTS internal format - terminating");
113 /*int countn = 0;
114 for (Long n: net.getNodes().keySet())
115 {
116 countn++;
117 System.out.println(n);
118 }
119 int countw = 0;
120 for (Long w: net.getWays().keySet())
121 {
122 countw++;
123 String s = "";
124 for (Tag t: net.getWay(w).getTags())
125 {
126 s = s + t.getKey() + ": " +t.getValue() + " || ";
127 }
128 if(!s.isEmpty())
129 {
130 System.out.println(s);
131 }
132 }
133 try
134 {
135 net.makeLinks();
136 int countl = 0;
137 for (Link l: net.getLinks())
138 {
139 countl++;
140 String s = "";
141 for (Tag t: l.getTags())
142 {
143 s = s + t.getKey() + ": " +t.getValue() + " || ";
144 }
145 if(!s.isEmpty())
146 {
147 System.out.println(s);
148 }
149 }
150 System.out.println("Number of ways: " + countw + " || Number of nodes " + countn + " || Number of links: " + countl);
151 }
152 catch(IOException e)
153 {
154 System.out.println(e);
155 }
156 */}
157 catch (URISyntaxException exception)
158 {
159 exception.printStackTrace();
160 }
161 catch (IOException exception)
162 {
163 exception.printStackTrace();
164 }
165 }
166
167 }