Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netimport/NILoader.cpp
169665 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 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
/****************************************************************************/
14
/// @file NILoader.cpp
15
/// @author Daniel Krajzewicz
16
/// @author Jakob Erdmann
17
/// @author Sascha Krieg
18
/// @author Michael Behrisch
19
/// @author Robert Hilbrich
20
/// @date Tue, 20 Nov 2001
21
///
22
// Perfoms network import
23
/****************************************************************************/
24
#include <config.h>
25
26
#include <string>
27
#include <utils/common/UtilExceptions.h>
28
#include <utils/common/MsgHandler.h>
29
#include <utils/options/OptionsCont.h>
30
#include <utils/options/Option.h>
31
#include <utils/common/FileHelpers.h>
32
#include <utils/common/StringUtils.h>
33
#include <utils/common/ToString.h>
34
#include <utils/common/StringUtils.h>
35
#include <utils/geom/GeoConvHelper.h>
36
#include <netbuild/NBTypeCont.h>
37
#include <netbuild/NBNodeCont.h>
38
#include <netbuild/NBEdgeCont.h>
39
#include <netbuild/NBHeightMapper.h>
40
#include <netbuild/NBNetBuilder.h>
41
#include <netimport/NIXMLEdgesHandler.h>
42
#include <netimport/NIXMLNodesHandler.h>
43
#include <netimport/NIXMLTrafficLightsHandler.h>
44
#include <netimport/NIXMLTypesHandler.h>
45
#include <netimport/NIXMLPTHandler.h>
46
#include <netimport/NIXMLShapeHandler.h>
47
#include <netimport/NIXMLConnectionsHandler.h>
48
#include <netimport/NIImporter_DlrNavteq.h>
49
#include <netimport/NIImporter_VISUM.h>
50
#include <netimport/vissim/NIImporter_Vissim.h>
51
#include <netimport/NIImporter_ArcView.h>
52
#include <netimport/NIImporter_SUMO.h>
53
#include <netimport/NIImporter_OpenStreetMap.h>
54
#include <netimport/NIImporter_OpenDrive.h>
55
#include <netimport/NIImporter_MATSim.h>
56
#include <netimport/NIImporter_ITSUMO.h>
57
#include <netimport/typemap.h>
58
#include "NILoader.h"
59
#include "NITypeLoader.h"
60
61
// ===========================================================================
62
// method definitions
63
// ===========================================================================
64
NILoader::NILoader(NBNetBuilder& nb)
65
: myNetBuilder(nb) {}
66
67
NILoader::~NILoader() {}
68
69
void
70
NILoader::load(OptionsCont& oc) {
71
bool ok = true;
72
// load types first
73
NIXMLTypesHandler handler(myNetBuilder.getTypeCont());
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
ok &= NITypeLoader::load(handler, files, toString(SUMO_TAG_TYPES), true);
83
} else {
84
ok &= NITypeLoader::load(handler, oc.getStringVector("type-files"), toString(SUMO_TAG_TYPES));
85
}
86
// try to load height data so it is ready for use by other importers
87
NBHeightMapper::loadIfSet(oc);
88
// try to load using different methods
89
NIImporter_SUMO::loadNetwork(oc, myNetBuilder);
90
NIImporter_OpenStreetMap::loadNetwork(oc, myNetBuilder);
91
NIImporter_VISUM::loadNetwork(oc, myNetBuilder);
92
NIImporter_ArcView::loadNetwork(oc, myNetBuilder);
93
NIImporter_Vissim::loadNetwork(oc, myNetBuilder);
94
NIImporter_DlrNavteq::loadNetwork(oc, myNetBuilder);
95
NIImporter_OpenDrive::loadNetwork(oc, myNetBuilder);
96
NIImporter_MATSim::loadNetwork(oc, myNetBuilder);
97
NIImporter_ITSUMO::loadNetwork(oc, myNetBuilder);
98
if (oc.getBool("tls.discard-loaded") || oc.getBool("tls.discard-simple")) {
99
myNetBuilder.getNodeCont().discardTrafficLights(myNetBuilder.getTLLogicCont(), oc.getBool("tls.discard-simple"));
100
int removed = myNetBuilder.getTLLogicCont().getNumExtracted();
101
if (removed > 0) {
102
WRITE_MESSAGEF(TL(" Removed % traffic lights before loading plain-XML"), toString(removed));
103
}
104
}
105
if (oc.getBool("railway.signals.discard")) {
106
myNetBuilder.getNodeCont().discardRailSignals();
107
}
108
ok &= loadXML(oc);
109
// check the loaded structures
110
if (myNetBuilder.getNodeCont().size() == 0) {
111
throw ProcessError(TL("No nodes loaded."));
112
}
113
if (myNetBuilder.getEdgeCont().size() == 0) {
114
throw ProcessError(TL("No edges loaded."));
115
}
116
if (!myNetBuilder.getEdgeCont().checkConsistency(myNetBuilder.getNodeCont())) {
117
throw ProcessError();
118
}
119
if (!ok && !oc.getBool("ignore-errors")) {
120
throw ProcessError();
121
}
122
// configure default values that depend on other values
123
myNetBuilder.getNodeCont().applyConditionalDefaults();
124
// report loaded structures
125
WRITE_MESSAGE(TL(" Import done:"));
126
if (myNetBuilder.getDistrictCont().size() > 0) {
127
WRITE_MESSAGEF(TL(" % districts loaded."), toString(myNetBuilder.getDistrictCont().size()));
128
}
129
WRITE_MESSAGEF(TL(" % nodes loaded."), toString(myNetBuilder.getNodeCont().size()));
130
if (myNetBuilder.getTypeCont().size() > 0) {
131
WRITE_MESSAGEF(TL(" % types loaded."), toString(myNetBuilder.getTypeCont().size()));
132
}
133
WRITE_MESSAGEF(TL(" % edges loaded."), toString(myNetBuilder.getEdgeCont().size()));
134
if (myNetBuilder.getEdgeCont().getNumEdgeSplits() > 0) {
135
WRITE_MESSAGEF(TL("The split of edges was performed % times."), toString(myNetBuilder.getEdgeCont().getNumEdgeSplits()));
136
}
137
138
//TODO: uncomment the following lines + adapt tests! [Gregor March '17]
139
// if (myNetBuilder.getPTStopCont().size() > 0) {
140
// WRITE_MESSAGEF(TL(" % pt stops loaded."), toString(myNetBuilder.getPTStopCont().size()));
141
// }
142
if (GeoConvHelper::getProcessing().usingGeoProjection()) {
143
WRITE_MESSAGEF(TL("Proj projection parameters used: '%'."), GeoConvHelper::getProcessing().getProjString());
144
}
145
}
146
147
/* -------------------------------------------------------------------------
148
* file loading methods
149
* ----------------------------------------------------------------------- */
150
bool
151
NILoader::loadXML(OptionsCont& oc) {
152
// load nodes
153
NIXMLNodesHandler nodesHandler(myNetBuilder.getNodeCont(), myNetBuilder.getEdgeCont(),
154
myNetBuilder.getTLLogicCont(), oc);
155
bool ok = NITypeLoader::load(nodesHandler, oc.getStringVector("node-files"), "nodes");
156
// load the edges
157
if (ok) {
158
NIXMLEdgesHandler edgesHandler(myNetBuilder.getNodeCont(), myNetBuilder.getEdgeCont(),
159
myNetBuilder.getTypeCont(), myNetBuilder.getDistrictCont(),
160
myNetBuilder.getTLLogicCont(), oc);
161
ok = NITypeLoader::load(edgesHandler, oc.getStringVector("edge-files"), "edges");
162
}
163
if (!deprecatedVehicleClassesSeen.empty()) {
164
WRITE_WARNINGF(TL("Deprecated vehicle class(es) '%' in input edge files."), toString(deprecatedVehicleClassesSeen));
165
}
166
// load the connections
167
if (ok) {
168
NIXMLConnectionsHandler connectionsHandler(myNetBuilder.getEdgeCont(),
169
myNetBuilder.getNodeCont(), myNetBuilder.getTLLogicCont());
170
ok = NITypeLoader::load(connectionsHandler, oc.getStringVector("connection-files"), "connections");
171
}
172
// load traffic lights (needs to come last, references loaded edges and connections)
173
if (ok) {
174
NIXMLTrafficLightsHandler tlHandler(myNetBuilder.getTLLogicCont(), myNetBuilder.getEdgeCont());
175
ok = NITypeLoader::load(tlHandler, oc.getStringVector("tllogic-files"), "traffic lights");
176
}
177
178
// load public transport stops (used for restricting edge removal and as input when repairing railroad topology)
179
if (ok && oc.exists("ptstop-files")) {
180
NIXMLPTHandler ptHandler(myNetBuilder.getEdgeCont(),
181
myNetBuilder.getPTStopCont(), myNetBuilder.getPTLineCont());
182
ok = NITypeLoader::load(ptHandler, oc.getStringVector("ptstop-files"), "public transport stops");
183
}
184
185
// load public transport lines (used as input when repairing railroad topology)
186
if (ok && oc.exists("ptline-files")) {
187
NIXMLPTHandler ptHandler(myNetBuilder.getEdgeCont(),
188
myNetBuilder.getPTStopCont(), myNetBuilder.getPTLineCont());
189
ok = NITypeLoader::load(ptHandler, oc.getStringVector("ptline-files"), "public transport lines");
190
}
191
192
// load shapes for output formats that embed shape data
193
if (ok && oc.exists("polygon-files")) {
194
NIXMLShapeHandler shapeHandler(myNetBuilder.getShapeCont(), myNetBuilder.getEdgeCont());
195
ok = NITypeLoader::load(shapeHandler, oc.getStringVector("polygon-files"), "polygon data");
196
}
197
return ok;
198
}
199
200
201
/****************************************************************************/
202
203