Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
NILoader.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2026 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>
36#include <netbuild/NBTypeCont.h>
37#include <netbuild/NBNodeCont.h>
38#include <netbuild/NBEdgeCont.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
69void
71 bool ok = true;
72 // load types first
74 if (!oc.isSet("type-files")) {
75 std::vector<std::string> files;
76 if (oc.isSet("osm-files")) {
77 files.push_back(osmTypemap);
78 }
79 if (oc.isSet("opendrive-files")) {
80 files.push_back(opendriveTypemap);
81 }
82 if (oc.isSet("visum-file")) {
83 files.push_back(visumTypemap);
84 }
85 ok &= NITypeLoader::load(handler, files, toString(SUMO_TAG_TYPES), true);
86 } else {
87 ok &= NITypeLoader::load(handler, oc.getStringVector("type-files"), toString(SUMO_TAG_TYPES));
88 }
89 // try to load height data so it is ready for use by other importers
91 // try to load using different methods
101 if (oc.getBool("tls.discard-loaded") || oc.getBool("tls.discard-simple")) {
104 if (removed > 0) {
105 WRITE_MESSAGEF(TL(" Removed % traffic lights before loading plain-XML"), toString(removed));
106 }
107 }
108 if (oc.getBool("railway.signals.discard")) {
110 }
111 ok &= loadXML(oc);
112 // check the loaded structures
113 if (myNetBuilder.getNodeCont().size() == 0) {
114 throw ProcessError(TL("No nodes loaded."));
115 }
116 if (myNetBuilder.getEdgeCont().size() == 0) {
117 throw ProcessError(TL("No edges loaded."));
118 }
120 throw ProcessError();
121 }
122 if (!ok && !oc.getBool("ignore-errors")) {
123 throw ProcessError();
124 }
125 // configure default values that depend on other values
127 // report loaded structures
128 WRITE_MESSAGE(TL(" Import done:"));
129 if (myNetBuilder.getDistrictCont().size() > 0) {
130 WRITE_MESSAGEF(TL(" % districts loaded."), toString(myNetBuilder.getDistrictCont().size()));
131 }
132 WRITE_MESSAGEF(TL(" % nodes loaded."), toString(myNetBuilder.getNodeCont().size()));
133 if (myNetBuilder.getTypeCont().size() > 0) {
134 WRITE_MESSAGEF(TL(" % types loaded."), toString(myNetBuilder.getTypeCont().size()));
135 }
136 WRITE_MESSAGEF(TL(" % edges loaded."), toString(myNetBuilder.getEdgeCont().size()));
138 WRITE_MESSAGEF(TL("The split of edges was performed % times."), toString(myNetBuilder.getEdgeCont().getNumEdgeSplits()));
139 }
140
141 //TODO: uncomment the following lines + adapt tests! [Gregor March '17]
142// if (myNetBuilder.getPTStopCont().size() > 0) {
143// WRITE_MESSAGEF(TL(" % pt stops loaded."), toString(myNetBuilder.getPTStopCont().size()));
144// }
145 if (GeoConvHelper::getProcessing().usingGeoProjection()) {
146 WRITE_MESSAGEF(TL("Proj projection parameters used: '%'."), GeoConvHelper::getProcessing().getProjString());
147 }
148}
149
150/* -------------------------------------------------------------------------
151 * file loading methods
152 * ----------------------------------------------------------------------- */
153bool
155 // load nodes
158 bool ok = NITypeLoader::load(nodesHandler, oc.getStringVector("node-files"), "nodes");
159 // load the edges
160 if (ok) {
164 ok = NITypeLoader::load(edgesHandler, oc.getStringVector("edge-files"), "edges");
165 }
166 if (!deprecatedVehicleClassesSeen.empty()) {
167 WRITE_WARNINGF(TL("Deprecated vehicle class(es) '%' in input edge files."), toString(deprecatedVehicleClassesSeen));
168 }
169 // load the connections
170 if (ok) {
173 ok = NITypeLoader::load(connectionsHandler, oc.getStringVector("connection-files"), "connections");
174 }
175 // load traffic lights (needs to come last, references loaded edges and connections)
176 if (ok) {
178 ok = NITypeLoader::load(tlHandler, oc.getStringVector("tllogic-files"), "traffic lights");
179 }
180
181 // load public transport stops (used for restricting edge removal and as input when repairing railroad topology)
182 if (ok && oc.exists("ptstop-files")) {
185 ok = NITypeLoader::load(ptHandler, oc.getStringVector("ptstop-files"), "public transport stops");
186 }
187
188 // load public transport lines (used as input when repairing railroad topology)
189 if (ok && oc.exists("ptline-files")) {
192 ok = NITypeLoader::load(ptHandler, oc.getStringVector("ptline-files"), "public transport lines");
193 }
194
195 // load shapes for output formats that embed shape data
196 if (ok && oc.exists("polygon-files")) {
198 ok = NITypeLoader::load(shapeHandler, oc.getStringVector("polygon-files"), "polygon data");
199 }
200 return ok;
201}
202
203
204/****************************************************************************/
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:287
#define WRITE_MESSAGEF(...)
Definition MsgHandler.h:289
#define WRITE_MESSAGE(msg)
Definition MsgHandler.h:288
#define TL(string)
Definition MsgHandler.h:304
std::set< std::string > deprecatedVehicleClassesSeen
@ SUMO_TAG_TYPES
types (edge)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:49
static GeoConvHelper & getProcessing()
the coordinate transformation to use for input conversion and processing
int size() const
Returns the number of districts inside the container.
int size() const
Returns the number of edges.
Definition NBEdgeCont.h:287
int getNumEdgeSplits() const
Returns the number of edge splits.
Definition NBEdgeCont.h:313
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.
NBPTLineCont & getPTLineCont()
Returns a reference to the pt line container.
NBPTStopCont & getPTStopCont()
Returns a reference to the pt stop container.
NBNodeCont & getNodeCont()
Returns a reference to the node container.
ShapeContainer & getShapeCont()
NBEdgeCont & getEdgeCont()
NBDistrictCont & getDistrictCont()
Returns a reference the districts container.
NBTypeCont & getTypeCont()
Returns a reference to the type container.
NBTrafficLightLogicCont & getTLLogicCont()
Returns a reference to the traffic light logics container.
int size() const
Returns the number of nodes stored in this container.
Definition NBNodeCont.h:312
void applyConditionalDefaults()
apply default values after loading
void discardRailSignals()
discards rail signals
void discardTrafficLights(NBTrafficLightLogicCont &tlc, bool geometryLike)
int getNumExtracted() const
return the number of extracted traffic light definitions
int size() const
Returns the number of known edgeTypes.
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:154
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)