|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00010 // Main for POLYCONVERT 00011 /****************************************************************************/ 00012 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00013 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00014 /****************************************************************************/ 00015 // 00016 // This file is part of SUMO. 00017 // SUMO is free software: you can redistribute it and/or modify 00018 // it under the terms of the GNU General Public License as published by 00019 // the Free Software Foundation, either version 3 of the License, or 00020 // (at your option) any later version. 00021 // 00022 /****************************************************************************/ 00023 00024 00025 // =========================================================================== 00026 // included modules 00027 // =========================================================================== 00028 #ifdef _MSC_VER 00029 #include <windows_config.h> 00030 #else 00031 #include <config.h> 00032 #endif 00033 00034 #ifdef HAVE_VERSION_H 00035 #include <version.h> 00036 #endif 00037 00038 #include <iostream> 00039 #include <string> 00040 #include <utils/options/OptionsIO.h> 00041 #include <utils/options/OptionsCont.h> 00042 #include <utils/common/UtilExceptions.h> 00043 #include <utils/common/StringTokenizer.h> 00044 #include <utils/common/SystemFrame.h> 00045 #include <utils/common/MsgHandler.h> 00046 #include <utils/common/TplConvert.h> 00047 #include <utils/common/ToString.h> 00048 #include <utils/importio/LineReader.h> 00049 #include <utils/geom/GeomConvHelper.h> 00050 #include <utils/geom/Boundary.h> 00051 #include <polyconvert/PCLoaderVisum.h> 00052 #include <polyconvert/PCLoaderDlrNavteq.h> 00053 #include <polyconvert/PCLoaderXML.h> 00054 #include <polyconvert/PCLoaderOSM.h> 00055 #include <polyconvert/PCLoaderArcView.h> 00056 #include <polyconvert/PCTypeMap.h> 00057 #include <polyconvert/PCTypeDefHandler.h> 00058 #include <polyconvert/PCNetProjectionLoader.h> 00059 #include <utils/xml/XMLSubSys.h> 00060 #include <utils/geom/GeoConvHelper.h> 00061 00062 #ifdef CHECK_MEMORY_LEAKS 00063 #include <foreign/nvwa/debug_new.h> 00064 #endif // CHECK_MEMORY_LEAKS 00065 00066 00067 // =========================================================================== 00068 // method definitions 00069 // =========================================================================== 00070 void 00071 fillOptions() { 00072 OptionsCont& oc = OptionsCont::getOptions(); 00073 oc.addCallExample("-c <CONFIGURATION>"); 00074 00075 // insert options sub-topics 00076 SystemFrame::addConfigurationOptions(oc); // fill this subtopic, too 00077 oc.addOptionSubTopic("Input"); 00078 oc.addOptionSubTopic("Output"); 00079 GeoConvHelper::addProjectionOptions(oc); 00080 oc.addOptionSubTopic("Pruning"); 00081 oc.addOptionSubTopic("Processing"); 00082 oc.addOptionSubTopic("Building Defaults"); 00083 SystemFrame::addReportOptions(oc); // fill this subtopic, too 00084 00085 00086 // register options 00087 // add i/o options 00088 // original network 00089 oc.doRegister("net-file", 'n', new Option_FileName()); 00090 oc.addSynonyme("net-file", "net"); 00091 oc.addDescription("net-file", "Input", "Loads SUMO-network FILE as reference to offset and projection"); 00092 00093 // dlrnavteq import 00094 oc.doRegister("dlr-navteq-poly-files", new Option_FileName()); 00095 oc.addDescription("dlr-navteq-poly-files", "Input", "Reads polygons from FILE assuming they're coded in DLR-Navteq (Elmar)-format"); 00096 oc.doRegister("dlr-navteq-poi-files", new Option_FileName()); 00097 oc.addDescription("dlr-navteq-poi-files", "Input", "Reads pois from FILE+ assuming they're coded in DLR-Navteq (Elmar)-format"); 00098 00099 // visum import 00100 oc.doRegister("visum-files", new Option_FileName()); 00101 oc.addSynonyme("visum-files", "visum"); 00102 oc.addDescription("visum-files", "Input", "Reads polygons from FILE assuming it's a Visum-net"); 00103 00104 // xml import 00105 oc.doRegister("xml-files", new Option_FileName()); 00106 oc.addSynonyme("xml-files", "xml"); 00107 oc.addDescription("xml-files", "Input", "Reads pois and shapes from FILE assuming they're coded in XML"); 00108 00109 // osm import 00110 oc.doRegister("osm-files", new Option_FileName()); 00111 oc.addSynonyme("osm-files", "osm"); 00112 oc.addDescription("osm-files", "Input", "Reads pois from FILE+ assuming they're coded in OSM"); 00113 oc.doRegister("osm.keep-full-type", new Option_Bool(false)); 00114 oc.addDescription("osm.keep-full-type", "Input", "The type will be made of the key-value - pair."); 00115 oc.doRegister("osm.use-name", new Option_Bool(false)); 00116 oc.addDescription("osm.use-name", "Input", "The id will be set from the given 'name' attribute."); 00117 00118 // arcview import 00119 oc.doRegister("shapefile-prefixes", new Option_FileName()); 00120 oc.addSynonyme("shapefile-prefixes", "shapefile-prefix"); 00121 oc.addSynonyme("shapefile-prefixes", "shapefile"); 00122 oc.addSynonyme("shapefile-prefixes", "shape-files", true); 00123 oc.addDescription("shapefile-prefixes", "Input", "Reads shapes from shapefiles FILE+"); 00124 00125 oc.doRegister("shapefile.guess-projection", new Option_Bool(false)); 00126 oc.addSynonyme("shapefile.guess-projection", "arcview.guess-projection", true); 00127 oc.addDescription("shapefile.guess-projection", "Input", "Guesses the shapefile's projection"); 00128 00129 oc.doRegister("shapefile.id-column", new Option_FileName()); 00130 oc.addSynonyme("shapefile.id-column", "shapefile.id-name", true); 00131 oc.addSynonyme("shapefile.id-column", "shape-files.id-name", true); 00132 oc.addDescription("shapefile.id-column", "Input", "Defines in which column the id can be found"); 00133 00134 // typemap reading 00135 oc.doRegister("type-file", new Option_FileName()); 00136 oc.addSynonyme("type-file", "typemap", true); 00137 oc.addDescription("type-file", "Input", "Reads types from FILE"); 00138 00139 00140 // output 00141 oc.doRegister("output-file", 'o', new Option_FileName("polygons.xml")); 00142 oc.addSynonyme("output-file", "output"); 00143 oc.addDescription("output-file", "Output", "Write generated polygons/pois to FILE"); 00144 00145 00146 // prunning options 00147 oc.doRegister("prune.in-net", new Option_Bool(false)); 00148 oc.addSynonyme("prune.in-net", "prune.on-net", true); 00149 oc.addDescription("prune.in-net", "Pruning", "Enables pruning on net boundaries"); 00150 00151 oc.doRegister("prune.in-net.offsets", new Option_String("0,0,0,0")); 00152 oc.addSynonyme("prune.in-net.offsets", "prune.on-net.offsets", true); 00153 oc.addDescription("prune.in-net.offsets", "Pruning", "Uses STR as offset definition added to the net boundaries"); 00154 00155 oc.doRegister("prune.boundary", new Option_String()); 00156 oc.addDescription("prune.boundary", "Pruning", "Uses STR as pruning boundary"); 00157 00158 oc.doRegister("prune.keep-list", new Option_String()); 00159 oc.addSynonyme("prune.keep-list", "prune.keep"); 00160 oc.addSynonyme("prune.keep-list", "prune.ignore", true); 00161 oc.addDescription("prune.keep-list", "Pruning", "Items in STR will be kept though out of boundary"); 00162 00163 oc.doRegister("prune.explicit", new Option_String("")); 00164 oc.addSynonyme("prune.explicit", "remove"); 00165 oc.addDescription("prune.explicit", "Pruning", "Items with names in STR will be removed"); 00166 00167 00168 oc.doRegister("offset.x", new Option_Float(0)); 00169 oc.addSynonyme("offset.x", "x-offset-to-apply", true); 00170 oc.addDescription("offset.x", "Processing", "Adds FLOAT to net x-positions"); 00171 00172 oc.doRegister("offset.y", new Option_Float(0)); 00173 oc.addSynonyme("offset.y", "y-offset-to-apply", true); 00174 oc.addDescription("offset.y", "Processing", "Adds FLOAT to net y-positions"); 00175 00176 00177 // building defaults options 00178 oc.doRegister("color", new Option_String("0.2,0.5,1.")); 00179 oc.addDescription("color", "Building Defaults", "Sets STR as default color"); 00180 00181 oc.doRegister("prefix", new Option_String("")); 00182 oc.addDescription("prefix", "Building Defaults", "Sets STR as default prefix"); 00183 00184 oc.doRegister("type", new Option_String("unknown")); 00185 oc.addDescription("type", "Building Defaults", "Sets STR as default type"); 00186 00187 oc.doRegister("layer", new Option_Integer(-1)); 00188 oc.addDescription("layer", "Building Defaults", "Sets INT as default layer"); 00189 00190 oc.doRegister("discard", new Option_Bool(false)); 00191 oc.addDescription("discard", "Building Defaults", "Sets default action to discard"); 00192 } 00193 00194 00195 int 00196 main(int argc, char** argv) { 00197 OptionsCont& oc = OptionsCont::getOptions(); 00198 oc.setApplicationDescription("Importer of polygons and POIs for the road traffic simulation SUMO."); 00199 oc.setApplicationName("polyconvert", "SUMO polyconvert Version " + (std::string)VERSION_STRING); 00200 int ret = 0; 00201 try { 00202 // initialise subsystems 00203 XMLSubSys::init(false); 00204 fillOptions(); 00205 OptionsIO::getOptions(true, argc, argv); 00206 if (oc.processMetaOptions(argc < 2)) { 00207 SystemFrame::close(); 00208 return 0; 00209 } 00210 MsgHandler::initOutputOptions(); 00211 // build the projection 00212 Boundary origNetBoundary, pruningBoundary; 00213 Position netOffset; 00214 std::string proj; 00215 PCNetProjectionLoader::loadIfSet(oc, netOffset, origNetBoundary, pruningBoundary, proj); 00216 if (proj != "") { 00217 if (oc.isDefault("proj")) { 00218 oc.set("proj", proj); 00219 } 00220 if (oc.isDefault("offset.x")) { 00221 oc.set("offset.x", toString(netOffset.x())); 00222 } 00223 if (oc.isDefault("offset.y")) { 00224 oc.set("offset.y", toString(netOffset.y())); 00225 } 00226 } 00227 #ifdef HAVE_PROJ 00228 unsigned numProjections = oc.getBool("simple-projection") + oc.getBool("proj.utm") + oc.getBool("proj.dhdn") + (oc.getString("proj").length() > 1); 00229 if ((oc.isSet("osm-files") || oc.isSet("dlr-navteq-poly-files") || oc.isSet("dlr-navteq-poi-files")) && numProjections == 0) { 00230 oc.set("proj.utm", "true"); 00231 } 00232 if ((oc.isSet("dlr-navteq-poly-files") || oc.isSet("dlr-navteq-poi-files")) && oc.isDefault("proj.scale")) { 00233 oc.set("proj.scale", std::string("5")); 00234 } 00235 #endif 00236 if (!GeoConvHelper::init(oc)) { 00237 throw ProcessError("Could not build projection!"); 00238 } 00239 00240 // check whether the input shall be pruned 00241 bool prune = false; 00242 if (oc.getBool("prune.in-net")) { 00243 if (!oc.isSet("net")) { 00244 throw ProcessError("In order to prune the input on the net, you have to supply a network."); 00245 } 00246 bool ok = true; 00247 // !!! no proper error handling 00248 Boundary offsets = GeomConvHelper::parseBoundaryReporting(oc.getString("prune.in-net.offsets"), "--prune.on-net.offsets", 0, ok); 00249 pruningBoundary = Boundary( 00250 pruningBoundary.xmin() + offsets.xmin(), 00251 pruningBoundary.ymin() + offsets.ymin(), 00252 pruningBoundary.xmax() + offsets.xmax(), 00253 pruningBoundary.ymax() + offsets.ymax()); 00254 prune = true; 00255 } 00256 if (oc.isSet("prune.boundary")) { 00257 bool ok = true; 00258 // !!! no proper error handling 00259 pruningBoundary = GeomConvHelper::parseBoundaryReporting(oc.getString("prune.boundary"), "--prune.boundary", 0, ok); 00260 prune = true; 00261 } 00262 00263 PCPolyContainer toFill(prune, pruningBoundary, oc.getStringVector("remove")); 00264 00265 // read in the type defaults 00266 PCTypeMap tm; 00267 if (oc.isSet("type-file")) { 00268 PCTypeDefHandler handler(oc, tm); 00269 if (!XMLSubSys::runParser(handler, oc.getString("type-file"))) { 00270 // something failed 00271 throw ProcessError(); 00272 } 00273 } 00274 00275 // read in the data 00276 PCLoaderXML::loadIfSet(oc, toFill, tm); // SUMO-XML 00277 PCLoaderOSM::loadIfSet(oc, toFill, tm); // OSM-XML 00278 PCLoaderDlrNavteq::loadIfSet(oc, toFill, tm); // Elmar-files 00279 PCLoaderVisum::loadIfSet(oc, toFill, tm); // VISUM 00280 PCLoaderArcView::loadIfSet(oc, toFill, tm); // shape-files 00281 // check whether any errors occured 00282 if (!MsgHandler::getErrorInstance()->wasInformed()) { 00283 // no? ok, save 00284 toFill.save(oc.getString("output-file")); 00285 } else { 00286 throw ProcessError(); 00287 } 00288 } catch (ProcessError& e) { 00289 if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) { 00290 WRITE_ERROR(e.what()); 00291 } 00292 MsgHandler::getErrorInstance()->inform("Quitting (on error).", false); 00293 ret = 1; 00294 #ifndef _DEBUG 00295 } catch (...) { 00296 MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false); 00297 ret = 1; 00298 #endif 00299 } 00300 SystemFrame::close(); 00301 // report about ending 00302 if (ret == 0) { 00303 std::cout << "Success." << std::endl; 00304 } 00305 return ret; 00306 } 00307 00308 00309 00310 /****************************************************************************/ 00311