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