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