Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
NIImporter_ArcView.cpp
Go to the documentation of this file.
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/****************************************************************************/
22// Importer for networks stored in ArcView-shape format
23/****************************************************************************/
24#include <config.h>
25
26#include <string>
34#include <netbuild/NBHelpers.h>
35#include <netbuild/NBEdge.h>
36#include <netbuild/NBEdgeCont.h>
37#include <netbuild/NBTypeCont.h>
38#include <netbuild/NBNode.h>
39#include <netbuild/NBNodeCont.h>
43#include "NILoader.h"
44#include "NIImporter_ArcView.h"
45
46#ifdef HAVE_GDAL
47#ifdef _MSC_VER
48#pragma warning(push)
49#pragma warning(disable: 4435 5219 5220)
50#endif
51#if __GNUC__ > 3
52#pragma GCC diagnostic push
53#pragma GCC diagnostic ignored "-Wpedantic"
54#endif
55#include <ogrsf_frmts.h>
56#if __GNUC__ > 3
57#pragma GCC diagnostic pop
58#endif
59#ifdef _MSC_VER
60#pragma warning(pop)
61#endif
62#endif
63
64
65// ===========================================================================
66// method definitions
67// ===========================================================================
68// ---------------------------------------------------------------------------
69// static methods (interface in this case)
70// ---------------------------------------------------------------------------
71void
73 if (!oc.isSet("shapefile-prefix")) {
74 return;
75 }
76 // check whether the correct set of entries is given
77 // and compute all file names
78 const std::string dbf_file = oc.getString("shapefile-prefix") + ".dbf";
79 const std::string shp_file = oc.getString("shapefile-prefix") + ".shp";
80 const std::string shx_file = oc.getString("shapefile-prefix") + ".shx";
81 if (!StringUtils::startsWith(shp_file, "/vsi")) {
82 // if we are not using a virtual file system, check whether the files do exist
83 if (!FileHelpers::isReadable(dbf_file)) {
84 WRITE_ERROR("File not accessible: " + dbf_file);
85 }
86 if (!FileHelpers::isReadable(shp_file)) {
87 WRITE_ERROR("File not accessible: " + shp_file);
88 }
89 if (!FileHelpers::isReadable(shx_file)) {
90 WRITE_ERROR("File not accessible: " + shx_file);
91 }
92 }
93 if (MsgHandler::getErrorInstance()->wasInformed()) {
94 return;
95 }
96 // load the arcview files
97 NIImporter_ArcView loader(oc, nb.getNodeCont(), nb.getEdgeCont(), nb.getTypeCont(),
98 shp_file, oc.getBool("speed-in-kmh"));
99 loader.load();
100}
101
102
103
104// ---------------------------------------------------------------------------
105// loader methods
106// ---------------------------------------------------------------------------
108 NBNodeCont& nc,
109 NBEdgeCont& ec,
110 NBTypeCont& tc,
111 const std::string& shp_name,
112 bool speedInKMH)
113 : myOptions(oc), mySHPName(shp_name),
114 myNameAddition(0),
115 myNodeCont(nc), myEdgeCont(ec), myTypeCont(tc),
116 mySpeedInKMH(speedInKMH),
117 myRunningEdgeID(0),
118 myRunningNodeID(0) {
119}
120
121
123
124
125void
127#ifdef HAVE_GDAL
128 PROGRESS_BEGIN_MESSAGE("Loading data from '" + mySHPName + "'");
129#if GDAL_VERSION_MAJOR < 2
130 OGRRegisterAll();
131 OGRDataSource* poDS = OGRSFDriverRegistrar::Open(mySHPName.c_str(), FALSE);
132#else
133 GDALAllRegister();
134 GDALDataset* poDS = (GDALDataset*)GDALOpenEx(mySHPName.c_str(), GDAL_OF_VECTOR | GA_ReadOnly, NULL, NULL, NULL);
135#endif
136 if (poDS == NULL) {
137 WRITE_ERRORF(TL("Could not open shape description '%'."), mySHPName);
138 return;
139 }
140
141 // begin file parsing
142 OGRLayer* poLayer = poDS->GetLayer(0);
143 poLayer->ResetReading();
144
145 // build coordinate transformation
146 OGRSpatialReference* origTransf = poLayer->GetSpatialRef();
147 OGRSpatialReference destTransf;
148 // use wgs84 as destination
149 destTransf.SetWellKnownGeogCS("WGS84");
150#if GDAL_VERSION_MAJOR > 2
151 if (myOptions.getBool("shapefile.traditional-axis-mapping") || origTransf != nullptr) {
152 destTransf.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
153 }
154#endif
155 OGRCoordinateTransformation* poCT = origTransf == nullptr ? nullptr : OGRCreateCoordinateTransformation(origTransf, &destTransf);
156 if (poCT == nullptr) {
157 if (myOptions.getBool("shapefile.guess-projection")) {
158 OGRSpatialReference origTransf2;
159 origTransf2.SetWellKnownGeogCS("WGS84");
160 poCT = OGRCreateCoordinateTransformation(&origTransf2, &destTransf);
161 }
162 }
163
164 const bool saveOrigIDs = OptionsCont::getOptions().getBool("output.original-names");
165 OGRFeature* poFeature;
166 poLayer->ResetReading();
167
168 const double nodeJoinDist = myOptions.getFloat("shapefile.node-join-dist");
169 const std::vector<std::string> params = myOptions.getStringVector("shapefile.add-params");
170
171 int featureIndex = 0;
172 bool warnNotUnique = true;
173 bool warnMissingProjection = true;
174 std::string idPrefix = ""; // prefix for non-unique street-id values
175 std::map<std::string, int> idIndex; // running index to make street-id unique
176 while ((poFeature = poLayer->GetNextFeature()) != NULL) {
177 // read in edge attributes
178 if (featureIndex == 0) {
179 WRITE_MESSAGE("Available fields: " + toString(getFieldNames(poFeature)));
180 }
181 std::string id;
182 std::string name;
183 std::string from_node;
184 std::string to_node;
185 if (!getStringEntry(poFeature, "shapefile.street-id", "LINK_ID", true, id)) {
186 WRITE_ERRORF(TL("Needed field '%' (street-id) is missing."), id);
187 id = "";
188 }
189 if (id == "") {
191 }
192
193 getStringEntry(poFeature, "shapefile.name", "ST_NAME", true, name);
194 name = StringUtils::replace(name, "&", "&amp;");
195
196 if (!getStringEntry(poFeature, "shapefile.from-id", "REF_IN_ID", true, from_node)) {
197 WRITE_ERRORF(TL("Needed field '%' (from node id) is missing."), from_node);
198 from_node = "";
199 }
200 if (!getStringEntry(poFeature, "shapefile.to-id", "NREF_IN_ID", true, to_node)) {
201 WRITE_ERRORF(TL("Needed field '%' (to node id) is missing."), to_node);
202 to_node = "";
203 }
204
205 if (from_node == "" || to_node == "") {
206 from_node = toString(myRunningNodeID++);
207 to_node = toString(myRunningNodeID++);
208 }
209
210 std::string type;
211 if (myOptions.isSet("shapefile.type-id") && poFeature->GetFieldIndex(myOptions.getString("shapefile.type-id").c_str()) >= 0) {
212 type = poFeature->GetFieldAsString(myOptions.getString("shapefile.type-id").c_str());
213 } else if (poFeature->GetFieldIndex("ST_TYP_AFT") >= 0) {
214 type = poFeature->GetFieldAsString("ST_TYP_AFT");
215 }
216 if ((type != "" || myOptions.isSet("shapefile.type-id")) && !myTypeCont.knows(type)) {
217 WRITE_WARNINGF(TL("Unknown type '%' for edge '%'"), type, id);
218 }
219 bool oneway = myTypeCont.knows(type) ? myTypeCont.getEdgeTypeIsOneWay(type) : false;
220 double speed = getSpeed(*poFeature, id);
221 int nolanes = getLaneNo(*poFeature, id, speed);
222 int priority = getPriority(*poFeature, id);
223 double width = getLaneWidth(*poFeature, id, nolanes);
224 double length = getLength(*poFeature, id);
225 if (nolanes <= 0 || speed <= 0) {
226 if (myOptions.getBool("shapefile.use-defaults-on-failure")) {
227 nolanes = nolanes <= 0 ? myTypeCont.getEdgeTypeNumLanes(type) : nolanes;
228 speed = speed <= 0 ? myTypeCont.getEdgeTypeSpeed(type) : speed;
229 } else {
230 const std::string lanesField = myOptions.isSet("shapefile.laneNumber") ? myOptions.getString("shapefile.laneNumber") : "nolanes";
231 const std::string speedField = myOptions.isSet("shapefile.speed") ? myOptions.getString("shapefile.speed") : "speed";
232 WRITE_ERRORF(TL("Required field '%' or '%' is missing (add fields or set option --shapefile.use-defaults-on-failure)."), lanesField, speedField);
233 WRITE_ERROR("Available fields: " + toString(getFieldNames(poFeature)));
234 OGRFeature::DestroyFeature(poFeature);
235 return;
236 }
237 }
238 if (mySpeedInKMH) {
239 speed /= 3.6;
240 }
241
242
243 // read in the geometry
244 OGRGeometry* poGeometry = poFeature->GetGeometryRef();
245 OGRwkbGeometryType gtype = poGeometry->getGeometryType();
246 if (gtype != wkbLineString && gtype != wkbLineString25D) {
247 OGRFeature::DestroyFeature(poFeature);
248 WRITE_ERRORF(TL("Road geometry must be of type 'linestring' or 'linestring25D' (found '%')"), toString(gtype));
249 return;
250 }
251 OGRLineString* cgeom = (OGRLineString*) poGeometry;
252 if (poCT == nullptr && warnMissingProjection) {
253 int outOfRange = 0;
254 for (int j = 0; j < cgeom->getNumPoints(); j++) {
255 if (fabs(cgeom->getX(j)) > 180 || fabs(cgeom->getY(j)) > 90) {
256 outOfRange++;
257 }
258 }
259 if (2 * outOfRange > cgeom->getNumPoints()) {
260 WRITE_WARNING(TL("No coordinate system found and coordinates look already projected."));
261 GeoConvHelper::init("!", GeoConvHelper::getProcessing().getOffset(), GeoConvHelper::getProcessing().getOrigBoundary(), GeoConvHelper::getProcessing().getConvBoundary());
262 } else {
263 WRITE_WARNING(TL("Could not find geo coordinate system, assuming WGS84."));
264 }
265 warnMissingProjection = false;
266 }
267 if (poCT != nullptr) {
268 // try transform to wgs84
269 cgeom->transform(poCT);
270 }
271
272 PositionVector shape;
273 for (int j = 0; j < cgeom->getNumPoints(); j++) {
274 Position pos(cgeom->getX(j), cgeom->getY(j), cgeom->getZ(j));
276 WRITE_WARNINGF(TL("Unable to project coordinates for edge '%'."), id);
277 }
278 shape.push_back_noDoublePos(pos);
279 }
280
281 // build from-node
282 NBNode* from = myNodeCont.retrieve(from_node);
283 if (from == nullptr) {
284 Position from_pos = shape[0];
285 from = myNodeCont.retrieve(from_pos, nodeJoinDist);
286 if (from == nullptr) {
287 from = new NBNode(from_node, from_pos);
288 if (!myNodeCont.insert(from)) {
289 WRITE_ERRORF(TL("Node '%' could not be added"), from_node);
290 delete from;
291 continue;
292 }
293 }
294 }
295 // build to-node
296 NBNode* to = myNodeCont.retrieve(to_node);
297 if (to == nullptr) {
298 Position to_pos = shape[-1];
299 to = myNodeCont.retrieve(to_pos, nodeJoinDist);
300 if (to == nullptr) {
301 to = new NBNode(to_node, to_pos);
302 if (!myNodeCont.insert(to)) {
303 WRITE_ERRORF(TL("Node '%' could not be added"), to_node);
304 delete to;
305 continue;
306 }
307 }
308 }
309
310 if (from == to) {
311 WRITE_WARNINGF(TL("Edge '%' connects identical nodes, skipping."), id);
312 continue;
313 }
314
315 // retrieve the information whether the street is bi-directional
316 std::string dir;
317 int index = poFeature->GetDefnRef()->GetFieldIndex("DIR_TRAVEL");
318 if (index >= 0 && poFeature->IsFieldSet(index)) {
319 dir = poFeature->GetFieldAsString(index);
320 }
321 const std::string origID = saveOrigIDs ? id : "";
322 // check for duplicate ids
323 NBEdge* const existing = myEdgeCont.retrieve(id);
324 NBEdge* const existingReverse = myEdgeCont.retrieve("-" + id);
325 if (existing != nullptr || existingReverse != nullptr) {
326 if ((existing != nullptr && existing->getGeometry() == shape)
327 || (existingReverse != nullptr && existingReverse->getGeometry() == shape.reverse())) {
328 WRITE_ERRORF(TL("Edge '%' is not unique."), (existing != nullptr ? id : existingReverse->getID()));
329 } else {
330 if (idIndex.count(id) == 0) {
331 idIndex[id] = 0;
332 }
333 idIndex[id]++;
334 idPrefix = id;
335 id += "#" + toString(idIndex[id]);
336 if (warnNotUnique) {
337 WRITE_WARNINGF(TL("Edge '%' is not unique. Renaming subsequent edge to '%'."), idPrefix, id);
338 warnNotUnique = false;
339 }
340 }
341 }
342 // add positive direction if wanted
343 if (dir == "B" || dir == "F" || dir == "" || myOptions.getBool("shapefile.all-bidirectional")) {
344 if (myEdgeCont.retrieve(id) == 0) {
345 LaneSpreadFunction spread = dir == "B" || dir == "FALSE" ? LaneSpreadFunction::RIGHT : LaneSpreadFunction::CENTER;
346 if (spread == LaneSpreadFunction::RIGHT && OptionsCont::getOptions().getString("default.spreadtype") == toString(LaneSpreadFunction::ROADCENTER)) {
348 }
349 NBEdge* edge = new NBEdge(id, from, to, type, speed, NBEdge::UNSPECIFIED_FRICTION, nolanes, priority, width, NBEdge::UNSPECIFIED_OFFSET, shape, spread, name, origID);
351 edge->setLoadedLength(length);
352 myEdgeCont.insert(edge);
353 checkSpread(edge);
354 addParams(edge, poFeature, params);
355 } else {
356 WRITE_ERRORF(TL("Could not create edge '%'. An edge with the same id already exists."), id);
357 }
358 }
359 // add negative direction if wanted
360 if ((dir == "B" || dir == "T" || myOptions.getBool("shapefile.all-bidirectional")) && !oneway) {
361 if (myEdgeCont.retrieve("-" + id) == 0) {
362 LaneSpreadFunction spread = dir == "B" || dir == "FALSE" ? LaneSpreadFunction::RIGHT : LaneSpreadFunction::CENTER;
363 if (spread == LaneSpreadFunction::RIGHT && OptionsCont::getOptions().getString("default.spreadtype") == toString(LaneSpreadFunction::ROADCENTER)) {
365 }
366 NBEdge* edge = new NBEdge("-" + id, to, from, type, speed, NBEdge::UNSPECIFIED_FRICTION, nolanes, priority, width, NBEdge::UNSPECIFIED_OFFSET, shape.reverse(), spread, name, origID);
368 edge->setLoadedLength(length);
369 myEdgeCont.insert(edge);
370 checkSpread(edge);
371 addParams(edge, poFeature, params);
372 } else {
373 WRITE_ERRORF(TL("Could not create edge '-%'. An edge with the same id already exists."), id);
374 }
375 }
376 //
377 OGRFeature::DestroyFeature(poFeature);
378 featureIndex++;
379 }
380#if GDAL_VERSION_MAJOR < 2
381 OGRDataSource::DestroyDataSource(poDS);
382#else
383 GDALClose(poDS);
384#endif
386#else
387 WRITE_ERROR(TL("SUMO was compiled without GDAL support."));
388#endif
389}
390
391#ifdef HAVE_GDAL
392double
393NIImporter_ArcView::getSpeed(OGRFeature& poFeature, const std::string& edgeid) {
394 if (myOptions.isSet("shapefile.speed")) {
395 int index = poFeature.GetDefnRef()->GetFieldIndex(myOptions.getString("shapefile.speed").c_str());
396 if (index >= 0 && poFeature.IsFieldSet(index)) {
397 const double speed = poFeature.GetFieldAsDouble(index);
398 if (speed <= 0) {
399 WRITE_WARNING("invalid value for field: '"
400 + myOptions.getString("shapefile.speed")
401 + "': '" + std::string(poFeature.GetFieldAsString(index)) + "'");
402 } else {
403 return speed;
404 }
405 }
406 }
407 if (myOptions.isSet("shapefile.type-id")) {
408 return myTypeCont.getEdgeTypeSpeed(poFeature.GetFieldAsString((char*)(myOptions.getString("shapefile.type-id").c_str())));
409 }
410 // try to get definitions as to be found in SUMO-XML-definitions
411 // idea by John Michael Calandrino
412 int index = poFeature.GetDefnRef()->GetFieldIndex("speed");
413 if (index >= 0 && poFeature.IsFieldSet(index)) {
414 return (double) poFeature.GetFieldAsDouble(index);
415 }
416 index = poFeature.GetDefnRef()->GetFieldIndex("SPEED");
417 if (index >= 0 && poFeature.IsFieldSet(index)) {
418 return (double) poFeature.GetFieldAsDouble(index);
419 }
420 // try to get the NavTech-information
421 index = poFeature.GetDefnRef()->GetFieldIndex("SPEED_CAT");
422 if (index >= 0 && poFeature.IsFieldSet(index)) {
423 std::string def = poFeature.GetFieldAsString(index);
424 return NINavTeqHelper::getSpeed(edgeid, def);
425 }
426 return -1;
427}
428
429
430double
431NIImporter_ArcView::getLaneWidth(OGRFeature& poFeature, const std::string& edgeid, int laneNumber) {
432 if (myOptions.isSet("shapefile.width")) {
433 int index = poFeature.GetDefnRef()->GetFieldIndex(myOptions.getString("shapefile.width").c_str());
434 if (index >= 0 && poFeature.IsFieldSet(index)) {
435 const double width = poFeature.GetFieldAsDouble(index);
436 if (width <= 0) {
437 WRITE_WARNING("invalid value for field: '"
438 + myOptions.getString("shapefile.width")
439 + "' of edge '" + edgeid
440 + "': '" + std::string(poFeature.GetFieldAsString(index)) + "'");
441 } else {
442 return width / laneNumber;
443 }
444 }
445 }
446 if (myOptions.isSet("shapefile.type-id")) {
447 return myTypeCont.getEdgeTypeWidth(poFeature.GetFieldAsString((char*)(myOptions.getString("shapefile.type-id").c_str())));
448 }
450}
451
452
453
454double
455NIImporter_ArcView::getLength(OGRFeature& poFeature, const std::string& edgeid) {
456 if (myOptions.isSet("shapefile.length")) {
457 int index = poFeature.GetDefnRef()->GetFieldIndex(myOptions.getString("shapefile.length").c_str());
458 if (index >= 0 && poFeature.IsFieldSet(index)) {
459 const double length = poFeature.GetFieldAsDouble(index);
460 if (length <= 0) {
461 WRITE_WARNING("invalid value for field: '"
462 + myOptions.getString("shapefile.length")
463 + "' of edge '" + edgeid
464 + "': '" + std::string(poFeature.GetFieldAsString(index)) + "'");
465 } else {
466 return length;
467 }
468 }
469 }
471}
472
473
474int
475NIImporter_ArcView::getLaneNo(OGRFeature& poFeature, const std::string& edgeid,
476 double speed) {
477 if (myOptions.isSet("shapefile.laneNumber")) {
478 int index = poFeature.GetDefnRef()->GetFieldIndex(myOptions.getString("shapefile.laneNumber").c_str());
479 if (index >= 0 && poFeature.IsFieldSet(index)) {
480 const int laneNumber = poFeature.GetFieldAsInteger(index);
481 if (laneNumber <= 0) {
482 WRITE_WARNING("invalid value for field '"
483 + myOptions.getString("shapefile.laneNumber")
484 + "': '" + std::string(poFeature.GetFieldAsString(index)) + "'");
485 } else {
486 return laneNumber;
487 }
488 }
489 }
490 if (myOptions.isSet("shapefile.type-id")) {
491 return (int) myTypeCont.getEdgeTypeNumLanes(poFeature.GetFieldAsString((char*)(myOptions.getString("shapefile.type-id").c_str())));
492 }
493 // try to get definitions as to be found in SUMO-XML-definitions
494 // idea by John Michael Calandrino
495 int index = poFeature.GetDefnRef()->GetFieldIndex("nolanes");
496 if (index >= 0 && poFeature.IsFieldSet(index)) {
497 return (int) poFeature.GetFieldAsInteger(index);
498 }
499 index = poFeature.GetDefnRef()->GetFieldIndex("NOLANES");
500 if (index >= 0 && poFeature.IsFieldSet(index)) {
501 return (int) poFeature.GetFieldAsInteger(index);
502 }
503 index = poFeature.GetDefnRef()->GetFieldIndex("rnol");
504 if (index >= 0 && poFeature.IsFieldSet(index)) {
505 return (int) poFeature.GetFieldAsInteger(index);
506 }
507 index = poFeature.GetDefnRef()->GetFieldIndex("LANE_CAT");
508 if (index >= 0 && poFeature.IsFieldSet(index)) {
509 std::string def = poFeature.GetFieldAsString(index);
510 return NINavTeqHelper::getLaneNumber(edgeid, def, speed);
511 }
512 return 0;
513}
514
515
516int
517NIImporter_ArcView::getPriority(OGRFeature& poFeature, const std::string& /*edgeid*/) {
518 if (myOptions.isSet("shapefile.type-id")) {
519 return myTypeCont.getEdgeTypePriority(poFeature.GetFieldAsString((char*)(myOptions.getString("shapefile.type-id").c_str())));
520 }
521 // try to get definitions as to be found in SUMO-XML-definitions
522 // idea by John Michael Calandrino
523 int index = poFeature.GetDefnRef()->GetFieldIndex("priority");
524 if (index >= 0 && poFeature.IsFieldSet(index)) {
525 return poFeature.GetFieldAsInteger(index);
526 }
527 index = poFeature.GetDefnRef()->GetFieldIndex("PRIORITY");
528 if (index >= 0 && poFeature.IsFieldSet(index)) {
529 return poFeature.GetFieldAsInteger(index);
530 }
531 // try to determine priority from NavTechs FUNC_CLASS attribute
532 index = poFeature.GetDefnRef()->GetFieldIndex("FUNC_CLASS");
533 if (index >= 0 && poFeature.IsFieldSet(index)) {
534 return poFeature.GetFieldAsInteger(index);
535 }
536 return 0;
537}
538
539void
540NIImporter_ArcView::checkSpread(NBEdge* e) {
541 NBEdge* ret = e->getToNode()->getConnectionTo(e->getFromNode());
542 if (ret != 0) {
545 }
546}
547
548bool
549NIImporter_ArcView::getStringEntry(OGRFeature* poFeature, const std::string& optionName, const char* defaultName, bool prune, std::string& into) {
550 std::string v(defaultName);
551 if (myOptions.isSet(optionName)) {
552 v = myOptions.getString(optionName);
553 }
554 if (poFeature->GetFieldIndex(v.c_str()) < 0) {
555 if (myOptions.isSet(optionName)) {
556 into = v;
557 return false;
558 }
559 into = "";
560 return true;
561 }
562 into = poFeature->GetFieldAsString((char*)v.c_str());
563 if (prune) {
564 into = StringUtils::prune(into);
565 }
566 return true;
567}
568
569std::vector<std::string>
570NIImporter_ArcView::getFieldNames(OGRFeature* poFeature) const {
571 std::vector<std::string> fields;
572 for (int i = 0; i < poFeature->GetFieldCount(); i++) {
573 fields.push_back(poFeature->GetFieldDefnRef(i)->GetNameRef());
574 }
575 return fields;
576}
577
578void
579NIImporter_ArcView::addParams(NBEdge* edge, OGRFeature* poFeature, const std::vector<std::string>& params) const {
580 for (const std::string& p : params) {
581 int index = poFeature->GetDefnRef()->GetFieldIndex(p.c_str());
582 if (index >= 0 && poFeature->IsFieldSet(index)) {
583 edge->setParameter(p, poFeature->GetFieldAsString(index));
584 }
585 }
586}
587
588#endif
589
590
591/****************************************************************************/
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:296
#define WRITE_ERRORF(...)
Definition MsgHandler.h:305
#define WRITE_MESSAGE(msg)
Definition MsgHandler.h:297
#define WRITE_ERROR(msg)
Definition MsgHandler.h:304
#define WRITE_WARNING(msg)
Definition MsgHandler.h:295
#define TL(string)
Definition MsgHandler.h:315
#define PROGRESS_DONE_MESSAGE()
Definition MsgHandler.h:300
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition MsgHandler.h:299
LaneSpreadFunction
Numbers representing special SUMO-XML-attribute values Information how the edge's lateral offset shal...
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
static bool isReadable(std::string path)
Checks whether the given file is readable.
static GeoConvHelper & getProcessing()
the coordinate transformation to use for input conversion and processing
static bool init(OptionsCont &oc)
Initialises the processing and the final instance using the given options.
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Storage for edges, including some functionality operating on multiple edges.
Definition NBEdgeCont.h:59
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
bool insert(NBEdge *edge, bool ignorePrunning=false)
Adds an edge to the dictionary.
The representation of a single edge during network building.
Definition NBEdge.h:92
void setPermissions(SVCPermissions permissions, int lane=-1)
set allowed/disallowed classes for the given lane or for all lanes if -1 is given
Definition NBEdge.cpp:4342
NBNode * getToNode() const
Returns the destination node of the edge.
Definition NBEdge.h:546
static const double UNSPECIFIED_FRICTION
unspecified lane friction
Definition NBEdge.h:355
const PositionVector & getGeometry() const
Returns the geometry of the edge.
Definition NBEdge.h:783
const std::string & getID() const
Definition NBEdge.h:1528
static const double UNSPECIFIED_LOADED_LENGTH
no length override given
Definition NBEdge.h:364
void setLaneSpreadFunction(LaneSpreadFunction spread)
(Re)sets how the lanes lateral offset shall be computed
Definition NBEdge.cpp:992
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition NBEdge.h:539
static const double UNSPECIFIED_WIDTH
unspecified lane width
Definition NBEdge.h:346
static const double UNSPECIFIED_OFFSET
unspecified lane offset
Definition NBEdge.h:349
void setLoadedLength(double val)
set loaded length
Definition NBEdge.cpp:4394
Instance responsible for building networks.
NBNodeCont & getNodeCont()
Returns a reference to the node container.
NBEdgeCont & getEdgeCont()
NBTypeCont & getTypeCont()
Returns a reference to the type container.
static bool transformCoordinate(Position &from, bool includeInBoundary=true, GeoConvHelper *from_srs=nullptr)
transforms loaded coordinates handles projections, offsets (using GeoConvHelper) and import of height...
Container for nodes during the netbuilding process.
Definition NBNodeCont.h:57
bool insert(const std::string &id, const Position &position, NBDistrict *district=0)
Inserts a node into the map.
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Represents a single node (junction) during network building.
Definition NBNode.h:66
NBEdge * getConnectionTo(NBNode *n) const
get connection to certain node
Definition NBNode.cpp:2685
A storage for available edgeTypes of edges.
Definition NBTypeCont.h:52
double getEdgeTypeSpeed(const std::string &edgeType) const
Returns the maximal velocity for the given edgeType [m/s].
int getEdgeTypePriority(const std::string &edgeType) const
Returns the priority for the given edgeType.
int getEdgeTypeNumLanes(const std::string &edgeType) const
Returns the number of lanes for the given edgeType.
double getEdgeTypeWidth(const std::string &edgeType) const
Returns the lane width for the given edgeType [m].
SVCPermissions getEdgeTypePermissions(const std::string &edgeType) const
Returns allowed vehicle classes for the given edgeType.
bool knows(const std::string &edgeType) const
Returns whether the named edgeType is in the container.
bool getEdgeTypeIsOneWay(const std::string &edgeType) const
Returns whether edges are one-way per default for the given edgeType.
Importer for networks stored in ArcView-shape format.
const OptionsCont & myOptions
The options to use.
void load()
Loads the shape files.
int myRunningEdgeID
A running number to assure unique ids (as fallback)
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given ArcView Shape files.
std::string mySHPName
The name of the shape file.
NBTypeCont & myTypeCont
The container to get the types from.
NBNodeCont & myNodeCont
The container to add nodes to.
bool mySpeedInKMH
Whether the speed is given in km/h.
NBEdgeCont & myEdgeCont
The container to add edges to.
NIImporter_ArcView(const OptionsCont &oc, NBNodeCont &nc, NBEdgeCont &ec, NBTypeCont &tc, const std::string &shp_name, bool speedInKMH)
Constructor.
static int getLaneNumber(const std::string &id, const std::string &laneNoS, double speed)
Returns the lane number evaluating the given Navteq-description.
static double getSpeed(const std::string &id, const std::string &speedClassS)
Returns the speed evaluating the given Navteq-description.
A storage for options typed value containers)
Definition OptionsCont.h:89
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
static OptionsCont & getOptions()
Retrieves the options.
virtual void setParameter(const std::string &key, const std::string &value)
Sets a parameter.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.
void push_back_noDoublePos(const Position &p)
insert in back a non double position
PositionVector reverse() const
reverse position vector
static std::string replace(std::string str, const std::string &what, const std::string &by)
Replaces all occurrences of the second string by the third string within the first string.
static std::string prune(const std::string &str)
Removes trailing and leading whitechars.
static bool startsWith(const std::string &str, const std::string prefix)
Checks whether a given string starts with the prefix.