Line data Source code
1 : /****************************************************************************/ 2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3 : // Copyright (C) 2001-2024 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 2224 : NILoader::NILoader(NBNetBuilder& nb) 65 2224 : : myNetBuilder(nb) {} 66 : 67 2224 : NILoader::~NILoader() {} 68 : 69 : void 70 2224 : NILoader::load(OptionsCont& oc) { 71 : bool ok = true; 72 : // load types first 73 2224 : NIXMLTypesHandler handler(myNetBuilder.getTypeCont()); 74 4448 : if (!oc.isSet("type-files")) { 75 : std::vector<std::string> files; 76 3976 : if (oc.isSet("osm-files")) { 77 0 : files.push_back(osmTypemap); 78 : } 79 3976 : if (oc.isSet("opendrive-files")) { 80 0 : files.push_back(opendriveTypemap); 81 : } 82 1988 : ok &= NITypeLoader::load(handler, files, "types", true); 83 1988 : } else { 84 472 : ok &= NITypeLoader::load(handler, oc.getStringVector("type-files"), "types"); 85 : } 86 : // try to load height data so it is ready for use by other importers 87 2224 : NBHeightMapper::loadIfSet(oc); 88 : // try to load using different methods 89 2224 : NIImporter_SUMO::loadNetwork(oc, myNetBuilder); 90 2224 : NIImporter_OpenStreetMap::loadNetwork(oc, myNetBuilder); 91 2224 : NIImporter_VISUM::loadNetwork(oc, myNetBuilder); 92 2224 : NIImporter_ArcView::loadNetwork(oc, myNetBuilder); 93 2224 : NIImporter_Vissim::loadNetwork(oc, myNetBuilder); 94 2224 : NIImporter_DlrNavteq::loadNetwork(oc, myNetBuilder); 95 2224 : NIImporter_OpenDrive::loadNetwork(oc, myNetBuilder); 96 2224 : NIImporter_MATSim::loadNetwork(oc, myNetBuilder); 97 2224 : NIImporter_ITSUMO::loadNetwork(oc, myNetBuilder); 98 6715 : if (oc.getBool("tls.discard-loaded") || oc.getBool("tls.discard-simple")) { 99 159 : myNetBuilder.getNodeCont().discardTrafficLights(myNetBuilder.getTLLogicCont(), oc.getBool("tls.discard-simple"), 100 53 : oc.getBool("tls.guess-signals")); 101 53 : int removed = myNetBuilder.getTLLogicCont().getNumExtracted(); 102 53 : if (removed > 0) { 103 94 : WRITE_MESSAGEF(TL(" Removed % traffic lights before loading plain-XML"), toString(removed)); 104 : } 105 : } 106 4448 : if (oc.getBool("railway.signals.discard")) { 107 1 : myNetBuilder.getNodeCont().discardRailSignals(); 108 : } 109 2224 : ok &= loadXML(oc); 110 : // check the loaded structures 111 2224 : if (myNetBuilder.getNodeCont().size() == 0) { 112 294 : throw ProcessError(TL("No nodes loaded.")); 113 : } 114 2077 : if (myNetBuilder.getEdgeCont().size() == 0) { 115 62 : throw ProcessError(TL("No edges loaded.")); 116 : } 117 2046 : if (!myNetBuilder.getEdgeCont().checkConsistency(myNetBuilder.getNodeCont())) { 118 1 : throw ProcessError(); 119 : } 120 2106 : if (!ok && !oc.getBool("ignore-errors")) { 121 55 : throw ProcessError(); 122 : } 123 : // configure default values that depend on other values 124 1990 : myNetBuilder.getNodeCont().applyConditionalDefaults(); 125 : // report loaded structures 126 1990 : WRITE_MESSAGE(TL(" Import done:")); 127 1990 : if (myNetBuilder.getDistrictCont().size() > 0) { 128 4 : WRITE_MESSAGEF(TL(" % districts loaded."), toString(myNetBuilder.getDistrictCont().size())); 129 : } 130 3980 : WRITE_MESSAGEF(TL(" % nodes loaded."), toString(myNetBuilder.getNodeCont().size())); 131 1990 : if (myNetBuilder.getTypeCont().size() > 0) { 132 604 : WRITE_MESSAGEF(TL(" % types loaded."), toString(myNetBuilder.getTypeCont().size())); 133 : } 134 3980 : WRITE_MESSAGEF(TL(" % edges loaded."), toString(myNetBuilder.getEdgeCont().size())); 135 1990 : if (myNetBuilder.getEdgeCont().getNumEdgeSplits() > 0) { 136 188 : WRITE_MESSAGEF(TL("The split of edges was performed % times."), toString(myNetBuilder.getEdgeCont().getNumEdgeSplits())); 137 : } 138 : 139 : //TODO: uncomment the following lines + adapt tests! [Gregor March '17] 140 : // if (myNetBuilder.getPTStopCont().size() > 0) { 141 : // WRITE_MESSAGEF(TL(" % pt stops loaded."), toString(myNetBuilder.getPTStopCont().size())); 142 : // } 143 1990 : if (GeoConvHelper::getProcessing().usingGeoProjection()) { 144 919 : WRITE_MESSAGEF(TL("Proj projection parameters used: '%'."), GeoConvHelper::getProcessing().getProjString()); 145 : } 146 2224 : } 147 : 148 : /* ------------------------------------------------------------------------- 149 : * file loading methods 150 : * ----------------------------------------------------------------------- */ 151 : bool 152 2224 : NILoader::loadXML(OptionsCont& oc) { 153 : // load nodes 154 : NIXMLNodesHandler nodesHandler(myNetBuilder.getNodeCont(), myNetBuilder.getEdgeCont(), 155 2224 : myNetBuilder.getTLLogicCont(), oc); 156 4448 : bool ok = NITypeLoader::load(nodesHandler, oc.getStringVector("node-files"), "nodes"); 157 : // load the edges 158 2224 : if (ok) { 159 : NIXMLEdgesHandler edgesHandler(myNetBuilder.getNodeCont(), myNetBuilder.getEdgeCont(), 160 : myNetBuilder.getTypeCont(), myNetBuilder.getDistrictCont(), 161 2222 : myNetBuilder.getTLLogicCont(), oc); 162 4444 : ok = NITypeLoader::load(edgesHandler, oc.getStringVector("edge-files"), "edges"); 163 2222 : } 164 2224 : if (!deprecatedVehicleClassesSeen.empty()) { 165 0 : WRITE_WARNINGF(TL("Deprecated vehicle class(es) '%' in input edge files."), toString(deprecatedVehicleClassesSeen)); 166 : } 167 : // load the connections 168 2224 : if (ok) { 169 : NIXMLConnectionsHandler connectionsHandler(myNetBuilder.getEdgeCont(), 170 2168 : myNetBuilder.getNodeCont(), myNetBuilder.getTLLogicCont()); 171 4336 : ok = NITypeLoader::load(connectionsHandler, oc.getStringVector("connection-files"), "connections"); 172 2168 : } 173 : // load traffic lights (needs to come last, references loaded edges and connections) 174 2224 : if (ok) { 175 2165 : NIXMLTrafficLightsHandler tlHandler(myNetBuilder.getTLLogicCont(), myNetBuilder.getEdgeCont()); 176 4330 : ok = NITypeLoader::load(tlHandler, oc.getStringVector("tllogic-files"), "traffic lights"); 177 2165 : } 178 : 179 : // load public transport stops (used for restricting edge removal and as input when repairing railroad topology) 180 4387 : if (ok && oc.exists("ptstop-files")) { 181 : NIXMLPTHandler ptHandler(myNetBuilder.getEdgeCont(), 182 2163 : myNetBuilder.getPTStopCont(), myNetBuilder.getPTLineCont()); 183 4326 : ok = NITypeLoader::load(ptHandler, oc.getStringVector("ptstop-files"), "public transport stops"); 184 2163 : } 185 : 186 : // load public transport lines (used as input when repairing railroad topology) 187 4387 : if (ok && oc.exists("ptline-files")) { 188 : NIXMLPTHandler ptHandler(myNetBuilder.getEdgeCont(), 189 2163 : myNetBuilder.getPTStopCont(), myNetBuilder.getPTLineCont()); 190 4326 : ok = NITypeLoader::load(ptHandler, oc.getStringVector("ptline-files"), "public transport lines"); 191 2163 : } 192 : 193 : // load shapes for output formats that embed shape data 194 4387 : if (ok && oc.exists("polygon-files")) { 195 2163 : NIXMLShapeHandler shapeHandler(myNetBuilder.getShapeCont(), myNetBuilder.getEdgeCont()); 196 4326 : ok = NITypeLoader::load(shapeHandler, oc.getStringVector("polygon-files"), "polygon data"); 197 : } 198 2224 : return ok; 199 2224 : } 200 : 201 : 202 : /****************************************************************************/