Eclipse SUMO - Simulation of Urban MObility
NILoader.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-2022 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
22 // Perfoms network import
23 /****************************************************************************/
24 #include <config.h>
25 
26 #include <string>
30 #include <utils/options/Option.h>
33 #include <utils/common/ToString.h>
36 #include <netbuild/NBTypeCont.h>
37 #include <netbuild/NBNodeCont.h>
38 #include <netbuild/NBEdgeCont.h>
40 #include <netbuild/NBNetBuilder.h>
57 #include <netimport/typemap.h>
58 #include "NILoader.h"
59 #include "NITypeLoader.h"
60 
61 // ===========================================================================
62 // method definitions
63 // ===========================================================================
65  : myNetBuilder(nb) {}
66 
68 
69 void
71  bool ok = true;
72  // load types first
73  NIXMLTypesHandler* handler =
75  if (!oc.isSet("type-files")) {
76  std::vector<std::string> files;
77  if (oc.isSet("osm-files")) {
78  files.push_back(osmTypemap);
79  }
80  if (oc.isSet("opendrive-files")) {
81  files.push_back(opendriveTypemap);
82  }
83  ok &= NITypeLoader::load(handler, files, "types", true);
84  } else {
85  ok &= NITypeLoader::load(handler, oc.getStringVector("type-files"), "types");
86  }
87  // try to load height data so it is ready for use by other importers
89  // try to load using different methods
99  if (oc.getBool("tls.discard-loaded") || oc.getBool("tls.discard-simple")) {
101  oc.getBool("tls.guess-signals"));
102  int removed = myNetBuilder.getTLLogicCont().getNumExtracted();
103  if (removed > 0) {
104  WRITE_MESSAGE(" Removed " + toString(removed) + " traffic lights before loading plain-XML");
105  }
106  }
107  if (oc.getBool("railway.signals.discard")) {
109  }
110  ok &= loadXML(oc);
111  // check the loaded structures
112  if (myNetBuilder.getNodeCont().size() == 0) {
113  throw ProcessError("No nodes loaded.");
114  }
115  if (myNetBuilder.getEdgeCont().size() == 0) {
116  throw ProcessError("No edges loaded.");
117  }
119  throw ProcessError();
120  }
121  if (!ok && !oc.getBool("ignore-errors")) {
122  throw ProcessError();
123  }
124  // report loaded structures
125  WRITE_MESSAGE(" Import done:");
126  if (myNetBuilder.getDistrictCont().size() > 0) {
127  WRITE_MESSAGE(" " + toString(myNetBuilder.getDistrictCont().size()) + " districts loaded.");
128  }
129  WRITE_MESSAGE(" " + toString(myNetBuilder.getNodeCont().size()) + " nodes loaded.");
130  if (myNetBuilder.getTypeCont().size() > 0) {
131  WRITE_MESSAGE(" " + toString(myNetBuilder.getTypeCont().size()) + " types loaded.");
132  }
133  WRITE_MESSAGE(" " + toString(myNetBuilder.getEdgeCont().size()) + " edges loaded.");
136  "The split of edges was performed " + toString(myNetBuilder.getEdgeCont().getNoEdgeSplits()) + " times.");
137  }
138 
139  //TODO: uncomment the following lines + adapt tests! [Gregor March '17]
140 // if (myNetBuilder.getPTStopCont().size() > 0) {
141 // WRITE_MESSAGE(" " + toString(myNetBuilder.getPTStopCont().size()) + " pt stops loaded.");
142 // }
143  if (GeoConvHelper::getProcessing().usingGeoProjection()) {
144  WRITE_MESSAGE("Proj projection parameters used: '" + GeoConvHelper::getProcessing().getProjString() + "'.");
145  }
146 }
147 
148 /* -------------------------------------------------------------------------
149  * file loading methods
150  * ----------------------------------------------------------------------- */
151 bool
153  // load nodes
156  oc.getStringVector("node-files"), "nodes");
157  // load the edges
158  if (ok) {
164  oc),
165  oc.getStringVector("edge-files"), "edges");
166  }
167  if (!deprecatedVehicleClassesSeen.empty()) {
168  WRITE_WARNING("Deprecated vehicle class(es) '" + toString(deprecatedVehicleClassesSeen) + "' in input edge files.");
169  }
170  // load the connections
171  if (ok) {
175  oc.getStringVector("connection-files"), "connections");
176  }
177  // load traffic lights (needs to come last, references loaded edges and connections)
178  if (ok) {
181  oc.getStringVector("tllogic-files"), "traffic lights");
182  }
183 
184  // load public transport stops (used for restricting edge removal and as input when repairing railroad topology)
185  if (ok && oc.exists("ptstop-files")) {
190  oc.getStringVector("ptstop-files"), "public transport stops");
191  }
192 
193  // load public transport lines (used as input when repairing railroad topology)
194  if (ok && oc.exists("ptline-files")) {
199  oc.getStringVector("ptline-files"), "public transport lines");
200  }
201 
202  // load shapes for output formats that embed shape data
203  if (ok && oc.exists("polygon-files")) {
207  oc.getStringVector("polygon-files"), "polygon data");
208  }
209  return ok;
210 }
211 
212 
213 /****************************************************************************/
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:282
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:280
std::set< std::string > deprecatedVehicleClassesSeen
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
static GeoConvHelper & getProcessing()
the coordinate transformation to use for input conversion and processing
Definition: GeoConvHelper.h:84
int size() const
Returns the number of districts inside the container.
int size() const
Returns the number of edges.
Definition: NBEdgeCont.h:303
int getNoEdgeSplits() const
Returns the number of edge splits.
Definition: NBEdgeCont.h:318
bool checkConsistency(const NBNodeCont &nc)
ensure that all edges have valid nodes
static void loadIfSet(OptionsCont &oc)
loads height map data if any loading options are set
Instance responsible for building networks.
Definition: NBNetBuilder.h:107
ShapeContainer & getShapeCont()
Definition: NBNetBuilder.h:188
NBDistrictCont & getDistrictCont()
Returns a reference the districts container.
Definition: NBNetBuilder.h:168
NBTypeCont & getTypeCont()
Returns a reference to the type container.
Definition: NBNetBuilder.h:158
NBPTLineCont & getPTLineCont()
Returns a reference to the pt line container.
Definition: NBNetBuilder.h:179
NBEdgeCont & getEdgeCont()
Definition: NBNetBuilder.h:148
NBPTStopCont & getPTStopCont()
Returns a reference to the pt stop container.
Definition: NBNetBuilder.h:174
NBNodeCont & getNodeCont()
Returns a reference to the node container.
Definition: NBNetBuilder.h:153
NBTrafficLightLogicCont & getTLLogicCont()
Returns a reference to the traffic light logics container.
Definition: NBNetBuilder.h:163
int size() const
Returns the number of nodes stored in this container.
Definition: NBNodeCont.h:288
void discardRailSignals()
void discardTrafficLights(NBTrafficLightLogicCont &tlc, bool geometryLike, bool guessSignals)
int getNumExtracted() const
return the number of extracted traffic light definitions
int size() const
Returns the number of known edgeTypes.
Definition: NBTypeCont.cpp:243
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given ArcView Shape files.
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given dlr-navteq (aka Elmar-fomat) folder.
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given ITSUMO network files.
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given MATSIM network files.
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given SUMO file.
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given OSM file.
static void loadNetwork(OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given SUMO file.
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads network definition from the assigned option and stores it in the given network builder.
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads network definition from the assigned option and stores it in the given network builder.
NILoader(NBNetBuilder &nb)
Constructor.
Definition: NILoader.cpp:64
NBNetBuilder & myNetBuilder
The network builder to fill with loaded data.
Definition: NILoader.h:74
void load(OptionsCont &oc)
Definition: NILoader.cpp:70
~NILoader()
Destructor.
Definition: NILoader.cpp:67
bool loadXML(OptionsCont &oc)
Definition: NILoader.cpp:152
static bool load(SUMOSAXHandler *handler, const std::vector< std::string > &files, const std::string &type, const bool stringParse=false)
Importer for edge connections stored in XML.
Importer for network edges stored in XML.
Importer for network nodes stored in XML.
Importer for network edges stored in XML.
Importer for edge connections stored in XML.
Importer for edge type information stored in XML.
A storage for options typed value containers)
Definition: OptionsCont.h:89
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
bool exists(const std::string &name) const
Returns the information whether the named option is known.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)