SUMO - Simulation of Urban MObility
NIFrame.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
20 // Sets and checks options for netimport
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 
51 // ===========================================================================
52 // method definitions
53 // ===========================================================================
54 void
57  // register input formats
58  oc.doRegister("sumo-net-file", 's', new Option_FileName());
59  oc.addSynonyme("sumo-net-file", "sumo-net", true);
60  oc.addDescription("sumo-net-file", "Input", "Read SUMO-net from FILE");
61  oc.addXMLDefault("sumo-net-file", "net");
62 
63  oc.doRegister("node-files", 'n', new Option_FileName());
64  oc.addSynonyme("node-files", "xml-node-files", true);
65  oc.addSynonyme("node-files", "xml-nodes", true);
66  oc.addSynonyme("node-files", "nodes");
67  oc.addDescription("node-files", "Input", "Read XML-node defs from FILE");
68 
69  oc.doRegister("edge-files", 'e', new Option_FileName());
70  oc.addSynonyme("edge-files", "xml-edge-files", true);
71  oc.addSynonyme("edge-files", "xml-edges", true);
72  oc.addSynonyme("edge-files", "edges");
73  oc.addDescription("edge-files", "Input", "Read XML-edge defs from FILE");
74 
75  oc.doRegister("connection-files", 'x', new Option_FileName());
76  oc.addSynonyme("connection-files", "xml-connection-files", true);
77  oc.addSynonyme("connection-files", "xml-connections", true);
78  oc.addSynonyme("connection-files", "connections");
79  oc.addDescription("connection-files", "Input", "Read XML-connection defs from FILE");
80 
81  oc.doRegister("tllogic-files", 'i', new Option_FileName());
82  oc.addDescription("tllogic-files", "Input", "Read XML-traffic light defs from FILE");
83 
84  oc.doRegister("type-files", 't', new Option_FileName());
85  oc.addSynonyme("type-files", "xml-type-files", true);
86  oc.addSynonyme("type-files", "xml-types", true);
87  oc.addSynonyme("type-files", "types");
88  oc.addDescription("type-files", "Input", "Read XML-type defs from FILE");
89 
90  oc.doRegister("shapefile-prefix", new Option_FileName());
91  oc.addSynonyme("shapefile-prefix", "shapefile");
92  oc.addSynonyme("shapefile-prefix", "arcview", true);
93  oc.addSynonyme("shapefile-prefix", "tiger", true);
94  oc.addDescription("shapefile-prefix", "Input", "Read shapefiles (ArcView, Tiger, ...) from files starting with 'FILE'");
95 
96  oc.doRegister("dlr-navteq-prefix", new Option_FileName());
97  oc.addSynonyme("dlr-navteq-prefix", "dlr-navteq");
98  oc.addSynonyme("dlr-navteq-prefix", "elmar2", true);
99  oc.addDescription("dlr-navteq-prefix", "Input", "Read converted Navteq GDF data (unsplitted Elmar-network) from path 'FILE'");
100 
101  oc.doRegister("osm-files", new Option_FileName());
102  oc.addSynonyme("osm-files", "osm");
103  oc.addDescription("osm-files", "Input", "Read OSM-network from path 'FILE(s)'");
104 
105  oc.doRegister("opendrive-files", new Option_FileName());
106  oc.addSynonyme("opendrive-files", "opendrive");
107  oc.addDescription("opendrive-files", "Input", "Read OpenDRIVE-network from FILE");
108 
109  oc.doRegister("visum-file", new Option_FileName());
110  oc.addSynonyme("visum-file", "visum");
111  oc.addDescription("visum-file", "Input", "Read VISUM-net from FILE");
112 
113  oc.doRegister("vissim-file", new Option_FileName());
114  oc.addSynonyme("vissim-file", "vissim");
115  oc.addDescription("vissim-file", "Input", "Read VISSIM-net from FILE");
116 
117  oc.doRegister("robocup-dir", new Option_FileName());
118  oc.addSynonyme("robocup-dir", "robocup-net", true);
119  oc.addSynonyme("robocup-dir", "robocup");
120  oc.addDescription("robocup-dir", "Input", "Read RoboCup-net from DIR");
121 
122  oc.doRegister("matsim-files", new Option_FileName());
123  oc.addSynonyme("matsim-files", "matsim");
124  oc.addDescription("matsim-files", "Input", "Read MATsim-net from FILE");
125 
126  oc.doRegister("itsumo-files", new Option_FileName());
127  oc.addSynonyme("itsumo-files", "itsumo");
128  oc.addDescription("itsumo-files", "Input", "Read ITSUMO-net from FILE");
129 
130  oc.doRegister("heightmap.shapefiles", new Option_FileName());
131  oc.addDescription("heightmap.shapefiles", "Input", "Read heightmap from ArcGIS shapefile");
132 
133  oc.doRegister("heightmap.geotiff", new Option_FileName());
134  oc.addDescription("heightmap.geotiff", "Input", "Read heightmap from GeoTIFF");
135 
136  // register basic processing options
137  oc.doRegister("ignore-errors", new Option_Bool(false));
138  oc.addSynonyme("ignore-errors", "dismiss-loading-errors", true);
139  oc.addDescription("ignore-errors", "Processing", "Continue on broken input");
140 
141  oc.doRegister("ignore-errors.connections", new Option_Bool(false));
142  oc.addDescription("ignore-errors.connections", "Processing", "Continue on invalid connections");
143 
144  oc.doRegister("show-errors.connections-first-try", new Option_Bool(false));
145  oc.addDescription("show-errors.connections-first-try", "Processing", "Show errors in connections at parsing");
146 
147  oc.doRegister("ignore-errors.edge-type", new Option_Bool(false));
148  oc.addDescription("ignore-errors.edge-type", "Processing", "Continue on unknown edge types");
149 
150  oc.doRegister("lanes-from-capacity.norm", new Option_Float((double) 1800));
151  oc.addSynonyme("lanes-from-capacity.norm", "capacity-norm");
152  oc.addDescription("lanes-from-capacity.norm", "Processing", "The factor for flow to no. lanes conversion");
153 
154  oc.doRegister("speed-in-kmh", new Option_Bool(false));
155  oc.addDescription("speed-in-kmh", "Processing", "vmax is parsed as given in km/h (some)");
156 
157  oc.doRegister("construction-date", new Option_String());
158  oc.addDescription("construction-date", "Processing", "Use YYYY-MM-DD date to determine the readiness of features under construction");
159 
160 
161  // register xml options
162  oc.doRegister("plain.extend-edge-shape", new Option_Bool(false));
163  oc.addSynonyme("plain.extend-edge-shape", "xml.keep-shape", true);
164  oc.addDescription("plain.extend-edge-shape", "Processing", "If edge shapes do not end at the node positions, extend them");
165 
166 
167  // register matsim options
168  oc.doRegister("matsim.keep-length", new Option_Bool(false));
169  oc.addDescription("matsim.keep-length", "Processing", "The edge lengths given in the MATSIM-file will be kept");
170 
171  oc.doRegister("matsim.lanes-from-capacity", new Option_Bool(false));
172  oc.addDescription("matsim.lanes-from-capacity", "Processing", "The lane number will be computed from the capacity");
173 
174 
175  // register shapefile options
176  oc.doRegister("shapefile.street-id", new Option_String());
177  oc.addSynonyme("shapefile.street-id", "arcview.street-id", true);
178  oc.addDescription("shapefile.street-id", "Processing", "Read edge ids from column STR");
179 
180  oc.doRegister("shapefile.from-id", new Option_String());
181  oc.addSynonyme("shapefile.from-id", "arcview.from-id", true);
182  oc.addDescription("shapefile.from-id", "Processing", "Read from-node ids from column STR");
183 
184  oc.doRegister("shapefile.to-id", new Option_String());
185  oc.addSynonyme("shapefile.to-id", "arcview.to-id", true);
186  oc.addDescription("shapefile.to-id", "Processing", "Read to-node ids from column STR");
187 
188  oc.doRegister("shapefile.type-id", new Option_String());
189  oc.addSynonyme("shapefile.type-id", "arcview.type-id", true);
190  oc.addDescription("shapefile.type-id", "Processing", "Read type ids from column STR");
191 
192  oc.doRegister("shapefile.use-defaults-on-failure", new Option_Bool(false));
193  oc.addSynonyme("shapefile.use-defaults-on-failure", "arcview.use-defaults-on-failure", true);
194  oc.addDescription("shapefile.use-defaults-on-failure", "Processing", "Uses edge type defaults on problems");
195 
196  oc.doRegister("shapefile.all-bidirectional", new Option_Bool(false));
197  oc.addSynonyme("shapefile.all-bidirectional", "shapefile.all-bidi");
198  oc.addSynonyme("shapefile.all-bidirectional", "arcview.all-bidi", true);
199  oc.addDescription("shapefile.all-bidirectional", "Processing", "Insert edges in both directions");
200 
201  oc.doRegister("shapefile.guess-projection", new Option_Bool(false));
202  oc.addSynonyme("shapefile.guess-projection", "arcview.guess-projection", true);
203  oc.addDescription("shapefile.guess-projection", "Processing", "Guess the proper projection");
204 
205 
206  // register vissim options
207  oc.doRegister("vissim.join-distance", new Option_Float(5.0f));
208  oc.addSynonyme("vissim.join-distance", "vissim.offset", true);
209  oc.addDescription("vissim.join-distance", "Processing", "Structure join offset");
210 
211  oc.doRegister("vissim.default-speed", new Option_Float(50.0f));
212  oc.addDescription("vissim.default-speed", "Processing", "Use FLOAT as default speed");
213 
214  oc.doRegister("vissim.speed-norm", new Option_Float(1.0f));
215  oc.addDescription("vissim.speed-norm", "Processing", "Factor for edge velocity");
216 
217  oc.doRegister("vissim.report-unset-speeds", new Option_Bool(false));
218  oc.addDescription("vissim.report-unset-speeds", "Processing", "Writes lanes without an explicit speed set");
219 
220 
221  // register visum options
222  oc.doRegister("visum.use-type-priority", new Option_Bool(false));
223  oc.addDescription("visum.use-type-priority", "Processing", "Uses priorities from types");
224 
225  oc.doRegister("visum.use-type-laneno", new Option_Bool(false));
226  oc.addDescription("visum.use-type-laneno", "Processing", "Uses lane numbers from types");
227 
228  oc.doRegister("visum.use-type-speed", new Option_Bool(false));
229  oc.addDescription("visum.use-type-speed", "Processing", "Uses speeds from types");
230 
231  oc.doRegister("visum.connector-speeds", new Option_Float(100.));
232  oc.addDescription("visum.connector-speeds", "Processing", "Sets connector speed");
233 
234  oc.doRegister("visum.connectors-lane-number", new Option_Integer(3));
235  oc.addSynonyme("visum.connectors-lane-number", "visum.connector-laneno", true);
236  oc.addDescription("visum.connectors-lane-number", "Processing", "Sets connector lane number");
237 
238  oc.doRegister("visum.no-connectors", new Option_Bool(false));
239  oc.addDescription("visum.no-connectors", "Processing", "Excludes connectors");
240 
241  oc.doRegister("visum.recompute-lane-number", new Option_Bool(false));
242  oc.addSynonyme("visum.recompute-lane-number", "visum.recompute-laneno", true);
243  oc.addDescription("visum.recompute-lane-number", "Processing", "Computes the number of lanes from the edges' capacities");
244 
245  oc.doRegister("visum.verbose-warnings", new Option_Bool(false));
246  oc.addDescription("visum.verbose-warnings", "Processing", "Prints all warnings, some of which are due to VISUM misbehaviour");
247 
248 
249  // register osm options
250  oc.doRegister("osm.skip-duplicates-check", new Option_Bool(false));
251  oc.addDescription("osm.skip-duplicates-check", "Processing", "Skips the check for duplicate nodes and edges");
252 
253  oc.doRegister("osm.elevation", new Option_Bool(false));
254  oc.addDescription("osm.elevation", "Processing", "Imports elevation data");
255 
256  oc.doRegister("osm.layer-elevation", new Option_Float(0));
257  oc.addDescription("osm.layer-elevation", "Processing", "Reconstruct (relative) elevation based on layer data. Each layer is raised by FLOAT m");
258 
259  oc.doRegister("osm.layer-elevation.max-grade", new Option_Float(10));
260  oc.addDescription("osm.layer-elevation.max-grade", "Processing", "Maximum grade threshold in % at 50km/h when reconstrucing elevation based on layer data. The value is scaled according to road speed.");
261 
262  oc.doRegister("osm.oneway-spread-right", new Option_Bool(false));
263  oc.addDescription("osm.oneway-spread-right", "Processing", "Whether one-way roads should be spread to the side instead of centered");
264 
265  oc.doRegister("osm.stop-output.length", new Option_Float(25));
266  oc.addDescription("osm.stop-output.length", "Processing", "The default length of a public transport stop in FLOAT m");
267  oc.doRegister("osm.stop-output.length.bus", new Option_Float(15));
268  oc.addDescription("osm.stop-output.length.bus", "Processing", "The default length of a bus stop in FLOAT m");
269  oc.doRegister("osm.stop-output.length.tram", new Option_Float(25));
270  oc.addDescription("osm.stop-output.length.tram", "Processing", "The default length of a tram stop in FLOAT m");
271  oc.doRegister("osm.stop-output.length.train", new Option_Float(200));
272  oc.addDescription("osm.stop-output.length.train", "Processing", "The default length of a train stop in FLOAT m");
273 
274  oc.doRegister("osm.all-attributes", new Option_Bool(false));
275  oc.addDescription("osm.all-attributes", "Processing", "Whether additional attributes shall be imported");
276 
277  // register opendrive options
278  oc.doRegister("opendrive.import-all-lanes", new Option_Bool(false));
279  oc.addDescription("opendrive.import-all-lanes", "Processing", "Imports all lane types");
280  oc.doRegister("opendrive.ignore-widths", new Option_Bool(false));
281  oc.addDescription("opendrive.ignore-widths", "Processing", "Whether lane widths shall be ignored.");
282  oc.doRegister("opendrive.curve-resolution", new Option_Float(2.0));
283  oc.addDescription("opendrive.curve-resolution", "Processing", "The geometry resolution in m when importing curved geometries as line segments.");
284  oc.doRegister("opendrive.advance-stopline", new Option_Float(12.0));
285  oc.addDescription("opendrive.advance-stopline", "Processing", "Allow stop lines to be built beyond the start of the junction if the geometries allow so");
286  oc.doRegister("opendrive.min-width", new Option_Float(1.8));
287  oc.addDescription("opendrive.min-width", "Processing", "The minimum lane width for determining start or end of variable-width lanes");
288 
289  // register some additional options
290  oc.doRegister("tls.discard-loaded", new Option_Bool(false));
291  oc.addDescription("tls.discard-loaded", "TLS Building", "Does not instatiate traffic lights loaded from other formats than XML");
292 
293  oc.doRegister("tls.discard-simple", new Option_Bool(false));
294  oc.addDescription("tls.discard-simple", "TLS Building", "Does not instatiate traffic lights at geometry-like nodes loaded from other formats than XML");
295 }
296 
297 
298 bool
301  bool ok = oc.checkDependingSuboptions("shapefile", "shapefile.");
302  ok &= oc.checkDependingSuboptions("visum-file", "visum.");
303  ok &= oc.checkDependingSuboptions("vissim-file", "vissim.");
304 #ifdef HAVE_PROJ
305  int numProjections = oc.getBool("simple-projection") + oc.getBool("proj.utm") + oc.getBool("proj.dhdn") + (oc.getString("proj").length() > 1);
306  if ((oc.isSet("osm-files") || oc.isSet("dlr-navteq-prefix") || oc.isSet("shapefile-prefix")) && numProjections == 0) {
307  if (oc.isDefault("proj")) {
308  oc.set("proj.utm", "true");
309  }
310  }
311  if (oc.isSet("dlr-navteq-prefix") && oc.isDefault("proj.scale")) {
312  oc.set("proj.scale", NIImporter_DlrNavteq::GEO_SCALE);
313  }
314 #else
315  if ((oc.isSet("osm-files") || oc.isSet("dlr-navteq-prefix") || oc.isSet("shapefile-prefix")) && !oc.getBool("simple-projection")) {
316  WRITE_ERROR("Cannot import network data without PROJ-Library. Please install packages proj before building sumo");
317  ok = false;
318  }
319 #endif
320  if (oc.isSet("sumo-net-file")) {
321  if (oc.isWriteable("no-turnarounds")) {
322  // changed default since turnarounds are loaded from the net file.
323  oc.set("no-turnarounds", "true");
324  }
325  if (oc.isWriteable("offset.disable-normalization")) {
326  // changed default since we wish to preserve the network as far as possible
327  oc.set("offset.disable-normalization", "true");
328  }
329  }
330  if (!oc.isSet("type-files")) {
331  const char* sumoPath = std::getenv("SUMO_HOME");
332  if (sumoPath == 0) {
333  WRITE_WARNING("Environment variable SUMO_HOME is not set, using built in type maps.");
334  } else {
335  const std::string path = sumoPath + std::string("/data/typemap/");
336  if (oc.isSet("osm-files")) {
337  oc.setDefault("type-files", path + "osmNetconvert.typ.xml");
338  }
339  if (oc.isSet("opendrive-files")) {
340  oc.setDefault("type-files", path + "opendriveNetconvert.typ.xml");
341  }
342  }
343  }
344  if (oc.isSet("opendrive-files")) {
345  if (oc.isDefault("tls.left-green.time")) {
346  // legacy behavior. see #2114
347  oc.set("tls.left-green.time", "0");
348  }
349  if (oc.isDefault("rectangular-lane-cut")) {
350  // a better interpretation of imported geometries
351  oc.set("rectangular-lane-cut", "true");
352  }
353  }
354  return ok;
355 }
356 
357 
358 
359 /****************************************************************************/
360 
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:81
static void fillOptions()
Inserts options used by the network importer and network building modules.
Definition: NIFrame.cpp:55
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:199
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:64
void addSynonyme(const std::string &name1, const std::string &name2, bool isDeprecated=false)
Adds a synonyme for an options name (any order)
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
bool setDefault(const std::string &name, const std::string &value)
Sets the given value for the named option as new default value.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool isWriteable(const std::string &name)
Returns the information whether the named option may be set.
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NIFrame.cpp:299
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:205
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 set(const std::string &name, const std::string &value)
Sets the given value for the named option.
An integer-option.
Definition: Option.h:312
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:98
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
static const std::string GEO_SCALE
scaling factor for geo coordinates (DLRNavteq format uses this to increase floating point precisions)...