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-2019 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>
63 #include <netimport/typemap.h>
64 #include "NILoader.h"
65 
66 // ===========================================================================
67 // method definitions
68 // ===========================================================================
70  : myNetBuilder(nb) {}
71 
73 
74 void
76  // load types first
77  NIXMLTypesHandler* handler =
79  if (!oc.isSet("type-files")) {
80  std::vector<std::string> files;
81  if (oc.isSet("osm-files")) {
82  files.push_back(osmTypemap);
83  }
84  if (oc.isSet("opendrive-files")) {
85  files.push_back(opendriveTypemap);
86  }
87  loadXMLType(handler, files, "types", true);
88  } else {
89  loadXMLType(handler, oc.getStringVector("type-files"), "types");
90  }
91  // try to load height data so it is ready for use by other importers
93  // try to load using different methods
104  if (oc.getBool("tls.discard-loaded") || oc.getBool("tls.discard-simple")) {
106  oc.getBool("tls.guess-signals"));
107  int removed = myNetBuilder.getTLLogicCont().getNumExtracted();
108  if (removed > 0) {
109  WRITE_MESSAGE(" Removed " + toString(removed) + " traffic lights before loading plain-XML");
110  }
111  }
112  if (oc.getBool("railway.signals.discard")) {
114  }
115  loadXML(oc);
116  // check the loaded structures
117  if (myNetBuilder.getNodeCont().size() == 0) {
118  throw ProcessError("No nodes loaded.");
119  }
120  if (myNetBuilder.getEdgeCont().size() == 0) {
121  throw ProcessError("No edges loaded.");
122  }
123  // report loaded structures
124  WRITE_MESSAGE(" Import done:");
125  if (myNetBuilder.getDistrictCont().size() > 0) {
126  WRITE_MESSAGE(" " + toString(myNetBuilder.getDistrictCont().size()) + " districts loaded.");
127  }
128  WRITE_MESSAGE(" " + toString(myNetBuilder.getNodeCont().size()) + " nodes loaded.");
129  if (myNetBuilder.getTypeCont().size() > 0) {
130  WRITE_MESSAGE(" " + toString(myNetBuilder.getTypeCont().size()) + " types loaded.");
131  }
132  WRITE_MESSAGE(" " + toString(myNetBuilder.getEdgeCont().size()) + " edges loaded.");
135  "The split of edges was performed " + toString(myNetBuilder.getEdgeCont().getNoEdgeSplits()) + " times.");
136  }
137 
138  //TODO: uncomment the following lines + adapt tests! [Gregor March '17]
139 // if (myNetBuilder.getPTStopCont().size() > 0) {
140 // WRITE_MESSAGE(" " + toString(myNetBuilder.getPTStopCont().size()) + " pt stops loaded.");
141 // }
142  if (GeoConvHelper::getProcessing().usingGeoProjection()) {
143  WRITE_MESSAGE("Proj projection parameters used: '" + GeoConvHelper::getProcessing().getProjString() + "'.");
144  }
145 }
146 
147 /* -------------------------------------------------------------------------
148  * file loading methods
149  * ----------------------------------------------------------------------- */
150 void
152  // load nodes
155  oc.getStringVector("node-files"), "nodes");
156  // load the edges
162  oc),
163  oc.getStringVector("edge-files"), "edges");
164  if (!deprecatedVehicleClassesSeen.empty()) {
165  WRITE_WARNING("Deprecated vehicle class(es) '" + toString(deprecatedVehicleClassesSeen) + "' in input edge files.");
166  }
167  // load the connections
171  oc.getStringVector("connection-files"), "connections");
172  // load traffic lights (needs to come last, references loaded edges and connections)
175  oc.getStringVector("tllogic-files"), "traffic lights");
176 
177  // load public transport stops (used for restricting edge removal and as input when repairing railroad topology)
178  if (oc.exists("ptstop-files")) {
183  oc.getStringVector("ptstop-files"), "public transport stops");
184  }
185 
186  // load public transport lines (used as input when repairing railroad topology)
187  if (oc.exists("ptline-files")) {
192  oc.getStringVector("ptline-files"), "public transport lines");
193  }
194 
195  // load shapes for output formats that embed shape data
196  if (oc.exists("polygon-files")) {
200  oc.getStringVector("polygon-files"), "polygon data");
201  }
202 }
203 
204 void
205 NILoader::loadXMLType(SUMOSAXHandler* handler, const std::vector<std::string>& files,
206  const std::string& type, const bool stringParse) {
207  // build parser
208  std::string exceptMsg = "";
209  // start the parsing
210  try {
211  for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
212  if (stringParse) {
213  handler->setFileName("built in type map");
214  SUMOSAXReader* reader = XMLSubSys::getSAXReader(*handler);
215  reader->parseString(*file);
216  delete reader;
217  continue;
218  }
219  if (!FileHelpers::isReadable(*file)) {
220  WRITE_ERROR("Could not open " + type + "-file '" + *file + "'.");
221  exceptMsg = "Process Error";
222  continue;
223  }
224  PROGRESS_BEGIN_MESSAGE("Parsing " + type + " from '" + *file + "'");
225  XMLSubSys::runParser(*handler, *file);
227  }
228  } catch (const XERCES_CPP_NAMESPACE::XMLException& toCatch) {
229  exceptMsg = StringUtils::transcode(toCatch.getMessage())
230  + "\n The " + type + " could not be loaded from '" + handler->getFileName() + "'.";
231  } catch (const ProcessError& toCatch) {
232  exceptMsg =
233  std::string(toCatch.what()) + "\n The " + type + " could not be loaded from '" + handler->getFileName() + "'.";
234  } catch (...) {
235  exceptMsg = "The " + type + " could not be loaded from '" + handler->getFileName() + "'.";
236  }
237  delete handler;
238  if (exceptMsg != "") {
239  throw ProcessError(exceptMsg);
240  }
241 }
242 
243 /****************************************************************************/
Importer for network edges stored in XML.
ShapeContainer & getShapeCont()
Definition: NBNetBuilder.h:191
std::set< std::string > deprecatedVehicleClassesSeen
NBTypeCont & getTypeCont()
Returns a reference to the type container.
Definition: NBNetBuilder.h:161
static bool isReadable(std::string path)
Checks whether the given file is readable.
Definition: FileHelpers.cpp:49
static GeoConvHelper & getProcessing()
the coordinate transformation to use for input conversion and processing
Definition: GeoConvHelper.h:87
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:56
NBPTStopCont & getPTStopCont()
Returns a reference to the pt stop container.
Definition: NBNetBuilder.h:177
NBPTLineCont & getPTLineCont()
Returns a reference to the pt line container.
Definition: NBNetBuilder.h:182
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:239
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:132
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:205
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
~NILoader()
Destructor.
Definition: NILoader.cpp:72
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:48
int size() const
Returns the number of nodes stored in this container.
Definition: NBNodeCont.h:264
NBEdgeCont & getEdgeCont()
Definition: NBNetBuilder.h:151
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.
bool exists(const std::string &name) const
Returns the information whether the named option is known.
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:241
void load(OptionsCont &oc)
Definition: NILoader.cpp:75
void loadXML(OptionsCont &oc)
Definition: NILoader.cpp:151
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:245
Importer for edge type information stored in XML.
NBNodeCont & getNodeCont()
Returns a reference to the node container.
Definition: NBNetBuilder.h:156
Instance responsible for building networks.
Definition: NBNetBuilder.h:110
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:90
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:166
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:242
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:240
NILoader(NBNetBuilder &nb)
Constructor.
Definition: NILoader.cpp:69
NBDistrictCont & getDistrictCont()
Returns a reference the districts container.
Definition: NBNetBuilder.h:171
int size() const
Returns the number of known types.
Definition: NBTypeCont.h:100