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-2025 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 std::vector<NBNode*> cands = myNodeCont.retrieveByPos(from_pos, nodeJoinDist);
286 if (!cands.empty()) {
287 from = cands.front();
288 }
289 if (from == nullptr) {
290 from = new NBNode(from_node, from_pos);
291 if (!myNodeCont.insert(from)) {
292 WRITE_ERRORF(TL("Node '%' could not be added"), from_node);
293 delete from;
294 continue;
295 }
296 }
297 }
298 // build to-node
299 NBNode* to = myNodeCont.retrieve(to_node);
300 if (to == nullptr) {
301 Position to_pos = shape[-1];
302 std::vector<NBNode*> cands = myNodeCont.retrieveByPos(to_pos, nodeJoinDist);
303 if (!cands.empty()) {
304 to = cands.front();
305 }
306 if (to == nullptr) {
307 to = new NBNode(to_node, to_pos);
308 if (!myNodeCont.insert(to)) {
309 WRITE_ERRORF(TL("Node '%' could not be added"), to_node);
310 delete to;
311 continue;
312 }
313 }
314 }
315
316 if (from == to) {
317 WRITE_WARNINGF(TL("Edge '%' connects identical nodes, skipping."), id);
318 continue;
319 }
320
321 // retrieve the information whether the street is bi-directional
322 std::string dir;
323 int index = poFeature->GetDefnRef()->GetFieldIndex("DIR_TRAVEL");
324 if (index >= 0 && poFeature->IsFieldSet(index)) {
325 dir = poFeature->GetFieldAsString(index);
326 }
327 const std::string origID = saveOrigIDs ? id : "";
328 // check for duplicate ids
329 NBEdge* const existing = myEdgeCont.retrieve(id);
330 NBEdge* const existingReverse = myEdgeCont.retrieve("-" + id);
331 if (existing != nullptr || existingReverse != nullptr) {
332 if ((existing != nullptr && existing->getGeometry() == shape)
333 || (existingReverse != nullptr && existingReverse->getGeometry() == shape.reverse())) {
334 WRITE_ERRORF(TL("Edge '%' is not unique."), (existing != nullptr ? id : existingReverse->getID()));
335 } else {
336 if (idIndex.count(id) == 0) {
337 idIndex[id] = 0;
338 }
339 idIndex[id]++;
340 idPrefix = id;
341 id += "#" + toString(idIndex[id]);
342 if (warnNotUnique) {
343 WRITE_WARNINGF(TL("Edge '%' is not unique. Renaming subsequent edge to '%'."), idPrefix, id);
344 warnNotUnique = false;
345 }
346 }
347 }
348 // add positive direction if wanted
349 if (dir == "B" || dir == "F" || dir == "" || myOptions.getBool("shapefile.all-bidirectional")) {
350 if (myEdgeCont.retrieve(id) == 0) {
351 LaneSpreadFunction spread = dir == "B" || dir == "FALSE" ? LaneSpreadFunction::RIGHT : LaneSpreadFunction::CENTER;
352 if (spread == LaneSpreadFunction::RIGHT && OptionsCont::getOptions().getString("default.spreadtype") == toString(LaneSpreadFunction::ROADCENTER)) {
354 }
355 NBEdge* edge = new NBEdge(id, from, to, type, speed, NBEdge::UNSPECIFIED_FRICTION, nolanes, priority, width, NBEdge::UNSPECIFIED_OFFSET, shape, spread, name, origID);
357 edge->setLoadedLength(length);
358 myEdgeCont.insert(edge);
359 checkSpread(edge);
360 addParams(edge, poFeature, params);
361 } else {
362 WRITE_ERRORF(TL("Could not create edge '%'. An edge with the same id already exists."), id);
363 }
364 }
365 // add negative direction if wanted
366 if ((dir == "B" || dir == "T" || myOptions.getBool("shapefile.all-bidirectional")) && !oneway) {
367 if (myEdgeCont.retrieve("-" + id) == 0) {
368 LaneSpreadFunction spread = dir == "B" || dir == "FALSE" ? LaneSpreadFunction::RIGHT : LaneSpreadFunction::CENTER;
369 if (spread == LaneSpreadFunction::RIGHT && OptionsCont::getOptions().getString("default.spreadtype") == toString(LaneSpreadFunction::ROADCENTER)) {
371 }
372 NBEdge* edge = new NBEdge("-" + id, to, from, type, speed, NBEdge::UNSPECIFIED_FRICTION, nolanes, priority, width, NBEdge::UNSPECIFIED_OFFSET, shape.reverse(), spread, name, origID);
374 edge->setLoadedLength(length);
375 myEdgeCont.insert(edge);
376 checkSpread(edge);
377 addParams(edge, poFeature, params);
378 } else {
379 WRITE_ERRORF(TL("Could not create edge '-%'. An edge with the same id already exists."), id);
380 }
381 }
382 //
383 OGRFeature::DestroyFeature(poFeature);
384 featureIndex++;
385 }
386#if GDAL_VERSION_MAJOR < 2
387 OGRDataSource::DestroyDataSource(poDS);
388#else
389 GDALClose(poDS);
390#endif
392#else
393 WRITE_ERROR(TL("SUMO was compiled without GDAL support."));
394#endif
395}
396
397#ifdef HAVE_GDAL
398double
399NIImporter_ArcView::getSpeed(OGRFeature& poFeature, const std::string& edgeid) {
400 if (myOptions.isSet("shapefile.speed")) {
401 int index = poFeature.GetDefnRef()->GetFieldIndex(myOptions.getString("shapefile.speed").c_str());
402 if (index >= 0 && poFeature.IsFieldSet(index)) {
403 const double speed = poFeature.GetFieldAsDouble(index);
404 if (speed <= 0) {
405 WRITE_WARNING("invalid value for field: '"
406 + myOptions.getString("shapefile.speed")
407 + "': '" + std::string(poFeature.GetFieldAsString(index)) + "'");
408 } else {
409 return speed;
410 }
411 }
412 }
413 if (myOptions.isSet("shapefile.type-id")) {
414 return myTypeCont.getEdgeTypeSpeed(poFeature.GetFieldAsString((char*)(myOptions.getString("shapefile.type-id").c_str())));
415 }
416 // try to get definitions as to be found in SUMO-XML-definitions
417 // idea by John Michael Calandrino
418 int index = poFeature.GetDefnRef()->GetFieldIndex("speed");
419 if (index >= 0 && poFeature.IsFieldSet(index)) {
420 return (double) poFeature.GetFieldAsDouble(index);
421 }
422 index = poFeature.GetDefnRef()->GetFieldIndex("SPEED");
423 if (index >= 0 && poFeature.IsFieldSet(index)) {
424 return (double) poFeature.GetFieldAsDouble(index);
425 }
426 // try to get the NavTech-information
427 index = poFeature.GetDefnRef()->GetFieldIndex("SPEED_CAT");
428 if (index >= 0 && poFeature.IsFieldSet(index)) {
429 std::string def = poFeature.GetFieldAsString(index);
430 return NINavTeqHelper::getSpeed(edgeid, def);
431 }
432 return -1;
433}
434
435
436double
437NIImporter_ArcView::getLaneWidth(OGRFeature& poFeature, const std::string& edgeid, int laneNumber) {
438 if (myOptions.isSet("shapefile.width")) {
439 int index = poFeature.GetDefnRef()->GetFieldIndex(myOptions.getString("shapefile.width").c_str());
440 if (index >= 0 && poFeature.IsFieldSet(index)) {
441 const double width = poFeature.GetFieldAsDouble(index);
442 if (width <= 0) {
443 WRITE_WARNING("invalid value for field: '"
444 + myOptions.getString("shapefile.width")
445 + "' of edge '" + edgeid
446 + "': '" + std::string(poFeature.GetFieldAsString(index)) + "'");
447 } else {
448 return width / laneNumber;
449 }
450 }
451 }
452 if (myOptions.isSet("shapefile.type-id")) {
453 return myTypeCont.getEdgeTypeWidth(poFeature.GetFieldAsString((char*)(myOptions.getString("shapefile.type-id").c_str())));
454 }
456}
457
458
459
460double
461NIImporter_ArcView::getLength(OGRFeature& poFeature, const std::string& edgeid) {
462 if (myOptions.isSet("shapefile.length")) {
463 int index = poFeature.GetDefnRef()->GetFieldIndex(myOptions.getString("shapefile.length").c_str());
464 if (index >= 0 && poFeature.IsFieldSet(index)) {
465 const double length = poFeature.GetFieldAsDouble(index);
466 if (length <= 0) {
467 WRITE_WARNING("invalid value for field: '"
468 + myOptions.getString("shapefile.length")
469 + "' of edge '" + edgeid
470 + "': '" + std::string(poFeature.GetFieldAsString(index)) + "'");
471 } else {
472 return length;
473 }
474 }
475 }
477}
478
479
480int
481NIImporter_ArcView::getLaneNo(OGRFeature& poFeature, const std::string& edgeid,
482 double speed) {
483 if (myOptions.isSet("shapefile.laneNumber")) {
484 int index = poFeature.GetDefnRef()->GetFieldIndex(myOptions.getString("shapefile.laneNumber").c_str());
485 if (index >= 0 && poFeature.IsFieldSet(index)) {
486 const int laneNumber = poFeature.GetFieldAsInteger(index);
487 if (laneNumber <= 0) {
488 WRITE_WARNING("invalid value for field '"
489 + myOptions.getString("shapefile.laneNumber")
490 + "': '" + std::string(poFeature.GetFieldAsString(index)) + "'");
491 } else {
492 return laneNumber;
493 }
494 }
495 }
496 if (myOptions.isSet("shapefile.type-id")) {
497 return (int) myTypeCont.getEdgeTypeNumLanes(poFeature.GetFieldAsString((char*)(myOptions.getString("shapefile.type-id").c_str())));
498 }
499 // try to get definitions as to be found in SUMO-XML-definitions
500 // idea by John Michael Calandrino
501 int index = poFeature.GetDefnRef()->GetFieldIndex("nolanes");
502 if (index >= 0 && poFeature.IsFieldSet(index)) {
503 return (int) poFeature.GetFieldAsInteger(index);
504 }
505 index = poFeature.GetDefnRef()->GetFieldIndex("NOLANES");
506 if (index >= 0 && poFeature.IsFieldSet(index)) {
507 return (int) poFeature.GetFieldAsInteger(index);
508 }
509 index = poFeature.GetDefnRef()->GetFieldIndex("rnol");
510 if (index >= 0 && poFeature.IsFieldSet(index)) {
511 return (int) poFeature.GetFieldAsInteger(index);
512 }
513 index = poFeature.GetDefnRef()->GetFieldIndex("LANE_CAT");
514 if (index >= 0 && poFeature.IsFieldSet(index)) {
515 std::string def = poFeature.GetFieldAsString(index);
516 return NINavTeqHelper::getLaneNumber(edgeid, def, speed);
517 }
518 return 0;
519}
520
521
522int
523NIImporter_ArcView::getPriority(OGRFeature& poFeature, const std::string& /*edgeid*/) {
524 if (myOptions.isSet("shapefile.type-id")) {
525 return myTypeCont.getEdgeTypePriority(poFeature.GetFieldAsString((char*)(myOptions.getString("shapefile.type-id").c_str())));
526 }
527 // try to get definitions as to be found in SUMO-XML-definitions
528 // idea by John Michael Calandrino
529 int index = poFeature.GetDefnRef()->GetFieldIndex("priority");
530 if (index >= 0 && poFeature.IsFieldSet(index)) {
531 return poFeature.GetFieldAsInteger(index);
532 }
533 index = poFeature.GetDefnRef()->GetFieldIndex("PRIORITY");
534 if (index >= 0 && poFeature.IsFieldSet(index)) {
535 return poFeature.GetFieldAsInteger(index);
536 }
537 // try to determine priority from NavTechs FUNC_CLASS attribute
538 index = poFeature.GetDefnRef()->GetFieldIndex("FUNC_CLASS");
539 if (index >= 0 && poFeature.IsFieldSet(index)) {
540 return poFeature.GetFieldAsInteger(index);
541 }
542 return 0;
543}
544
545void
546NIImporter_ArcView::checkSpread(NBEdge* e) {
547 NBEdge* ret = e->getToNode()->getConnectionTo(e->getFromNode());
548 if (ret != 0) {
551 }
552}
553
554bool
555NIImporter_ArcView::getStringEntry(OGRFeature* poFeature, const std::string& optionName, const char* defaultName, bool prune, std::string& into) {
556 std::string v(defaultName);
557 if (myOptions.isSet(optionName)) {
558 v = myOptions.getString(optionName);
559 }
560 if (poFeature->GetFieldIndex(v.c_str()) < 0) {
561 if (myOptions.isSet(optionName)) {
562 into = v;
563 return false;
564 }
565 into = "";
566 return true;
567 }
568 into = poFeature->GetFieldAsString((char*)v.c_str());
569 if (prune) {
570 into = StringUtils::prune(into);
571 }
572 return true;
573}
574
575std::vector<std::string>
576NIImporter_ArcView::getFieldNames(OGRFeature* poFeature) const {
577 std::vector<std::string> fields;
578 for (int i = 0; i < poFeature->GetFieldCount(); i++) {
579 fields.push_back(poFeature->GetFieldDefnRef(i)->GetNameRef());
580 }
581 return fields;
582}
583
584void
585NIImporter_ArcView::addParams(NBEdge* edge, OGRFeature* poFeature, const std::vector<std::string>& params) const {
586 for (const std::string& p : params) {
587 int index = poFeature->GetDefnRef()->GetFieldIndex(p.c_str());
588 if (index >= 0 && poFeature->IsFieldSet(index)) {
589 edge->setParameter(p, poFeature->GetFieldAsString(index));
590 }
591 }
592}
593
594#endif
595
596
597/****************************************************************************/
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:287
#define WRITE_ERRORF(...)
Definition MsgHandler.h:296
#define WRITE_MESSAGE(msg)
Definition MsgHandler.h:288
#define WRITE_ERROR(msg)
Definition MsgHandler.h:295
#define WRITE_WARNING(msg)
Definition MsgHandler.h:286
#define TL(string)
Definition MsgHandler.h:304
#define PROGRESS_DONE_MESSAGE()
Definition MsgHandler.h:291
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition MsgHandler.h:290
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:4503
NBNode * getToNode() const
Returns the destination node of the edge.
Definition NBEdge.h:552
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:789
const std::string & getID() const
Definition NBEdge.h:1551
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:1015
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition NBEdge.h:545
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:4555
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
std::vector< NBNode * > retrieveByPos(const Position &position, const double offset=0.) const
Returns the node with the given coordinates.
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:2799
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.