SUMO - Simulation of Urban MObility
NIFrame.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // Sets and checks options for netimport
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <string>
34 #include <iostream>
35 #include <fstream>
36 #include <utils/options/Option.h>
40 #include <utils/common/ToString.h>
44 #include <netbuild/NBNetBuilder.h>
45 #include <netwrite/NWFrame.h>
47 #include "NIImporter_DlrNavteq.h"
48 #include "NIFrame.h"
49 
50 #ifdef CHECK_MEMORY_LEAKS
51 #include <foreign/nvwa/debug_new.h>
52 #endif // CHECK_MEMORY_LEAKS
53 
54 
55 // ===========================================================================
56 // method definitions
57 // ===========================================================================
58 void
61  // register input formats
62  oc.doRegister("sumo-net-file", 's', new Option_FileName());
63  oc.addSynonyme("sumo-net-file", "sumo-net", true);
64  oc.addDescription("sumo-net-file", "Input", "Read SUMO-net from FILE");
65  oc.addXMLDefault("sumo-net-file", "net");
66 
67  oc.doRegister("node-files", 'n', new Option_FileName());
68  oc.addSynonyme("node-files", "xml-node-files", true);
69  oc.addSynonyme("node-files", "xml-nodes", true);
70  oc.addSynonyme("node-files", "nodes");
71  oc.addDescription("node-files", "Input", "Read XML-node defs from FILE");
72 
73  oc.doRegister("edge-files", 'e', new Option_FileName());
74  oc.addSynonyme("edge-files", "xml-edge-files", true);
75  oc.addSynonyme("edge-files", "xml-edges", true);
76  oc.addSynonyme("edge-files", "edges");
77  oc.addDescription("edge-files", "Input", "Read XML-edge defs from FILE");
78 
79  oc.doRegister("connection-files", 'x', new Option_FileName());
80  oc.addSynonyme("connection-files", "xml-connection-files", true);
81  oc.addSynonyme("connection-files", "xml-connections", true);
82  oc.addSynonyme("connection-files", "connections");
83  oc.addDescription("connection-files", "Input", "Read XML-connection defs from FILE");
84 
85  oc.doRegister("tllogic-files", 'i', new Option_FileName());
86  oc.addDescription("tllogic-files", "Input", "Read XML-traffic light defs from FILE");
87 
88  oc.doRegister("type-files", 't', new Option_FileName());
89  oc.addSynonyme("type-files", "xml-type-files", true);
90  oc.addSynonyme("type-files", "xml-types", true);
91  oc.addSynonyme("type-files", "types");
92  oc.addDescription("type-files", "Input", "Read XML-type defs from FILE");
93 
94  oc.doRegister("shapefile-prefix", new Option_FileName());
95  oc.addSynonyme("shapefile-prefix", "shapefile");
96  oc.addSynonyme("shapefile-prefix", "arcview", true);
97  oc.addSynonyme("shapefile-prefix", "tiger", true);
98  oc.addDescription("shapefile-prefix", "Input", "Read shapefiles (ArcView, Tiger, ...) from files starting with 'FILE'");
99 
100  oc.doRegister("dlr-navteq-prefix", new Option_FileName());
101  oc.addSynonyme("dlr-navteq-prefix", "dlr-navteq");
102  oc.addSynonyme("dlr-navteq-prefix", "elmar2", true);
103  oc.addDescription("dlr-navteq-prefix", "Input", "Read converted Navteq GDF data (unsplitted Elmar-network) from path 'FILE'");
104 
105  oc.doRegister("osm-files", new Option_FileName());
106  oc.addSynonyme("osm-files", "osm");
107  oc.addDescription("osm-files", "Input", "Read OSM-network from path 'FILE(s)'");
108 
109  oc.doRegister("opendrive-files", new Option_FileName());
110  oc.addSynonyme("opendrive-files", "opendrive");
111  oc.addDescription("opendrive-files", "Input", "Read OpenDRIVE-network from FILE");
112 
113  oc.doRegister("visum-file", new Option_FileName());
114  oc.addSynonyme("visum-file", "visum");
115  oc.addDescription("visum-file", "Input", "Read VISUM-net from FILE");
116 
117  oc.doRegister("vissim-file", new Option_FileName());
118  oc.addSynonyme("vissim-file", "vissim");
119  oc.addDescription("vissim-file", "Input", "Read VISSIM-net from FILE");
120 
121  oc.doRegister("robocup-dir", new Option_FileName());
122  oc.addSynonyme("robocup-dir", "robocup-net", true);
123  oc.addSynonyme("robocup-dir", "robocup");
124  oc.addDescription("robocup-dir", "Input", "Read RoboCup-net from DIR");
125 
126  oc.doRegister("matsim-files", new Option_FileName());
127  oc.addSynonyme("matsim-files", "matsim");
128  oc.addDescription("matsim-files", "Input", "Read MATsim-net from FILE");
129 
130  oc.doRegister("itsumo-files", new Option_FileName());
131  oc.addSynonyme("itsumo-files", "itsumo");
132  oc.addDescription("itsumo-files", "Input", "Read ITSUMO-net from FILE");
133 
134  oc.doRegister("heightmap.shapefiles", new Option_FileName());
135  oc.addDescription("heightmap.shapefiles", "Input", "Read heightmap from ArcGIS shapefile");
136 
137  oc.doRegister("heightmap.geotiff", new Option_FileName());
138  oc.addDescription("heightmap.geotiff", "Input", "Read heightmap from GeoTIFF");
139 
140  // register basic processing options
141  oc.doRegister("ignore-errors", new Option_Bool(false));
142  oc.addSynonyme("ignore-errors", "dismiss-loading-errors", true);
143  oc.addDescription("ignore-errors", "Processing", "Continue on broken input");
144 
145  oc.doRegister("ignore-errors.connections", new Option_Bool(false));
146  oc.addDescription("ignore-errors.connections", "Processing", "Continue on invalid connections");
147 
148  oc.doRegister("show-errors.connections-first-try", new Option_Bool(false));
149  oc.addDescription("show-errors.connections-first-try", "Processing", "Show errors in connections at parsing");
150 
151  oc.doRegister("ignore-errors.edge-type", new Option_Bool(false));
152  oc.addDescription("ignore-errors.edge-type", "Processing", "Continue on unknown edge types");
153 
154  oc.doRegister("lanes-from-capacity.norm", new Option_Float((SUMOReal) 1800));
155  oc.addSynonyme("lanes-from-capacity.norm", "capacity-norm");
156  oc.addDescription("lanes-from-capacity.norm", "Processing", "The factor for flow to no. lanes conversion");
157 
158  oc.doRegister("speed-in-kmh", new Option_Bool(false));
159  oc.addDescription("speed-in-kmh", "Processing", "vmax is parsed as given in km/h (some)");
160 
161 
162 
163  // register xml options
164  oc.doRegister("plain.extend-edge-shape", new Option_Bool(false));
165  oc.addSynonyme("plain.extend-edge-shape", "xml.keep-shape", true);
166  oc.addDescription("plain.extend-edge-shape", "Processing", "If edge shapes do not end at the node positions, extend them");
167 
168 
169  // register matsim options
170  oc.doRegister("matsim.keep-length", new Option_Bool(false));
171  oc.addDescription("matsim.keep-length", "Processing", "The edge lengths given in the MATSIM-file will be kept");
172 
173  oc.doRegister("matsim.lanes-from-capacity", new Option_Bool(false));
174  oc.addDescription("matsim.lanes-from-capacity", "Processing", "The lane number will be computed from the capacity");
175 
176 
177  // register shapefile options
178  oc.doRegister("shapefile.street-id", new Option_String());
179  oc.addSynonyme("shapefile.street-id", "arcview.street-id", true);
180  oc.addDescription("shapefile.street-id", "Processing", "Read edge ids from column STR");
181 
182  oc.doRegister("shapefile.from-id", new Option_String());
183  oc.addSynonyme("shapefile.from-id", "arcview.from-id", true);
184  oc.addDescription("shapefile.from-id", "Processing", "Read from-node ids from column STR");
185 
186  oc.doRegister("shapefile.to-id", new Option_String());
187  oc.addSynonyme("shapefile.to-id", "arcview.to-id", true);
188  oc.addDescription("shapefile.to-id", "Processing", "Read to-node ids from column STR");
189 
190  oc.doRegister("shapefile.type-id", new Option_String());
191  oc.addSynonyme("shapefile.type-id", "arcview.type-id", true);
192  oc.addDescription("shapefile.type-id", "Processing", "Read type ids from column STR");
193 
194  oc.doRegister("shapefile.use-defaults-on-failure", new Option_Bool(false));
195  oc.addSynonyme("shapefile.use-defaults-on-failure", "arcview.use-defaults-on-failure", true);
196  oc.addDescription("shapefile.use-defaults-on-failure", "Processing", "Uses edge type defaults on problems");
197 
198  oc.doRegister("shapefile.all-bidirectional", new Option_Bool(false));
199  oc.addSynonyme("shapefile.all-bidirectional", "shapefile.all-bidi");
200  oc.addSynonyme("shapefile.all-bidirectional", "arcview.all-bidi", true);
201  oc.addDescription("shapefile.all-bidirectional", "Processing", "Insert edges in both directions");
202 
203  oc.doRegister("shapefile.guess-projection", new Option_Bool(false));
204  oc.addSynonyme("shapefile.guess-projection", "arcview.guess-projection", true);
205  oc.addDescription("shapefile.guess-projection", "Processing", "Guess the proper projection");
206 
207 
208  // register vissim options
209  oc.doRegister("vissim.join-distance", new Option_Float(5.0f));
210  oc.addSynonyme("vissim.join-distance", "vissim.offset", true);
211  oc.addDescription("vissim.join-distance", "Processing", "Structure join offset");
212 
213  oc.doRegister("vissim.default-speed", new Option_Float(50.0f));
214  oc.addDescription("vissim.default-speed", "Processing", "Use FLOAT as default speed");
215 
216  oc.doRegister("vissim.speed-norm", new Option_Float(1.0f));
217  oc.addDescription("vissim.speed-norm", "Processing", "Factor for edge velocity");
218 
219  oc.doRegister("vissim.report-unset-speeds", new Option_Bool(false));
220  oc.addDescription("vissim.report-unset-speeds", "Processing", "Writes lanes without an explicit speed set");
221 
222 
223  // register visum options
224  oc.doRegister("visum.use-type-priority", new Option_Bool(false));
225  oc.addDescription("visum.use-type-priority", "Processing", "Uses priorities from types");
226 
227  oc.doRegister("visum.use-type-laneno", new Option_Bool(false));
228  oc.addDescription("visum.use-type-laneno", "Processing", "Uses lane numbers from types");
229 
230  oc.doRegister("visum.use-type-speed", new Option_Bool(false));
231  oc.addDescription("visum.use-type-speed", "Processing", "Uses speeds from types");
232 
233  oc.doRegister("visum.connector-speeds", new Option_Float(100.));
234  oc.addDescription("visum.connector-speeds", "Processing", "Sets connector speed");
235 
236  oc.doRegister("visum.connectors-lane-number", new Option_Integer(3));
237  oc.addSynonyme("visum.connectors-lane-number", "visum.connector-laneno", true);
238  oc.addDescription("visum.connectors-lane-number", "Processing", "Sets connector lane number");
239 
240  oc.doRegister("visum.no-connectors", new Option_Bool(false));
241  oc.addDescription("visum.no-connectors", "Processing", "Excludes connectors");
242 
243  oc.doRegister("visum.recompute-lane-number", new Option_Bool(false));
244  oc.addSynonyme("visum.recompute-lane-number", "visum.recompute-laneno", true);
245  oc.addDescription("visum.recompute-lane-number", "Processing", "Computes the number of lanes from the edges' capacities");
246 
247  oc.doRegister("visum.verbose-warnings", new Option_Bool(false));
248  oc.addDescription("visum.verbose-warnings", "Processing", "Prints all warnings, some of which are due to VISUM misbehaviour");
249 
250 
251  // register osm options
252  oc.doRegister("osm.skip-duplicates-check", new Option_Bool(false));
253  oc.addDescription("osm.skip-duplicates-check", "Processing", "Skips the check for duplicate nodes and edges");
254 
255  oc.doRegister("osm.elevation", new Option_Bool(false));
256  oc.addDescription("osm.elevation", "Processing", "Imports elevation data");
257 
258  oc.doRegister("osm.layer-elevation", new Option_Float(0));
259  oc.addDescription("osm.layer-elevation", "Processing", "Reconstruct (relative) elevation based on layer data. Each layer is raised by FLOAT m");
260 
261  // register opendrive options
262  oc.doRegister("opendrive.import-all-lanes", new Option_Bool(false));
263  oc.addDescription("opendrive.import-all-lanes", "Processing", "Imports all lane types");
264  oc.doRegister("opendrive.ignore-widths", new Option_Bool(false));
265  oc.addDescription("opendrive.ignore-widths", "Processing", "Whether lane widths shall be ignored.");
266 
267  // register some additional options
268  oc.doRegister("tls.discard-loaded", new Option_Bool(false));
269  oc.addDescription("tls.discard-loaded", "TLS Building", "Does not instatiate traffic lights loaded from other formats than XML");
270 
271  oc.doRegister("tls.discard-simple", new Option_Bool(false));
272  oc.addDescription("tls.discard-simple", "TLS Building", "Does not instatiate traffic lights at geometry-like nodes loaded from other formats than XML");
273 }
274 
275 
276 bool
279  bool ok = oc.checkDependingSuboptions("shapefile", "shapefile.");
280  ok &= oc.checkDependingSuboptions("visum-file", "visum.");
281  ok &= oc.checkDependingSuboptions("vissim-file", "vissim.");
282 #ifdef HAVE_PROJ
283  int numProjections = oc.getBool("simple-projection") + oc.getBool("proj.utm") + oc.getBool("proj.dhdn") + (oc.getString("proj").length() > 1);
284  if ((oc.isSet("osm-files") || oc.isSet("dlr-navteq-prefix") || oc.isSet("shapefile-prefix")) && numProjections == 0) {
285  if (oc.isDefault("proj")) {
286  oc.set("proj.utm", "true");
287  }
288  }
289  if (oc.isSet("dlr-navteq-prefix") && oc.isDefault("proj.scale")) {
290  oc.set("proj.scale", toString(NIImporter_DlrNavteq::GEO_SCALE));
291  }
292 #else
293  if ((oc.isSet("osm-files") || oc.isSet("dlr-navteq-prefix") || oc.isSet("shapefile-prefix")) && !oc.getBool("simple-projection")) {
294  WRITE_ERROR("Cannot import network data without PROJ-Library. Please install packages proj before building sumo");
295  ok = false;
296  }
297 #endif
298  if (oc.isSet("sumo-net-file")) {
299  if (oc.isWriteable("no-turnarounds")) {
300  // changed default since turnarounds are loaded from the net file.
301  oc.set("no-turnarounds", "true");
302  }
303  if (oc.isWriteable("offset.disable-normalization")) {
304  // changed default since we wish to preserve the network as far as possible
305  oc.set("offset.disable-normalization", "true");
306  }
307  }
308  if (!oc.isSet("type-files")) {
309  const char* sumoPath = std::getenv("SUMO_HOME");
310  if (sumoPath == 0) {
311  WRITE_WARNING("Environment variable SUMO_HOME is not set, using built in type maps.");
312  } else {
313  const std::string path = sumoPath + std::string("/data/typemap/");
314  if (oc.isSet("osm-files")) {
315  oc.setDefault("type-files", path + "osmNetconvert.typ.xml");
316  }
317  if (oc.isSet("opendrive-files")) {
318  oc.setDefault("type-files", path + "opendriveNetconvert.typ.xml");
319  }
320  }
321  }
322  return ok;
323 }
324 
325 
326 
327 /****************************************************************************/
328 
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:86
bool checkDependingSuboptions(const std::string &name, const std::string &prefix) const
Checks whether an option is set, which has options with a prefix depending on it. ...
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static void fillOptions()
Inserts options used by the network importer and network building modules.
Definition: NIFrame.cpp:59
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:69
void addSynonyme(const std::string &name1, const std::string &name2, bool isDeprecated=false)
Adds a synonyme for an options name (any order)
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool setDefault(const std::string &name, const std::string &value)
Sets the given value for the named option as new default value.
bool isWriteable(const std::string &name)
Returns the information whether the named option may be set.
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NIFrame.cpp:277
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
bool set(const std::string &name, const std::string &value)
Sets the given value for the named option.
An integer-option.
Definition: Option.h:313
void addXMLDefault(const std::string &name, const std::string &xmlRoot="")
Adds an XML root element to handle by default. The special root "" denotes the default handler...
A storage for options typed value containers)
Definition: OptionsCont.h:99
static const int GEO_SCALE
scaling factor for geo coordinates (DLRNavteq format uses this to increase floating point precisions)...
#define SUMOReal
Definition: config.h:213
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.