#include <NIImporter_ArcView.h>
The current importer works only if SUMO was compiled with GDAL-support. If not, an error message is generated.
Definition at line 54 of file NIImporter_ArcView.h.
Static Public Member Functions | |
| static void | loadNetwork (const OptionsCont &oc, NBNetBuilder &nb) |
| Loads content of the optionally given ArcView Shape files. | |
Protected Member Functions | |
| void | load () |
| Loads the shape files. | |
| NIImporter_ArcView (const OptionsCont &oc, NBNodeCont &nc, NBEdgeCont &ec, NBTypeCont &tc, const std::string &dbf_name, const std::string &shp_name, bool speedInKMH) | |
| Constructor. | |
| ~NIImporter_ArcView () | |
| Destructor. | |
Private Member Functions | |
| NIImporter_ArcView (const NIImporter_ArcView &) | |
| Invalidated copy constructor. | |
| NIImporter_ArcView & | operator= (const NIImporter_ArcView &) |
| Invalidated assignment operator. | |
Private Attributes | |
| NBEdgeCont & | myEdgeCont |
| The container to add edges to. | |
| int | myNameAddition |
| A running number to assure unique edge ids. | |
| NBNodeCont & | myNodeCont |
| The container to add nodes to. | |
| const OptionsCont & | myOptions |
| The options to use. | |
| int | myRunningNodeID |
| A running number to assure unique node ids. | |
| std::string | mySHPName |
| The name of the shape file. | |
| bool | mySpeedInKMH |
| Whether the speed is given in km/h. | |
| NBTypeCont & | myTypeCont |
| The container to get the types from. | |
| NIImporter_ArcView::NIImporter_ArcView | ( | const OptionsCont & | oc, | |
| NBNodeCont & | nc, | |||
| NBEdgeCont & | ec, | |||
| NBTypeCont & | tc, | |||
| const std::string & | dbf_name, | |||
| const std::string & | shp_name, | |||
| bool | speedInKMH | |||
| ) | [protected] |
Constructor.
| [in] | oc | Options container to read options from |
| [in] | nc | The node container to store nodes into |
| [in] | ec | The edge container to store edges into |
| [in] | tc | The type container to get edge types from |
| [in] | dbf_name | The name of the according database file |
| [in] | shp_name | The name of the according shape file |
| [in] | speedInKMH | Whether the speed shall be assumed to be given in km/h |
Definition at line 99 of file NIImporter_ArcView.cpp.
00106 : myOptions(oc), mySHPName(shp_name), 00107 myNameAddition(0), 00108 myNodeCont(nc), myEdgeCont(ec), myTypeCont(tc), 00109 mySpeedInKMH(speedInKMH), 00110 myRunningNodeID(0) {}
| NIImporter_ArcView::~NIImporter_ArcView | ( | ) | [protected] |
| NIImporter_ArcView::NIImporter_ArcView | ( | const NIImporter_ArcView & | ) | [private] |
Invalidated copy constructor.
| void NIImporter_ArcView::load | ( | ) | [protected] |
Loads the shape files.
Definition at line 117 of file NIImporter_ArcView.cpp.
References MsgHandler::beginProcessMsg(), MsgHandler::endProcessMsg(), OptionsCont::getBool(), NBTypeCont::getDefaultNoLanes(), NBTypeCont::getDefaultSpeed(), MsgHandler::getErrorInstance(), MsgHandler::getMessageInstance(), OptionsCont::getString(), MsgHandler::inform(), NBEdgeCont::insert(), NBNodeCont::insert(), OptionsCont::isSet(), NBEdge::LANESPREAD_CENTER, NBEdge::LANESPREAD_RIGHT, myEdgeCont, myNodeCont, myOptions, myRunningNodeID, mySHPName, mySpeedInKMH, myTypeCont, StringUtils::prune(), Position2DVector::push_back_noDoublePos(), StringUtils::replace(), NBEdgeCont::retrieve(), NBNodeCont::retrieve(), Position2DVector::reverse(), SUMOReal, toString(), WRITE_WARNING, and GeoConvHelper::x2cartesian().
00117 { 00118 #ifdef HAVE_GDAL 00119 MsgHandler::getMessageInstance()->beginProcessMsg("Loading data from '" + mySHPName + "'..."); 00120 OGRRegisterAll(); 00121 OGRDataSource *poDS = OGRSFDriverRegistrar::Open(mySHPName.c_str(), FALSE); 00122 if (poDS == NULL) { 00123 MsgHandler::getErrorInstance()->inform("Could not open shape description '" + mySHPName + "'."); 00124 return; 00125 } 00126 00127 // begin file parsing 00128 OGRLayer *poLayer = poDS->GetLayer(0); 00129 poLayer->ResetReading(); 00130 00131 // build coordinate transformation 00132 OGRSpatialReference *origTransf = poLayer->GetSpatialRef(); 00133 OGRSpatialReference destTransf; 00134 // use wgs84 as destination 00135 destTransf.SetWellKnownGeogCS("WGS84"); 00136 OGRCoordinateTransformation *poCT = 00137 OGRCreateCoordinateTransformation(origTransf, &destTransf); 00138 if (poCT == NULL) { 00139 if (myOptions.isSet("arcview.guess-projection")) { 00140 OGRSpatialReference origTransf2; 00141 origTransf2.SetWellKnownGeogCS("WGS84"); 00142 poCT = OGRCreateCoordinateTransformation(&origTransf2, &destTransf); 00143 } 00144 if (poCT==0) { 00145 WRITE_WARNING("Could not create geocoordinates converter; check whether proj.4 is installed."); 00146 } 00147 } 00148 00149 OGRFeature *poFeature; 00150 poLayer->ResetReading(); 00151 while ((poFeature = poLayer->GetNextFeature()) != NULL) { 00152 // read in edge attributes 00153 std::string id = 00154 myOptions.isSet("arcview.street-id") 00155 ? poFeature->GetFieldAsString((char*)(myOptions.getString("arcview.street-id").c_str())) 00156 : poFeature->GetFieldAsString("LINK_ID"); 00157 id = StringUtils::prune(id); 00158 if (id=="") { 00159 MsgHandler::getErrorInstance()->inform("Could not obtain edge id."); 00160 return; 00161 } 00162 std::string name = 00163 myOptions.isSet("arcview.street-id") 00164 ? poFeature->GetFieldAsString((char*) myOptions.getString("arcview.street-id").c_str()) 00165 : poFeature->GetFieldAsString("ST_NAME"); 00166 name = StringUtils::prune(StringUtils::replace(name, "&", "&")); 00167 00168 std::string from_node = 00169 myOptions.isSet("arcview.from-id") 00170 ? poFeature->GetFieldAsString((char*)(myOptions.getString("arcview.from-id").c_str())) 00171 : poFeature->GetFieldAsString("REF_IN_ID"); 00172 from_node = StringUtils::prune(from_node); 00173 std::string to_node = 00174 myOptions.isSet("arcview.to-id") 00175 ? poFeature->GetFieldAsString((char*) myOptions.getString("arcview.to-id").c_str()) 00176 : poFeature->GetFieldAsString("NREF_IN_ID"); 00177 to_node = StringUtils::prune(to_node); 00178 if (from_node==""||to_node=="") { 00179 from_node = toString(myRunningNodeID++); 00180 to_node = toString(myRunningNodeID++); 00181 } 00182 std::string type = poFeature->GetFieldAsString("ST_TYP_AFT"); 00183 SUMOReal speed = getSpeed(*poFeature, id); 00184 unsigned int nolanes = getLaneNo(*poFeature, id, speed); 00185 int priority = getPriority(*poFeature, id); 00186 if (nolanes==0||speed==0) { 00187 if (myOptions.getBool("arcview.use-defaults-on-failure")) { 00188 nolanes = myTypeCont.getDefaultNoLanes(); 00189 speed = myTypeCont.getDefaultSpeed(); 00190 } else { 00191 OGRFeature::DestroyFeature(poFeature); 00192 MsgHandler::getErrorInstance()->inform("The description seems to be invalid. Please recheck usage of types."); 00193 return; 00194 } 00195 } 00196 if (mySpeedInKMH) { 00197 speed = speed / (SUMOReal) 3.6; 00198 } 00199 00200 00201 // read in the geometry 00202 OGRGeometry *poGeometry = poFeature->GetGeometryRef(); 00203 OGRwkbGeometryType gtype = poGeometry->getGeometryType(); 00204 assert(gtype==wkbLineString); 00205 OGRLineString *cgeom = (OGRLineString*) poGeometry; 00206 if (poCT!=0) { 00207 // try transform to wgs84 00208 cgeom->transform(poCT); 00209 } 00210 00211 Position2DVector shape; 00212 for (int j=0; j<cgeom->getNumPoints(); j++) { 00213 Position2D pos((SUMOReal) cgeom->getX(j), (SUMOReal) cgeom->getY(j)); 00214 if (!GeoConvHelper::x2cartesian(pos)) { 00215 WRITE_WARNING("Unable to project coordinates for edge '" + id + "'."); 00216 } 00217 shape.push_back_noDoublePos(pos); 00218 } 00219 00220 // build from-node 00221 NBNode *from = myNodeCont.retrieve(from_node); 00222 if (from==0) { 00223 Position2D from_pos = shape[0]; 00224 from = myNodeCont.retrieve(from_pos); 00225 if (from==0) { 00226 from = new NBNode(from_node, from_pos); 00227 if (!myNodeCont.insert(from)) { 00228 MsgHandler::getErrorInstance()->inform("Node '" + from_node + "' could not be added"); 00229 delete from; 00230 continue; 00231 } 00232 } 00233 } 00234 // build to-node 00235 NBNode *to = myNodeCont.retrieve(to_node); 00236 if (to==0) { 00237 Position2D to_pos = shape[-1]; 00238 to = myNodeCont.retrieve(to_pos); 00239 if (to==0) { 00240 to = new NBNode(to_node, to_pos); 00241 if (!myNodeCont.insert(to)) { 00242 MsgHandler::getErrorInstance()->inform("Node '" + to_node + "' could not be added"); 00243 delete to; 00244 continue; 00245 } 00246 } 00247 } 00248 00249 if (from==to) { 00250 WRITE_WARNING("Edge '" + id + "' connects identical nodes, skipping."); 00251 continue; 00252 } 00253 00254 // retrieve the information whether the street is bi-directional 00255 std::string dir; 00256 int index = poFeature->GetDefnRef()->GetFieldIndex("DIR_TRAVEL"); 00257 if (index>=0&&poFeature->IsFieldSet(index)) { 00258 dir = poFeature->GetFieldAsString(index); 00259 } 00260 // add positive direction if wanted 00261 if (dir=="B"||dir=="F"||dir==""||myOptions.getBool("arcview.all-bidi")) { 00262 if (myEdgeCont.retrieve(id)==0) { 00263 NBEdge::LaneSpreadFunction spread = 00264 dir=="B"||dir=="FALSE" 00265 ? NBEdge::LANESPREAD_RIGHT 00266 : NBEdge::LANESPREAD_CENTER; 00267 NBEdge *edge = new NBEdge(id, from, to, type, speed, nolanes, 00268 priority, shape, spread); 00269 myEdgeCont.insert(edge); 00270 checkSpread(edge); 00271 } 00272 } 00273 // add negative direction if wanted 00274 if (dir=="B"||dir=="T"||myOptions.getBool("arcview.all-bidi")) { 00275 id = "-" + id; 00276 if (myEdgeCont.retrieve(id)==0) { 00277 NBEdge::LaneSpreadFunction spread = 00278 dir=="B"||dir=="FALSE" 00279 ? NBEdge::LANESPREAD_RIGHT 00280 : NBEdge::LANESPREAD_CENTER; 00281 NBEdge *edge = new NBEdge(id, to, from, type, speed, nolanes, 00282 priority, shape.reverse(), spread); 00283 myEdgeCont.insert(edge); 00284 checkSpread(edge); 00285 } 00286 } 00287 // 00288 OGRFeature::DestroyFeature(poFeature); 00289 } 00290 MsgHandler::getMessageInstance()->endProcessMsg("done."); 00291 #else 00292 MsgHandler::getErrorInstance()->inform("SUMO was compiled without GDAL support."); 00293 #endif 00294 }
| void NIImporter_ArcView::loadNetwork | ( | const OptionsCont & | oc, | |
| NBNetBuilder & | nb | |||
| ) | [static] |
Loads content of the optionally given ArcView Shape files.
If the option "arcview" is set, the file stored therein is read and the network definition stored therein is stored within the given network builder.
If the option "arcview" is not set, this method simply returns.
| [in] | oc | The options to use |
| [in] | nb | The network builder to fill |
Definition at line 65 of file NIImporter_ArcView.cpp.
References FileHelpers::exists(), OptionsCont::getBool(), NBNetBuilder::getEdgeCont(), MsgHandler::getErrorInstance(), NBNetBuilder::getNodeCont(), OptionsCont::getString(), NBNetBuilder::getTypeCont(), MsgHandler::inform(), and OptionsCont::isSet().
Referenced by NILoader::load().
00065 { 00066 if (!oc.isSet("arcview")) { 00067 return; 00068 } 00069 // check whether the correct set of entries is given 00070 // and compute both file names 00071 std::string dbf_file = oc.getString("arcview") + ".dbf"; 00072 std::string shp_file = oc.getString("arcview") + ".shp"; 00073 std::string shx_file = oc.getString("arcview") + ".shx"; 00074 // check whether the files do exist 00075 if (!FileHelpers::exists(dbf_file)) { 00076 MsgHandler::getErrorInstance()->inform("File not found: " + dbf_file); 00077 } 00078 if (!FileHelpers::exists(shp_file)) { 00079 MsgHandler::getErrorInstance()->inform("File not found: " + shp_file); 00080 } 00081 if (!FileHelpers::exists(shx_file)) { 00082 MsgHandler::getErrorInstance()->inform("File not found: " + shx_file); 00083 } 00084 if (MsgHandler::getErrorInstance()->wasInformed()) { 00085 return; 00086 } 00087 // load the arcview files 00088 NIImporter_ArcView loader(oc, 00089 nb.getNodeCont(), nb.getEdgeCont(), nb.getTypeCont(), 00090 dbf_file, shp_file, oc.getBool("speed-in-kmh")); 00091 loader.load(); 00092 }
| NIImporter_ArcView& NIImporter_ArcView::operator= | ( | const NIImporter_ArcView & | ) | [private] |
Invalidated assignment operator.
NBEdgeCont& NIImporter_ArcView::myEdgeCont [private] |
The container to add edges to.
Definition at line 142 of file NIImporter_ArcView.h.
Referenced by load().
int NIImporter_ArcView::myNameAddition [private] |
NBNodeCont& NIImporter_ArcView::myNodeCont [private] |
The container to add nodes to.
Definition at line 139 of file NIImporter_ArcView.h.
Referenced by load().
const OptionsCont& NIImporter_ArcView::myOptions [private] |
int NIImporter_ArcView::myRunningNodeID [private] |
A running number to assure unique node ids.
Definition at line 151 of file NIImporter_ArcView.h.
Referenced by load().
std::string NIImporter_ArcView::mySHPName [private] |
The name of the shape file.
Definition at line 133 of file NIImporter_ArcView.h.
Referenced by load().
bool NIImporter_ArcView::mySpeedInKMH [private] |
Whether the speed is given in km/h.
Definition at line 148 of file NIImporter_ArcView.h.
Referenced by load().
NBTypeCont& NIImporter_ArcView::myTypeCont [private] |
The container to get the types from.
Definition at line 145 of file NIImporter_ArcView.h.
Referenced by load().
1.5.6