-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
NIImporter_OpenStreetMap.cpp
2705 lines (2590 loc) · 127 KB
/
NIImporter_OpenStreetMap.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/****************************************************************************/
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
// Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0/
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License 2.0 are satisfied: GNU General Public License, version 2
// or later which is available at
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
/****************************************************************************/
/// @file NIImporter_OpenStreetMap.cpp
/// @author Daniel Krajzewicz
/// @author Jakob Erdmann
/// @author Michael Behrisch
/// @author Walter Bamberger
/// @author Gregor Laemmel
/// @date Mon, 14.04.2008
///
// Importer for networks stored in OpenStreetMap format
/****************************************************************************/
#include <config.h>
#include <algorithm>
#include <set>
#include <functional>
#include <sstream>
#include <limits>
#include <utils/common/UtilExceptions.h>
#include <utils/common/StringUtils.h>
#include <utils/common/ToString.h>
#include <utils/common/MsgHandler.h>
#include <utils/common/StringUtils.h>
#include <utils/common/StringTokenizer.h>
#include <utils/common/FileHelpers.h>
#include <utils/geom/GeoConvHelper.h>
#include <utils/geom/GeomConvHelper.h>
#include <utils/options/OptionsCont.h>
#include <utils/xml/SUMOSAXHandler.h>
#include <utils/xml/SUMOSAXReader.h>
#include <utils/xml/SUMOXMLDefinitions.h>
#include <utils/xml/XMLSubSys.h>
#include <netbuild/NBEdge.h>
#include <netbuild/NBEdgeCont.h>
#include <netbuild/NBNode.h>
#include <netbuild/NBNodeCont.h>
#include <netbuild/NBNetBuilder.h>
#include <netbuild/NBOwnTLDef.h>
#include <netbuild/NBPTLine.h>
#include <netbuild/NBPTLineCont.h>
#include <netbuild/NBPTPlatform.h>
#include <netbuild/NBPTStop.h>
#include "NILoader.h"
#include "NIImporter_OpenStreetMap.h"
#define KM_PER_MILE 1.609344
//#define DEBUG_LAYER_ELEVATION
//#define DEBUG_RAIL_DIRECTION
// ---------------------------------------------------------------------------
// static members
// ---------------------------------------------------------------------------
const double NIImporter_OpenStreetMap::MAXSPEED_UNGIVEN = -1;
const long long int NIImporter_OpenStreetMap::INVALID_ID = std::numeric_limits<long long int>::max();
bool NIImporter_OpenStreetMap::myAllAttributes(false);
std::set<std::string> NIImporter_OpenStreetMap::myExtraAttributes;
// ===========================================================================
// Private classes
// ===========================================================================
/** @brief Functor which compares two Edges
*/
class NIImporter_OpenStreetMap::CompareEdges {
public:
bool operator()(const Edge* e1, const Edge* e2) const {
if (e1->myHighWayType != e2->myHighWayType) {
return e1->myHighWayType > e2->myHighWayType;
}
if (e1->myNoLanes != e2->myNoLanes) {
return e1->myNoLanes > e2->myNoLanes;
}
if (e1->myNoLanesForward != e2->myNoLanesForward) {
return e1->myNoLanesForward > e2->myNoLanesForward;
}
if (e1->myMaxSpeed != e2->myMaxSpeed) {
return e1->myMaxSpeed > e2->myMaxSpeed;
}
if (e1->myIsOneWay != e2->myIsOneWay) {
return e1->myIsOneWay > e2->myIsOneWay;
}
return e1->myCurrentNodes > e2->myCurrentNodes;
}
};
// ===========================================================================
// method definitions
// ===========================================================================
// ---------------------------------------------------------------------------
// static methods
// ---------------------------------------------------------------------------
const std::string NIImporter_OpenStreetMap::compoundTypeSeparator("|"); //clang-tidy says: "compundTypeSeparator with
// static storage duration my throw an exception that cannot be caught
void
NIImporter_OpenStreetMap::loadNetwork(const OptionsCont& oc, NBNetBuilder& nb) {
NIImporter_OpenStreetMap importer;
importer.load(oc, nb);
}
NIImporter_OpenStreetMap::NIImporter_OpenStreetMap() = default;
NIImporter_OpenStreetMap::~NIImporter_OpenStreetMap() {
// delete nodes
for (auto myUniqueNode : myUniqueNodes) {
delete myUniqueNode;
}
// delete edges
for (auto& myEdge : myEdges) {
delete myEdge.second;
}
// delete platform shapes
for (auto& myPlatformShape : myPlatformShapes) {
delete myPlatformShape.second;
}
}
void
NIImporter_OpenStreetMap::load(const OptionsCont& oc, NBNetBuilder& nb) {
if (!oc.isSet("osm-files")) {
return;
}
const std::vector<std::string> files = oc.getStringVector("osm-files");
std::vector<SUMOSAXReader*> readers;
myImportLaneAccess = oc.getBool("osm.lane-access");
myImportTurnSigns = oc.getBool("osm.turn-lanes");
myImportSidewalks = oc.getBool("osm.sidewalks");
myImportBikeAccess = oc.getBool("osm.bike-access");
myImportCrossings = oc.getBool("osm.crossings");
myAllAttributes = OptionsCont::getOptions().getBool("osm.all-attributes");
std::vector<std::string> extra = OptionsCont::getOptions().getStringVector("osm.extra-attributes");
myExtraAttributes.insert(extra.begin(), extra.end());
if (myExtraAttributes.count("all") != 0) {
// import all
myExtraAttributes.clear();
}
// load nodes, first
NodesHandler nodesHandler(myOSMNodes, myUniqueNodes, oc);
for (const std::string& file : files) {
if (!FileHelpers::isReadable(file)) {
WRITE_ERRORF(TL("Could not open osm-file '%'."), file);
return;
}
nodesHandler.setFileName(file);
nodesHandler.resetHierarchy();
const long before = PROGRESS_BEGIN_TIME_MESSAGE("Parsing nodes from osm-file '" + file + "'");
readers.push_back(XMLSubSys::getSAXReader(nodesHandler));
if (!readers.back()->parseFirst(file) || !readers.back()->parseSection(SUMO_TAG_NODE) ||
MsgHandler::getErrorInstance()->wasInformed()) {
return;
}
if (nodesHandler.getDuplicateNodes() > 0) {
WRITE_MESSAGEF(TL("Found and substituted % osm nodes."), toString(nodesHandler.getDuplicateNodes()));
}
PROGRESS_TIME_MESSAGE(before);
}
// load edges, then
EdgesHandler edgesHandler(myOSMNodes, myEdges, myPlatformShapes);
int idx = 0;
for (const std::string& file : files) {
edgesHandler.setFileName(file);
readers[idx]->setHandler(edgesHandler);
const long before = PROGRESS_BEGIN_TIME_MESSAGE("Parsing edges from osm-file '" + file + "'");
if (!readers[idx]->parseSection(SUMO_TAG_WAY)) {
// eof already reached, no relations
delete readers[idx];
readers[idx] = nullptr;
}
PROGRESS_TIME_MESSAGE(before);
idx++;
}
/* Remove duplicate edges with the same shape and attributes */
if (!oc.getBool("osm.skip-duplicates-check")) {
int numRemoved = 0;
PROGRESS_BEGIN_MESSAGE(TL("Removing duplicate edges"));
if (myEdges.size() > 1) {
std::set<const Edge*, CompareEdges> dupsFinder;
for (auto it = myEdges.begin(); it != myEdges.end();) {
if (dupsFinder.count(it->second) > 0) {
numRemoved++;
delete it->second;
myEdges.erase(it++);
} else {
dupsFinder.insert(it->second);
it++;
}
}
}
if (numRemoved > 0) {
WRITE_MESSAGEF(TL("Removed % duplicate osm edges."), toString(numRemoved));
}
PROGRESS_DONE_MESSAGE();
}
/* Mark which nodes are used (by edges or traffic lights).
* This is necessary to detect which OpenStreetMap nodes are for
* geometry only */
std::map<long long int, int> nodeUsage;
// Mark which nodes are used by edges (begin and end)
for (const auto& edgeIt : myEdges) {
assert(edgeIt.second->myCurrentIsRoad);
for (const long long int node : edgeIt.second->myCurrentNodes) {
nodeUsage[node]++;
}
}
// Mark which nodes are used by traffic lights or are pedestrian crossings
for (const auto& nodesIt : myOSMNodes) {
if (nodesIt.second->tlsControlled || nodesIt.second->railwaySignal || (nodesIt.second->pedestrianCrossing && myImportCrossings) /* || nodesIt->second->railwayCrossing*/) {
// If the key is not found in the map, the value is automatically
// initialized with 0.
nodeUsage[nodesIt.first]++;
}
}
/* Instantiate edges
* Only those nodes in the middle of an edge which are used by more than
* one edge are instantiated. Other nodes are considered as geometry nodes. */
NBNodeCont& nc = nb.getNodeCont();
NBTrafficLightLogicCont& tlsc = nb.getTLLogicCont();
for (const auto& edgeIt : myEdges) {
Edge* const e = edgeIt.second;
assert(e->myCurrentIsRoad);
if (e->myCurrentNodes.size() < 2) {
WRITE_WARNINGF(TL("Discarding way '%' because it has only % node(s)"), e->id, e->myCurrentNodes.size());
continue;
}
extendRailwayDistances(e, nb.getTypeCont());
// build nodes;
// - the from- and to-nodes must be built in any case
// - the in-between nodes are only built if more than one edge references them
NBNode* first = insertNodeChecking(e->myCurrentNodes.front(), nc, tlsc);
NBNode* last = insertNodeChecking(e->myCurrentNodes.back(), nc, tlsc);
NBNode* currentFrom = first;
int running = 0;
std::vector<long long int> passed;
for (auto j = e->myCurrentNodes.begin(); j != e->myCurrentNodes.end(); ++j) {
passed.push_back(*j);
if (nodeUsage[*j] > 1 && j != e->myCurrentNodes.end() - 1 && j != e->myCurrentNodes.begin()) {
NBNode* currentTo = insertNodeChecking(*j, nc, tlsc);
running = insertEdge(e, running, currentFrom, currentTo, passed, nb, first, last);
currentFrom = currentTo;
passed.clear();
passed.push_back(*j);
}
}
if (running == 0) {
running = -1;
}
insertEdge(e, running, currentFrom, last, passed, nb, first, last);
}
/* Collect edges which explictly are part of a roundabout and store the edges of each
* detected roundabout */
nb.getEdgeCont().extractRoundabouts();
if (myImportCrossings) {
/* After edges are instantiated
* nodes are parsed again to add pedestrian crossings to them
* This is only executed if crossings are imported and not guessed */
const double crossingWidth = OptionsCont::getOptions().getFloat("default.crossing-width");
for (const auto& nodeIt : nc) {
NBNode* const n = nodeIt.second;
if (n->hasParameter("computePedestrianCrossing")) {
EdgeVector incomingEdges = n->getIncomingEdges();
EdgeVector outgoingEdges = n->getOutgoingEdges();
size_t incomingEdgesNo = incomingEdges.size();
size_t outgoingEdgesNo = outgoingEdges.size();
for (size_t i = 0; i < incomingEdgesNo; i++) {
/* Check if incoming edge has driving lanes(and sidewalks)
* if not, ignore
* if yes, check if there is a corresponding outgoing edge for the opposite direction
* -> if yes, check if it has driving lanes
* --> if yes, do the crossing
* --> if no, only do the crossing with the incoming edge (usually one lane roads with two sidewalks)
* -> if not, do nothing as we don't have a sidewalk in the opposite direction */
auto const iEdge = incomingEdges[i];
if (iEdge->getFirstNonPedestrianLaneIndex(NBNode::FORWARD) > -1
&& iEdge->getSpecialLane(SVC_PEDESTRIAN) > -1) {
std::string const& iEdgeId = iEdge->getID();
std::size_t const m = iEdgeId.find_first_of("#");
std::string const& iWayId = iEdgeId.substr(0, m);
for (size_t j = 0; j < outgoingEdgesNo; j++) {
auto const oEdge = outgoingEdges[j];
// Searching for a corresponding outgoing edge (based on OSM way identifier)
// with at least a pedestrian lane, going in the opposite direction
if (oEdge->getID().find(iWayId) != std::string::npos
&& oEdge->getSpecialLane(SVC_PEDESTRIAN) > -1
&& oEdge->getID().rfind(iWayId, 0) != 0) {
EdgeVector edgeVector = EdgeVector{ iEdge };
if (oEdge->getFirstNonPedestrianLaneIndex(NBNode::FORWARD) > -1) {
edgeVector.push_back(oEdge);
}
if (!n->checkCrossingDuplicated(edgeVector)) {
n->addCrossing(edgeVector, crossingWidth, false);
}
}
}
}
}
for (size_t i = 0; i < outgoingEdgesNo; i++) {
// Same checks as above for loop, but for outgoing edges
auto const oEdge = outgoingEdges[i];
if (oEdge->getFirstNonPedestrianLaneIndex(NBNode::FORWARD) > -1
&& oEdge->getSpecialLane(SVC_PEDESTRIAN) > -1) {
std::string const& oEdgeId = oEdge->getID();
std::size_t const m = oEdgeId.find_first_of("#");
std::string const& iWayId = oEdgeId.substr(0, m);
for (size_t j = 0; j < incomingEdgesNo; j++) {
auto const iEdge = incomingEdges[j];
if (iEdge->getID().find(iWayId) != std::string::npos
&& iEdge->getSpecialLane(SVC_PEDESTRIAN) > -1
&& iEdge->getID().rfind(iWayId, 0) != 0) {
EdgeVector edgeVector = EdgeVector{ oEdge };
if (iEdge->getFirstNonPedestrianLaneIndex(NBNode::FORWARD) > -1) {
edgeVector.push_back(iEdge);
}
if (!n->checkCrossingDuplicated(edgeVector)) {
n->addCrossing(edgeVector, crossingWidth, false);
}
}
}
}
}
n->unsetParameter("computePedestrianCrossing");
}
}
}
const double layerElevation = oc.getFloat("osm.layer-elevation");
if (layerElevation > 0) {
reconstructLayerElevation(layerElevation, nb);
}
// revise pt stops; remove stops on deleted edges
nb.getPTStopCont().cleanupDeleted(nb.getEdgeCont());
// load relations (after edges are built since we want to apply
// turn-restrictions directly to NBEdges)
RelationHandler relationHandler(myOSMNodes, myEdges, &(nb.getPTStopCont()), myPlatformShapes,
&nb.getPTLineCont(), oc);
idx = 0;
for (const std::string& file : files) {
if (readers[idx] != nullptr) {
relationHandler.setFileName(file);
readers[idx]->setHandler(relationHandler);
const long before = PROGRESS_BEGIN_TIME_MESSAGE("Parsing relations from osm-file '" + file + "'");
readers[idx]->parseSection(SUMO_TAG_RELATION);
PROGRESS_TIME_MESSAGE(before);
delete readers[idx];
}
idx++;
}
// declare additional stops that are not anchored to a (road)-way or route relation
std::set<std::string> stopNames;
for (const auto& item : nb.getPTStopCont().getStops()) {
stopNames.insert(item.second->getName());
}
for (const auto& item : myOSMNodes) {
const NIOSMNode* n = item.second;
if (n->ptStopPosition && stopNames.count(n->name) == 0) {
Position ptPos(n->lon, n->lat, n->ele);
if (!NBNetBuilder::transformCoordinate(ptPos)) {
WRITE_ERRORF("Unable to project coordinates for node '%'.", n->id);
}
std::shared_ptr<NBPTStop> ptStop = std::make_shared<NBPTStop>(toString(n->id), ptPos, "", "", n->ptStopLength, n->name, n->permissions);
nb.getPTStopCont().insert(ptStop, true);
}
}
}
NBNode*
NIImporter_OpenStreetMap::insertNodeChecking(long long int id, NBNodeCont& nc, NBTrafficLightLogicCont& tlsc) {
NBNode* node = nc.retrieve(toString(id));
if (node == nullptr) {
NIOSMNode* n = myOSMNodes.find(id)->second;
Position pos(n->lon, n->lat, n->ele);
if (!NBNetBuilder::transformCoordinate(pos, true)) {
WRITE_ERRORF("Unable to project coordinates for junction '%'.", id);
return nullptr;
}
node = new NBNode(toString(id), pos);
if (!nc.insert(node)) {
WRITE_ERRORF(TL("Could not insert junction '%'."), toString(id));
delete node;
return nullptr;
}
n->node = node;
if (n->railwayCrossing) {
node->reinit(pos, SumoXMLNodeType::RAIL_CROSSING);
} else if (n->railwaySignal) {
node->reinit(pos, SumoXMLNodeType::RAIL_SIGNAL);
} else if (n->tlsControlled) {
// ok, this node is a traffic light node where no other nodes
// participate
// @note: The OSM-community has not settled on a schema for differentiating between fixed and actuated lights
TrafficLightType type = SUMOXMLDefinitions::TrafficLightTypes.get(
OptionsCont::getOptions().getString("tls.default-type"));
NBOwnTLDef* tlDef = new NBOwnTLDef(toString(id), node, 0, type);
if (!tlsc.insert(tlDef)) {
// actually, nothing should fail here
delete tlDef;
throw ProcessError(TLF("Could not allocate tls '%'.", toString(id)));
}
} else if (n->pedestrianCrossing && myImportCrossings) {
node->setParameter("computePedestrianCrossing", "true");
}
if (n->railwayBufferStop) {
node->setParameter("buffer_stop", "true");
node->setFringeType(FringeType::INNER);
}
if (n->railwaySignal) {
if (n->myRailDirection == WAY_FORWARD) {
node->setParameter(NBTrafficLightDefinition::OSM_SIGNAL_DIRECTION, "forward");
} else if (n->myRailDirection == WAY_BACKWARD) {
node->setParameter(NBTrafficLightDefinition::OSM_SIGNAL_DIRECTION, "backward");
}
}
node->updateParameters(n->getParametersMap());
}
return node;
}
int
NIImporter_OpenStreetMap::insertEdge(Edge* e, int index, NBNode* from, NBNode* to,
const std::vector<long long int>& passed, NBNetBuilder& nb,
const NBNode* first, const NBNode* last) {
NBNodeCont& nc = nb.getNodeCont();
NBEdgeCont& ec = nb.getEdgeCont();
NBTypeCont& tc = nb.getTypeCont();
NBPTStopCont& sc = nb.getPTStopCont();
NBTrafficLightLogicCont& tlsc = nb.getTLLogicCont();
// patch the id
std::string id = toString(e->id);
if (from == nullptr || to == nullptr) {
WRITE_ERRORF("Discarding edge '%' because the nodes could not be built.", id);
return index;
}
if (index >= 0) {
id = id + "#" + toString(index);
} else {
index = 0;
}
if (from == to) {
assert(passed.size() >= 2);
if (passed.size() == 2) {
WRITE_WARNINGF(TL("Discarding edge '%' which connects two identical nodes without geometry."), id);
return index;
}
// in the special case of a looped way split again using passed
int intermediateIndex = (int) passed.size() / 2;
NBNode* intermediate = insertNodeChecking(passed[intermediateIndex], nc, tlsc);
std::vector<long long int> part1(passed.begin(), passed.begin() + intermediateIndex + 1);
std::vector<long long int> part2(passed.begin() + intermediateIndex, passed.end());
index = insertEdge(e, index, from, intermediate, part1, nb, first, last);
return insertEdge(e, index, intermediate, to, part2, nb, first, last);
}
const int newIndex = index + 1;
const std::string type = usableType(e->myHighWayType, id, tc);
if (type == "") { // we do not want to import it
return newIndex;
}
int numLanesForward = tc.getEdgeTypeNumLanes(type);
int numLanesBackward = tc.getEdgeTypeNumLanes(type);
double speed = tc.getEdgeTypeSpeed(type);
bool defaultsToOneWay = tc.getEdgeTypeIsOneWay(type);
const SVCPermissions defaultPermissions = tc.getEdgeTypePermissions(type);
const SVCPermissions extra = myImportBikeAccess ? e->myExtraAllowed : (e->myExtraAllowed & ~SVC_BICYCLE);
const SVCPermissions extraDis = myImportBikeAccess ? e->myExtraDisallowed : (e->myExtraDisallowed & ~SVC_BICYCLE);
SVCPermissions permissions = (defaultPermissions | extra) & ~extraDis;
if (defaultPermissions == SVC_SHIP) {
// extra permission apply to the ships operating on the route rather than the waterway
permissions = defaultPermissions;
}
if (defaultsToOneWay && defaultPermissions == SVC_PEDESTRIAN && (permissions & (~SVC_PEDESTRIAN)) != 0) {
defaultsToOneWay = false;
}
if ((permissions & SVC_RAIL) != 0 && e->myExtraTags.count("electrified") != 0) {
permissions |= (SVC_RAIL_ELECTRIC | SVC_RAIL_FAST);
}
// convert the shape
PositionVector shape;
double distanceStart = myOSMNodes[passed.front()]->positionMeters;
double distanceEnd = myOSMNodes[passed.back()]->positionMeters;
const bool useDistance = distanceStart != std::numeric_limits<double>::max() && distanceEnd != std::numeric_limits<double>::max();
if (useDistance) {
// negative sign denotes counting in the other direction
if (distanceStart < distanceEnd) {
distanceStart *= -1;
} else {
distanceEnd *= -1;
}
} else {
distanceStart = 0;
distanceEnd = 0;
}
// get additional direction information
int nodeDirection = myOSMNodes.find(StringUtils::toLong(from->getID()))->second->myRailDirection |
myOSMNodes.find(StringUtils::toLong(to->getID()))->second->myRailDirection;
std::vector<std::shared_ptr<NBPTStop> > ptStops;
for (long long i : passed) {
NIOSMNode* n = myOSMNodes.find(i)->second;
// recheck permissions, maybe they got assigned to a strange edge, see #11656
if (n->ptStopPosition && (n->permissions == 0 || (permissions & n->permissions) != 0)) {
std::shared_ptr<NBPTStop> existingPtStop = sc.get(toString(n->id));
if (existingPtStop != nullptr) {
existingPtStop->registerAdditionalEdge(toString(e->id), id);
} else {
Position ptPos(n->lon, n->lat, n->ele);
if (!NBNetBuilder::transformCoordinate(ptPos)) {
WRITE_ERRORF("Unable to project coordinates for node '%'.", n->id);
}
ptStops.push_back(std::make_shared<NBPTStop>(toString(n->id), ptPos, id, toString(e->id), n->ptStopLength, n->name, n->permissions));
sc.insert(ptStops.back());
}
}
if (n->railwaySignal) {
nodeDirection |= n->myRailDirection;
}
Position pos(n->lon, n->lat, n->ele);
shape.push_back(pos);
}
#ifdef DEBUG_LAYER_ELEVATION
if (e->id == "DEBUGID") {
std::cout
<< " id=" << id << " from=" << from->getID() << " fromRailDirection=" << myOSMNodes.find(StringUtils::toLong(from->getID()))->second->myRailDirection
<< " to=" << to->getID() << " toRailDirection=" << myOSMNodes.find(StringUtils::toLong(to->getID()))->second->myRailDirection
<< " origRailDirection=" << e->myRailDirection
<< " nodeDirection=" << nodeDirection
<< "\n";
}
#endif
if (e->myRailDirection == WAY_UNKNOWN && nodeDirection != WAY_UNKNOWN && nodeDirection != WAY_FORWARD
&& nodeDirection != (WAY_FORWARD | WAY_UNKNOWN)) {
//std::cout << "way " << e->id << " nodeDirection=" << nodeDirection << " origDirection=" << e->myRailDirection << "\n";
// heuristc: assume that the mapped way direction indicates
// potential driving direction
e->myRailDirection = WAY_BOTH;
}
if (!NBNetBuilder::transformCoordinates(shape)) {
WRITE_ERRORF("Unable to project coordinates for edge '%'.", id);
}
SVCPermissions forwardPermissions = permissions;
SVCPermissions backwardPermissions = permissions;
const std::string streetName = isRailway(permissions) && e->ref != "" ? e->ref : e->streetName;
if (streetName == e->ref) {
e->unsetParameter("ref"); // avoid superfluous param for railways
}
double forwardWidth = tc.getEdgeTypeWidth(type);
double backwardWidth = tc.getEdgeTypeWidth(type);
double sidewalkWidth = tc.getEdgeTypeSidewalkWidth(type);
bool addSidewalk = sidewalkWidth != NBEdge::UNSPECIFIED_WIDTH;
if (myImportSidewalks) {
if (addSidewalk) {
// only use sidewalk width from typemap but don't add sidewalks
// unless OSM specifies them
addSidewalk = false;
} else {
sidewalkWidth = OptionsCont::getOptions().getFloat("default.sidewalk-width");
}
}
double bikeLaneWidth = tc.getEdgeTypeBikeLaneWidth(type);
const std::string& onewayBike = e->myExtraTags["oneway:bicycle"];
if (onewayBike == "false" || onewayBike == "no" || onewayBike == "0") {
e->myCyclewayType = e->myCyclewayType == WAY_UNKNOWN ? WAY_BACKWARD : (WayType)(e->myCyclewayType | WAY_BACKWARD);
}
const bool addBikeLane = bikeLaneWidth != NBEdge::UNSPECIFIED_WIDTH ||
(myImportBikeAccess && ((e->myCyclewayType & WAY_BOTH) != 0 || e->myExtraTags.count("segregated") != 0));
if (addBikeLane && bikeLaneWidth == NBEdge::UNSPECIFIED_WIDTH) {
bikeLaneWidth = OptionsCont::getOptions().getFloat("default.bikelane-width");
}
// check directions
bool addForward = true;
bool addBackward = true;
const bool explicitTwoWay = e->myIsOneWay == "no";
if ((e->myIsOneWay == "true" || e->myIsOneWay == "yes" || e->myIsOneWay == "1"
|| (defaultsToOneWay && e->myIsOneWay != "no" && e->myIsOneWay != "false" && e->myIsOneWay != "0"))
&& e->myRailDirection != WAY_BOTH) {
addBackward = false;
}
if (e->myIsOneWay == "-1" || e->myIsOneWay == "reverse" || e->myRailDirection == WAY_BACKWARD) {
// one-way in reversed direction of way
addForward = false;
addBackward = true;
}
if (!e->myIsOneWay.empty() && e->myIsOneWay != "false" && e->myIsOneWay != "no" && e->myIsOneWay != "true"
&& e->myIsOneWay != "yes" && e->myIsOneWay != "-1" && e->myIsOneWay != "1" && e->myIsOneWay != "reverse") {
WRITE_WARNINGF(TL("New value for oneway found: %"), e->myIsOneWay);
}
if ((permissions == SVC_BICYCLE || permissions == (SVC_BICYCLE | SVC_PEDESTRIAN) || permissions == SVC_PEDESTRIAN)) {
if (addBackward && (onewayBike == "true" || onewayBike == "yes" || onewayBike == "1")) {
addBackward = false;
}
if (addForward && (onewayBike == "reverse" || onewayBike == "-1")) {
addForward = false;
}
if (!addBackward && (onewayBike == "false" || onewayBike == "no" || onewayBike == "0")) {
addBackward = true;
}
}
bool ok = true;
// if we had been able to extract the number of lanes, override the highway type default
if (e->myNoLanes > 0) {
if (addForward && !addBackward) {
numLanesForward = e->myNoLanesForward > 0 ? e->myNoLanesForward : e->myNoLanes;
} else if (!addForward && addBackward) {
numLanesBackward = e->myNoLanesForward < 0 ? -e->myNoLanesForward : e->myNoLanes;
} else {
if (e->myNoLanesForward > 0) {
numLanesForward = e->myNoLanesForward;
} else if (e->myNoLanesForward < 0) {
numLanesForward = e->myNoLanes + e->myNoLanesForward;
} else {
numLanesForward = (int) std::ceil(e->myNoLanes / 2.0);
}
numLanesBackward = e->myNoLanes - numLanesForward;
// sometimes ways are tagged according to their physical width of a single
// lane but they are intended for traffic in both directions
numLanesForward = MAX2(1, numLanesForward);
numLanesBackward = MAX2(1, numLanesBackward);
}
} else if (e->myNoLanes == 0) {
WRITE_WARNINGF(TL("Skipping edge '%' because it has zero lanes."), id);
ok = false;
} else {
// the total number of lanes is not known but at least one direction
if (e->myNoLanesForward > 0) {
numLanesForward = e->myNoLanesForward;
}
if (e->myNoLanesForward < 0) {
numLanesBackward = -e->myNoLanesForward;
}
}
// deal with busways that run in the opposite direction of a one-way street
if (!addForward && (e->myBuswayType & WAY_FORWARD) != 0) {
addForward = true;
forwardPermissions = SVC_BUS;
numLanesForward = 1;
}
if (!addBackward && (e->myBuswayType & WAY_BACKWARD) != 0) {
addBackward = true;
backwardPermissions = SVC_BUS;
numLanesBackward = 1;
}
// with is meant for raw lane count before adding sidewalks or cycleways
const int taggedLanes = (addForward ? numLanesForward : 0) + (addBackward ? numLanesBackward : 0);
if (e->myWidth > 0 && e->myWidthLanesForward.size() == 0 && e->myWidthLanesBackward.size() == 0 && taggedLanes != 0
&& !OptionsCont::getOptions().getBool("ignore-widths")) {
// width is tagged excluding sidewalks and cycleways
forwardWidth = e->myWidth / taggedLanes;
backwardWidth = forwardWidth;
}
// if we had been able to extract the maximum speed, override the type's default
if (e->myMaxSpeed != MAXSPEED_UNGIVEN) {
speed = e->myMaxSpeed / 3.6;
}
double speedBackward = speed;
if (e->myMaxSpeedBackward != MAXSPEED_UNGIVEN) {
speedBackward = e->myMaxSpeedBackward / 3.6;
}
if (speed <= 0 || speedBackward <= 0) {
WRITE_WARNINGF(TL("Skipping edge '%' because it has speed %."), id, speed);
ok = false;
}
// deal with cycleways that run in the opposite direction of a one-way street
WayType cyclewayType = e->myCyclewayType; // make a copy because we do some temporary modifications
if (addBikeLane) {
if (!addForward && (cyclewayType & WAY_FORWARD) != 0) {
addForward = true;
forwardPermissions = SVC_BICYCLE;
forwardWidth = bikeLaneWidth;
numLanesForward = 1;
// do not add an additional cycle lane
cyclewayType = (WayType)(cyclewayType & ~WAY_FORWARD);
}
if (!addBackward && (cyclewayType & WAY_BACKWARD) != 0) {
addBackward = true;
backwardPermissions = SVC_BICYCLE;
backwardWidth = bikeLaneWidth;
numLanesBackward = 1;
// do not add an additional cycle lane
cyclewayType = (WayType)(cyclewayType & ~WAY_BACKWARD);
}
}
// deal with sidewalks that run in the opposite direction of a one-way street
WayType sidewalkType = e->mySidewalkType; // make a copy because we do some temporary modifications
if (sidewalkType == WAY_UNKNOWN && (e->myExtraAllowed & SVC_PEDESTRIAN) != 0 && (permissions & SVC_PASSENGER) != 0) {
// do not assume shared space unless sidewalk is actively disabled
sidewalkType = WAY_BOTH;
}
if (addSidewalk || (myImportSidewalks && (permissions & SVC_ROAD_CLASSES) != 0 && defaultPermissions != SVC_PEDESTRIAN)) {
if (!addForward && (sidewalkType & WAY_FORWARD) != 0) {
addForward = true;
forwardPermissions = SVC_PEDESTRIAN;
forwardWidth = tc.getEdgeTypeSidewalkWidth(type);
numLanesForward = 1;
// do not add an additional sidewalk
sidewalkType = (WayType)(sidewalkType & ~WAY_FORWARD); //clang tidy thinks "!WAY_FORWARD" is always false
} else if (addSidewalk && addForward && (sidewalkType & WAY_BOTH) == 0
&& numLanesForward == 1 && numLanesBackward <= 1
&& (e->myExtraDisallowed & SVC_PEDESTRIAN) == 0) {
// our typemap says pedestrians should walk here but the data says
// there is no sidewalk at all. If the road is small, pedestrians can just walk
// on the road
forwardPermissions |= SVC_PEDESTRIAN;
}
if (!addBackward && (sidewalkType & WAY_BACKWARD) != 0) {
addBackward = true;
backwardPermissions = SVC_PEDESTRIAN;
backwardWidth = tc.getEdgeTypeSidewalkWidth(type);
numLanesBackward = 1;
// do not add an additional cycle lane
sidewalkType = (WayType)(sidewalkType & ~WAY_BACKWARD); //clang tidy thinks "!WAY_BACKWARD" is always false
} else if (addSidewalk && addBackward && (sidewalkType & WAY_BOTH) == 0
&& numLanesBackward == 1 && numLanesForward <= 1
&& (e->myExtraDisallowed & SVC_PEDESTRIAN) == 0) {
// our typemap says pedestrians should walk here but the data says
// there is no sidewalk at all. If the road is small, pedestrians can just walk
// on the road
backwardPermissions |= SVC_PEDESTRIAN;
}
}
const std::string origID = OptionsCont::getOptions().getBool("output.original-names") ? toString(e->id) : "";
if (ok) {
const bool lefthand = OptionsCont::getOptions().getBool("lefthand");
const int offsetFactor = lefthand ? -1 : 1;
LaneSpreadFunction lsf = (addBackward || OptionsCont::getOptions().getBool("osm.oneway-spread-right")) &&
(e->myRailDirection == WAY_UNKNOWN || explicitTwoWay) ? LaneSpreadFunction::RIGHT : LaneSpreadFunction::CENTER;
if (addBackward && lsf == LaneSpreadFunction::RIGHT && OptionsCont::getOptions().getString("default.spreadtype") == toString(LaneSpreadFunction::ROADCENTER)) {
lsf = LaneSpreadFunction::ROADCENTER;
}
if (tc.getEdgeTypeSpreadType(type) != LaneSpreadFunction::RIGHT) {
// user defined value overrides defaults
lsf = tc.getEdgeTypeSpreadType(type);
}
id = StringUtils::escapeXML(id);
const std::string reverseID = "-" + id;
const bool markOSMDirection = from->getType() == SumoXMLNodeType::RAIL_SIGNAL || to->getType() == SumoXMLNodeType::RAIL_SIGNAL;
if (addForward) {
assert(numLanesForward > 0);
NBEdge* nbe = new NBEdge(id, from, to, type, speed, NBEdge::UNSPECIFIED_FRICTION, numLanesForward, tc.getEdgeTypePriority(type),
forwardWidth, NBEdge::UNSPECIFIED_OFFSET, shape, lsf,
StringUtils::escapeXML(streetName), origID, true);
if (markOSMDirection) {
nbe->setParameter(NBTrafficLightDefinition::OSM_DIRECTION, "forward");
}
nbe->setPermissions(forwardPermissions, -1);
if ((e->myBuswayType & WAY_FORWARD) != 0) {
nbe->setPermissions(SVC_BUS, 0);
}
applyChangeProhibition(nbe, e->myChangeForward);
applyLaneUse(nbe, e, true);
applyTurnSigns(nbe, e->myTurnSignsForward);
nbe->setTurnSignTarget(last->getID());
if (addBikeLane && (cyclewayType == WAY_UNKNOWN || (cyclewayType & WAY_FORWARD) != 0)) {
nbe->addBikeLane(bikeLaneWidth * offsetFactor);
} else if (nbe->getPermissions(0) == SVC_BUS) {
// bikes drive on buslanes if no separate cycle lane is available
nbe->setPermissions(SVC_BUS | SVC_BICYCLE, 0);
}
if ((addSidewalk && (sidewalkType == WAY_UNKNOWN || (sidewalkType & WAY_FORWARD) != 0))
|| (myImportSidewalks && (sidewalkType & WAY_FORWARD) != 0 && defaultPermissions != SVC_PEDESTRIAN)) {
nbe->addSidewalk(sidewalkWidth * offsetFactor);
}
if (!addBackward && (e->myExtraAllowed & SVC_PEDESTRIAN) != 0 && (nbe->getPermissions(0) & SVC_PEDESTRIAN) == 0) {
// Pedestrians are explicitly allowed (maybe through foot="yes") but did not get a sidewalk (maybe through sidewalk="no").
// Since we do not have a backward edge, we need to make sure they can at least walk somewhere, see #14124
nbe->setPermissions(nbe->getPermissions(0) | SVC_PEDESTRIAN, 0);
}
nbe->updateParameters(e->getParametersMap());
nbe->setDistance(distanceStart);
if (e->myAmInRoundabout) {
// ensure roundabout edges have the precedence
nbe->setJunctionPriority(to, NBEdge::JunctionPriority::ROUNDABOUT);
nbe->setJunctionPriority(from, NBEdge::JunctionPriority::ROUNDABOUT);
}
// process forward lanes width
const int numForwardLanesFromWidthKey = (int)e->myWidthLanesForward.size();
if (numForwardLanesFromWidthKey > 0 && !OptionsCont::getOptions().getBool("ignore-widths")) {
if ((int)nbe->getLanes().size() != numForwardLanesFromWidthKey) {
WRITE_WARNINGF(TL("Forward lanes count for edge '%' ('%') is not matching the number of lanes defined in width:lanes:forward key ('%'). Using default width values."),
id, nbe->getLanes().size(), numForwardLanesFromWidthKey);
} else {
for (int i = 0; i < numForwardLanesFromWidthKey; i++) {
const double actualWidth = e->myWidthLanesForward[i] <= 0 ? forwardWidth : e->myWidthLanesForward[i];
const int laneIndex = lefthand ? i : numForwardLanesFromWidthKey - i - 1;
nbe->setLaneWidth(laneIndex, actualWidth);
}
}
}
if (!ec.insert(nbe)) {
delete nbe;
throw ProcessError(TLF("Could not add edge '%'.", id));
}
}
if (addBackward) {
assert(numLanesBackward > 0);
NBEdge* nbe = new NBEdge(reverseID, to, from, type, speedBackward, NBEdge::UNSPECIFIED_FRICTION, numLanesBackward, tc.getEdgeTypePriority(type),
backwardWidth, NBEdge::UNSPECIFIED_OFFSET, shape.reverse(), lsf,
StringUtils::escapeXML(streetName), origID, true);
if (markOSMDirection) {
nbe->setParameter(NBTrafficLightDefinition::OSM_DIRECTION, "backward");
}
nbe->setPermissions(backwardPermissions);
if ((e->myBuswayType & WAY_BACKWARD) != 0) {
nbe->setPermissions(SVC_BUS, 0);
}
applyChangeProhibition(nbe, e->myChangeBackward);
applyLaneUse(nbe, e, false);
applyTurnSigns(nbe, e->myTurnSignsBackward);
nbe->setTurnSignTarget(first->getID());
if (addBikeLane && (cyclewayType == WAY_UNKNOWN || (cyclewayType & WAY_BACKWARD) != 0)) {
nbe->addBikeLane(tc.getEdgeTypeBikeLaneWidth(type) * offsetFactor);
} else if (nbe->getPermissions(0) == SVC_BUS) {
// bikes drive on buslanes if no separate cycle lane is available
nbe->setPermissions(SVC_BUS | SVC_BICYCLE, 0);
}
if ((addSidewalk && (sidewalkType == WAY_UNKNOWN || (sidewalkType & WAY_BACKWARD) != 0))
|| (myImportSidewalks && (sidewalkType & WAY_BACKWARD) != 0 && defaultPermissions != SVC_PEDESTRIAN)) {
nbe->addSidewalk(sidewalkWidth * offsetFactor);
}
nbe->updateParameters(e->getParametersMap());
nbe->setDistance(distanceEnd);
if (e->myAmInRoundabout) {
// ensure roundabout edges have the precedence
nbe->setJunctionPriority(from, NBEdge::JunctionPriority::ROUNDABOUT);
nbe->setJunctionPriority(to, NBEdge::JunctionPriority::ROUNDABOUT);
}
// process backward lanes width
const int numBackwardLanesFromWidthKey = (int)e->myWidthLanesBackward.size();
if (numBackwardLanesFromWidthKey > 0 && !OptionsCont::getOptions().getBool("ignore-widths")) {
if ((int)nbe->getLanes().size() != numBackwardLanesFromWidthKey) {
WRITE_WARNINGF(TL("Backward lanes count for edge '%' ('%') is not matching the number of lanes defined in width:lanes:backward key ('%'). Using default width values."),
id, nbe->getLanes().size(), numBackwardLanesFromWidthKey);
} else {
for (int i = 0; i < numBackwardLanesFromWidthKey; i++) {
const double actualWidth = e->myWidthLanesBackward[i] <= 0 ? backwardWidth : e->myWidthLanesBackward[i];
const int laneIndex = lefthand ? i : numBackwardLanesFromWidthKey - i - 1;
nbe->setLaneWidth(laneIndex, actualWidth);
}
}
}
if (!ec.insert(nbe)) {
delete nbe;
throw ProcessError(TLF("Could not add edge '-%'.", id));
}
}
if ((e->myParkingType & PARKING_BOTH) != 0 && OptionsCont::getOptions().isSet("parking-output")) {
if ((e->myParkingType & PARKING_RIGHT) != 0) {
if (addForward) {
nb.getParkingCont().push_back(NBParking(id, id));
} else {
/// XXX parking area should be added on the left side of a reverse one-way street
if ((e->myParkingType & PARKING_LEFT) == 0 && !addBackward) {
/// put it on the wrong side (better than nothing)
nb.getParkingCont().push_back(NBParking(reverseID, reverseID));
}
}
}
if ((e->myParkingType & PARKING_LEFT) != 0) {
if (addBackward) {
nb.getParkingCont().push_back(NBParking(reverseID, reverseID));
} else {
/// XXX parking area should be added on the left side of an one-way street
if ((e->myParkingType & PARKING_RIGHT) == 0 && !addForward) {
/// put it on the wrong side (better than nothing)
nb.getParkingCont().push_back(NBParking(id, id));
}
}
}
}
}
return newIndex;
}
// ---------------------------------------------------------------------------
// definitions of NIImporter_OpenStreetMap::NodesHandler-methods
// ---------------------------------------------------------------------------
NIImporter_OpenStreetMap::NodesHandler::NodesHandler(std::map<long long int, NIOSMNode*>& toFill,
std::set<NIOSMNode*, CompareNodes>& uniqueNodes, const OptionsCont& oc) :
SUMOSAXHandler("osm - file"),
myToFill(toFill),
myCurrentNode(nullptr),
myHierarchyLevel(0),
myUniqueNodes(uniqueNodes),
myImportElevation(oc.getBool("osm.elevation")),
myDuplicateNodes(0),
myOptionsCont(oc)
{
// init rail signal rules
for (std::string kv : oc.getStringVector("osm.railsignals")) {
if (kv == "DEFAULT") {
myRailSignalRules.push_back("railway:signal:main=");
myRailSignalRules.push_back("railway:signal:combined=");
} else if (kv == "ALL") {
myRailSignalRules.push_back("railway=signal");
} else {
myRailSignalRules.push_back("railway:signal:" + kv);
}
}
}
NIImporter_OpenStreetMap::NodesHandler::~NodesHandler() = default;
void
NIImporter_OpenStreetMap::NodesHandler::myStartElement(int element, const SUMOSAXAttributes& attrs) {
++myHierarchyLevel;
if (element == SUMO_TAG_NODE) {
bool ok = true;
myLastNodeID = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
if (myHierarchyLevel != 2) {
WRITE_ERROR("Node element on wrong XML hierarchy level (id='" + myLastNodeID +
"', level='" + toString(myHierarchyLevel) + "').");
return;
}
const std::string& action = attrs.getOpt<std::string>(SUMO_ATTR_ACTION, myLastNodeID.c_str(), ok);
if (action == "delete" || !ok) {
return;
}
try {
// we do not use attrs.get here to save some time on parsing
const long long int id = StringUtils::toLong(myLastNodeID);
myCurrentNode = nullptr;
const auto insertionIt = myToFill.lower_bound(id);
if (insertionIt == myToFill.end() || insertionIt->first != id) {
// assume we are loading multiple files, so we won't report duplicate nodes
const double tlon = attrs.get<double>(SUMO_ATTR_LON, myLastNodeID.c_str(), ok);
const double tlat = attrs.get<double>(SUMO_ATTR_LAT, myLastNodeID.c_str(), ok);
if (!ok) {
return;
}
myCurrentNode = new NIOSMNode(id, tlon, tlat);
auto similarNode = myUniqueNodes.find(myCurrentNode);
if (similarNode == myUniqueNodes.end()) {
myUniqueNodes.insert(myCurrentNode);
} else {
delete myCurrentNode;
myCurrentNode = *similarNode;
myDuplicateNodes++;
}
myToFill.emplace_hint(insertionIt, id, myCurrentNode);
}
} catch (FormatException&) {
WRITE_ERROR(TL("Attribute 'id' in the definition of a node is not of type long long int."));
return;
}
}
if (element == SUMO_TAG_TAG && myCurrentNode != nullptr) {
if (myHierarchyLevel != 3) {
WRITE_ERROR(TL("Tag element on wrong XML hierarchy level."));
return;
}
bool ok = true;
const std::string& key = attrs.get<std::string>(SUMO_ATTR_K, myLastNodeID.c_str(), ok, false);
// we check whether the key is relevant (and we really need to transcode the value) to avoid hitting #1636
if (key == "highway" || key == "ele" || key == "crossing" || key == "railway" || key == "public_transport"
|| key == "name" || key == "train" || key == "bus" || key == "tram" || key == "light_rail" || key == "subway" || key == "station" || key == "noexit"
|| StringUtils::startsWith(key, "railway:signal")
|| StringUtils::startsWith(key, "railway:position")
) {
const std::string& value = attrs.get<std::string>(SUMO_ATTR_V, myLastNodeID.c_str(), ok, false);