Line data Source code
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 : /****************************************************************************/
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 2373 : NILoader::NILoader(NBNetBuilder& nb)
65 2373 : : myNetBuilder(nb) {}
66 :
67 2373 : NILoader::~NILoader() {}
68 :
69 : void
70 2373 : NILoader::load(OptionsCont& oc) {
71 : bool ok = true;
72 : // load types first
73 2373 : NIXMLTypesHandler handler(myNetBuilder.getTypeCont());
74 4746 : if (!oc.isSet("type-files")) {
75 : std::vector<std::string> files;
76 3590 : if (oc.isSet("osm-files")) {
77 0 : files.push_back(osmTypemap);
78 : }
79 3590 : if (oc.isSet("opendrive-files")) {
80 0 : files.push_back(opendriveTypemap);
81 : }
82 3590 : if (oc.isSet("visum-file")) {
83 8 : files.push_back(visumTypemap);
84 : }
85 1795 : ok &= NITypeLoader::load(handler, files, toString(SUMO_TAG_TYPES), true);
86 1795 : } else {
87 1156 : 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
90 2373 : NBHeightMapper::loadIfSet(oc);
91 : // try to load using different methods
92 2373 : NIImporter_SUMO::loadNetwork(oc, myNetBuilder);
93 2373 : NIImporter_OpenStreetMap::loadNetwork(oc, myNetBuilder);
94 2373 : NIImporter_VISUM::loadNetwork(oc, myNetBuilder);
95 2373 : NIImporter_ArcView::loadNetwork(oc, myNetBuilder);
96 2373 : NIImporter_Vissim::loadNetwork(oc, myNetBuilder);
97 2373 : NIImporter_DlrNavteq::loadNetwork(oc, myNetBuilder);
98 2373 : NIImporter_OpenDrive::loadNetwork(oc, myNetBuilder);
99 2373 : NIImporter_MATSim::loadNetwork(oc, myNetBuilder);
100 2373 : NIImporter_ITSUMO::loadNetwork(oc, myNetBuilder);
101 4739 : if (oc.getBool("tls.discard-loaded") || oc.getBool("tls.discard-simple")) {
102 55 : myNetBuilder.getNodeCont().discardTrafficLights(myNetBuilder.getTLLogicCont(), oc.getBool("tls.discard-simple"));
103 55 : int removed = myNetBuilder.getTLLogicCont().getNumExtracted();
104 55 : if (removed > 0) {
105 94 : WRITE_MESSAGEF(TL(" Removed % traffic lights before loading plain-XML"), toString(removed));
106 : }
107 : }
108 4746 : if (oc.getBool("railway.signals.discard")) {
109 1 : myNetBuilder.getNodeCont().discardRailSignals();
110 : }
111 2373 : ok &= loadXML(oc);
112 : // check the loaded structures
113 2373 : if (myNetBuilder.getNodeCont().size() == 0) {
114 152 : throw ProcessError(TL("No nodes loaded."));
115 : }
116 2297 : if (myNetBuilder.getEdgeCont().size() == 0) {
117 46 : throw ProcessError(TL("No edges loaded."));
118 : }
119 2274 : if (!myNetBuilder.getEdgeCont().checkConsistency(myNetBuilder.getNodeCont())) {
120 1 : throw ProcessError();
121 : }
122 2332 : if (!ok && !oc.getBool("ignore-errors")) {
123 55 : throw ProcessError();
124 : }
125 : // configure default values that depend on other values
126 2218 : myNetBuilder.getNodeCont().applyConditionalDefaults();
127 : // report loaded structures
128 2218 : WRITE_MESSAGE(TL(" Import done:"));
129 2218 : if (myNetBuilder.getDistrictCont().size() > 0) {
130 6 : WRITE_MESSAGEF(TL(" % districts loaded."), toString(myNetBuilder.getDistrictCont().size()));
131 : }
132 4436 : WRITE_MESSAGEF(TL(" % nodes loaded."), toString(myNetBuilder.getNodeCont().size()));
133 2218 : if (myNetBuilder.getTypeCont().size() > 0) {
134 1330 : WRITE_MESSAGEF(TL(" % types loaded."), toString(myNetBuilder.getTypeCont().size()));
135 : }
136 4436 : WRITE_MESSAGEF(TL(" % edges loaded."), toString(myNetBuilder.getEdgeCont().size()));
137 2218 : if (myNetBuilder.getEdgeCont().getNumEdgeSplits() > 0) {
138 204 : 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 2218 : if (GeoConvHelper::getProcessing().usingGeoProjection()) {
146 1710 : WRITE_MESSAGEF(TL("Proj projection parameters used: '%'."), GeoConvHelper::getProcessing().getProjString());
147 : }
148 2373 : }
149 :
150 : /* -------------------------------------------------------------------------
151 : * file loading methods
152 : * ----------------------------------------------------------------------- */
153 : bool
154 2373 : NILoader::loadXML(OptionsCont& oc) {
155 : // load nodes
156 : NIXMLNodesHandler nodesHandler(myNetBuilder.getNodeCont(), myNetBuilder.getEdgeCont(),
157 2373 : myNetBuilder.getTLLogicCont(), oc);
158 4746 : bool ok = NITypeLoader::load(nodesHandler, oc.getStringVector("node-files"), "nodes");
159 : // load the edges
160 2373 : if (ok) {
161 : NIXMLEdgesHandler edgesHandler(myNetBuilder.getNodeCont(), myNetBuilder.getEdgeCont(),
162 : myNetBuilder.getTypeCont(), myNetBuilder.getDistrictCont(),
163 2371 : myNetBuilder.getTLLogicCont(), oc);
164 4742 : ok = NITypeLoader::load(edgesHandler, oc.getStringVector("edge-files"), "edges");
165 2371 : }
166 2373 : if (!deprecatedVehicleClassesSeen.empty()) {
167 0 : WRITE_WARNINGF(TL("Deprecated vehicle class(es) '%' in input edge files."), toString(deprecatedVehicleClassesSeen));
168 : }
169 : // load the connections
170 2373 : if (ok) {
171 : NIXMLConnectionsHandler connectionsHandler(myNetBuilder.getEdgeCont(),
172 2318 : myNetBuilder.getNodeCont(), myNetBuilder.getTLLogicCont());
173 4636 : ok = NITypeLoader::load(connectionsHandler, oc.getStringVector("connection-files"), "connections");
174 2318 : }
175 : // load traffic lights (needs to come last, references loaded edges and connections)
176 2318 : if (ok) {
177 2315 : NIXMLTrafficLightsHandler tlHandler(myNetBuilder.getTLLogicCont(), myNetBuilder.getEdgeCont());
178 4630 : ok = NITypeLoader::load(tlHandler, oc.getStringVector("tllogic-files"), "traffic lights");
179 2315 : }
180 :
181 : // load public transport stops (used for restricting edge removal and as input when repairing railroad topology)
182 4743 : if (ok && oc.exists("ptstop-files")) {
183 : NIXMLPTHandler ptHandler(myNetBuilder.getEdgeCont(),
184 2313 : myNetBuilder.getPTStopCont(), myNetBuilder.getPTLineCont());
185 4626 : ok = NITypeLoader::load(ptHandler, oc.getStringVector("ptstop-files"), "public transport stops");
186 2313 : }
187 :
188 : // load public transport lines (used as input when repairing railroad topology)
189 4686 : if (ok && oc.exists("ptline-files")) {
190 : NIXMLPTHandler ptHandler(myNetBuilder.getEdgeCont(),
191 2313 : myNetBuilder.getPTStopCont(), myNetBuilder.getPTLineCont());
192 4626 : ok = NITypeLoader::load(ptHandler, oc.getStringVector("ptline-files"), "public transport lines");
193 2313 : }
194 :
195 : // load shapes for output formats that embed shape data
196 4686 : if (ok && oc.exists("polygon-files")) {
197 2313 : NIXMLShapeHandler shapeHandler(myNetBuilder.getShapeCont(), myNetBuilder.getEdgeCont());
198 4626 : ok = NITypeLoader::load(shapeHandler, oc.getStringVector("polygon-files"), "polygon data");
199 : }
200 2373 : return ok;
201 2373 : }
202 :
203 :
204 : /****************************************************************************/
|