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-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 /****************************************************************************/
19 // Perfoms network import
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <string>
32 #include <utils/options/Option.h>
35 #include <utils/common/ToString.h>
40 #include <utils/xml/XMLSubSys.h>
41 #include <netbuild/NBTypeCont.h>
42 #include <netbuild/NBNodeCont.h>
43 #include <netbuild/NBEdgeCont.h>
45 #include <netbuild/NBNetBuilder.h>
62 #include <netimport/typemap.h>
63 #include "NILoader.h"
64 
65 // ===========================================================================
66 // method definitions
67 // ===========================================================================
69  : myNetBuilder(nb) {}
70 
72 
73 void
75  // load types first
76  NIXMLTypesHandler* handler =
78  if (!oc.isSet("type-files")) {
79  std::vector<std::string> files;
80  if (oc.isSet("osm-files")) {
81  files.push_back(osmTypemap);
82  }
83  if (oc.isSet("opendrive-files")) {
84  files.push_back(opendriveTypemap);
85  }
86  loadXMLType(handler, files, "types", true);
87  } else {
88  loadXMLType(handler, oc.getStringVector("type-files"), "types");
89  }
90  // try to load height data so it is ready for use by other importers
92  // try to load using different methods
103  if (oc.getBool("tls.discard-loaded") || oc.getBool("tls.discard-simple")) {
105  oc.getBool("tls.guess-signals"));
106  int removed = myNetBuilder.getTLLogicCont().getNumExtracted();
107  if (removed > 0) {
108  WRITE_MESSAGE(" Removed " + toString(removed) + " traffic lights before loading plain-XML");
109  }
110  }
111  if (oc.getBool("railway.signals.discard")) {
113  }
114  loadXML(oc);
115  // check the loaded structures
116  if (myNetBuilder.getNodeCont().size() == 0) {
117  throw ProcessError("No nodes loaded.");
118  }
119  if (myNetBuilder.getEdgeCont().size() == 0) {
120  throw ProcessError("No edges loaded.");
121  }
122  // report loaded structures
123  WRITE_MESSAGE(" Import done:");
124  if (myNetBuilder.getDistrictCont().size() > 0) {
125  WRITE_MESSAGE(" " + toString(myNetBuilder.getDistrictCont().size()) + " districts loaded.");
126  }
127  WRITE_MESSAGE(" " + toString(myNetBuilder.getNodeCont().size()) + " nodes loaded.");
128  if (myNetBuilder.getTypeCont().size() > 0) {
129  WRITE_MESSAGE(" " + toString(myNetBuilder.getTypeCont().size()) + " types loaded.");
130  }
131  WRITE_MESSAGE(" " + toString(myNetBuilder.getEdgeCont().size()) + " edges loaded.");
134  "The split of edges was performed " + toString(myNetBuilder.getEdgeCont().getNoEdgeSplits()) + " times.");
135  }
136 
137  //TODO: uncomment the following lines + adapt tests! [Gregor March '17]
138 // if (myNetBuilder.getPTStopCont().size() > 0) {
139 // WRITE_MESSAGE(" " + toString(myNetBuilder.getPTStopCont().size()) + " pt stops loaded.");
140 // }
141  if (GeoConvHelper::getProcessing().usingGeoProjection()) {
142  WRITE_MESSAGE("Proj projection parameters used: '" + GeoConvHelper::getProcessing().getProjString() + "'.");
143  }
144 }
145 
146 /* -------------------------------------------------------------------------
147  * file loading methods
148  * ----------------------------------------------------------------------- */
149 void
151  // load nodes
154  oc.getStringVector("node-files"), "nodes");
155  // load the edges
161  oc),
162  oc.getStringVector("edge-files"), "edges");
163  if (!deprecatedVehicleClassesSeen.empty()) {
164  WRITE_WARNING("Deprecated vehicle class(es) '" + toString(deprecatedVehicleClassesSeen) + "' in input edge files.");
165  }
166  // load the connections
170  oc.getStringVector("connection-files"), "connections");
171  // load traffic lights (needs to come last, references loaded edges and connections)
174  oc.getStringVector("tllogic-files"), "traffic lights");
175 
176  // load public transport stops (used for restricting edge removal and as input when repairing railroad topology)
181  oc.getStringVector("ptstop-files"), "public transport stops");
182 
183  // load public transport lines (used as input when repairing railroad topology)
188  oc.getStringVector("ptline-files"), "public transport lines");
189 }
190 
191 void
192 NILoader::loadXMLType(SUMOSAXHandler* handler, const std::vector<std::string>& files,
193  const std::string& type, const bool stringParse) {
194  // build parser
195  std::string exceptMsg = "";
196  // start the parsing
197  try {
198  for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
199  if (stringParse) {
200  handler->setFileName("built in type map");
201  SUMOSAXReader* reader = XMLSubSys::getSAXReader(*handler);
202  reader->parseString(*file);
203  delete reader;
204  continue;
205  }
206  if (!FileHelpers::isReadable(*file)) {
207  WRITE_ERROR("Could not open " + type + "-file '" + *file + "'.");
208  exceptMsg = "Process Error";
209  continue;
210  }
211  PROGRESS_BEGIN_MESSAGE("Parsing " + type + " from '" + *file + "'");
212  XMLSubSys::runParser(*handler, *file);
214  }
215  } catch (const XERCES_CPP_NAMESPACE::XMLException& toCatch) {
216  exceptMsg = StringUtils::transcode(toCatch.getMessage())
217  + "\n The " + type + " could not be loaded from '" + handler->getFileName() + "'.";
218  } catch (const ProcessError& toCatch) {
219  exceptMsg =
220  std::string(toCatch.what()) + "\n The " + type + " could not be loaded from '" + handler->getFileName() + "'.";
221  } catch (...) {
222  exceptMsg = "The " + type + " could not be loaded from '" + handler->getFileName() + "'.";
223  }
224  delete handler;
225  if (exceptMsg != "") {
226  throw ProcessError(exceptMsg);
227  }
228 }
229 
230 /****************************************************************************/
Importer for network edges stored in XML.
std::set< std::string > deprecatedVehicleClassesSeen
NBTypeCont & getTypeCont()
Returns a reference to the type container.
Definition: NBNetBuilder.h:160
static bool isReadable(std::string path)
Checks whether the given file is readable.
Definition: FileHelpers.cpp:47
static GeoConvHelper & getProcessing()
the coordinate transformation to use for input conversion and processing
Definition: GeoConvHelper.h:84
const std::string & getFileName() const
returns the current file name
Importer for edge connections stored in XML.
const std::string osmTypemap
Definition: typemap.h:38
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.
SAX-reader encapsulation containing binary reader.
Definition: SUMOSAXReader.h:51
NBPTStopCont & getPTStopCont()
Returns a reference to the pt stop container.
Definition: NBNetBuilder.h:176
NBPTLineCont & getPTLineCont()
Returns a reference to the pt line container.
Definition: NBNetBuilder.h:181
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
void parseString(std::string content)
SAX-handler base for SUMO-files.
int getNoEdgeSplits() const
Returns the number of edge splits.
Definition: NBEdgeCont.h:321
static bool runParser(GenericSAXHandler &handler, const std::string &file, const bool isNet=false)
Runs the given handler on the given file; returns if everything&#39;s ok.
Definition: XMLSubSys.cpp:113
void discardRailSignals()
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:241
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads network definition from the assigned option and stores it in the given network builder...
static std::string transcode(const XMLCh *const data)
converts a 0-terminated XMLCh* array (usually UTF-16, stemming from Xerces) into std::string in UTF-8...
Definition: StringUtils.h:133
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given OSM file.
void loadXMLType(SUMOSAXHandler *handler, const std::vector< std::string > &files, const std::string &type, const bool stringParse=false)
Definition: NILoader.cpp:192
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
~NILoader()
Destructor.
Definition: NILoader.cpp:71
static void loadIfSet(OptionsCont &oc)
loads heigh map data if any loading options are set
void setFileName(const std::string &name)
Sets the current file name.
Importer for network nodes stored in XML.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
int size() const
Returns the number of nodes stored in this container.
Definition: NBNodeCont.h:257
NBEdgeCont & getEdgeCont()
Definition: NBNetBuilder.h:150
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 RoboCup Rescue League files.
Importer for network edges stored in XML.
static SUMOSAXReader * getSAXReader(SUMOSAXHandler &handler)
Builds a reader and assigns the handler to it.
Definition: XMLSubSys.cpp:101
std::vector< std::string > getStringVector(const std::string &name) const
Returns the list of string-vector-value of the named option (only for Option_String) ...
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition: MsgHandler.h:243
void load(OptionsCont &oc)
Definition: NILoader.cpp:74
void loadXML(OptionsCont &oc)
Definition: NILoader.cpp:150
int size() const
Returns the number of districts inside the container.
const std::string opendriveTypemap
Definition: typemap.h:1
static void loadNetwork(OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given SUMO file.
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:247
Importer for edge type information stored in XML.
NBNodeCont & getNodeCont()
Returns a reference to the node container.
Definition: NBNetBuilder.h:155
Instance responsible for building networks.
Definition: NBNetBuilder.h:109
int size() const
Returns the number of edges.
Definition: NBEdgeCont.h:306
int getNumExtracted() const
return the number of extracted traffic light definitions
A storage for options typed value containers)
Definition: OptionsCont.h:92
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads network definition from the assigned option and stores it in the given network builder...
NBTrafficLightLogicCont & getTLLogicCont()
Returns a reference to the traffic light logics container.
Definition: NBNetBuilder.h:165
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given ITSUMO network files.
void discardTrafficLights(NBTrafficLightLogicCont &tlc, bool geometryLike, bool guessSignals)
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given MATSIM network files.
NBNetBuilder & myNetBuilder
The network builder to fill with loaded data.
Definition: NILoader.h:80
Importer for edge connections stored in XML.
#define PROGRESS_DONE_MESSAGE()
Definition: MsgHandler.h:244
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:242
NILoader(NBNetBuilder &nb)
Constructor.
Definition: NILoader.cpp:68
NBDistrictCont & getDistrictCont()
Returns a reference the districts container.
Definition: NBNetBuilder.h:170
int size() const
Returns the number of known types.
Definition: NBTypeCont.h:97