59 std::set<std::string> result;
60 result.insert(
"highway");
61 result.insert(
"railway");
62 result.insert(
"railway:position");
63 result.insert(
"railway:position:exact");
64 result.insert(
"waterway");
65 result.insert(
"aeroway");
66 result.insert(
"aerialway");
67 result.insert(
"power");
68 result.insert(
"man_made");
69 result.insert(
"building");
70 result.insert(
"leisure");
71 result.insert(
"amenity");
72 result.insert(
"shop");
73 result.insert(
"tourism");
74 result.insert(
"historic");
75 result.insert(
"landuse");
76 result.insert(
"natural");
77 result.insert(
"military");
78 result.insert(
"boundary");
79 result.insert(
"admin_level");
80 result.insert(
"sport");
81 result.insert(
"polygon");
82 result.insert(
"place");
83 result.insert(
"population");
84 result.insert(
"barrier");
85 result.insert(
"openGeoDB:population");
86 result.insert(
"openGeoDB:name");
93 if (!oc.
isSet(
"osm-files")) {
99 std::map<long long int, PCOSMNode*> nodes;
100 bool withAttributes = oc.
getBool(
"all-attributes");
103 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
106 WRITE_ERROR(
"Could not open osm-file '" + *file +
"'.");
111 for (std::map<long long int, PCOSMNode*>::const_iterator i = nodes.begin(); i != nodes.end(); ++i) {
121 RelationsHandler relationsHandler(additionalWays, relations, withAttributes, *m);
122 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
131 EdgesHandler edgesHandler(nodes, edges, additionalWays, withAttributes, *m);
132 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
140 const bool useName = oc.
getBool(
"osm.use-name");
143 if (mergeRelationsThreshold >= 0) {
145 if (!rel->keep || rel->myWays.empty()) {
150 for (
auto it = rel->myWays.begin(); it != rel->myWays.end();) {
151 if (edges.count(*it) == 0 || edges[*it]->myCurrentNodes.empty()) {
152 it = rel->myWays.erase(it);
154 numNodes += (int)edges[*it]->myCurrentNodes.size();
169 std::set<long long int> remaining(rel->myWays.begin(), rel->myWays.end());
170 PCOSMEdge* minEdge = edges[rel->myWays.front()];
174 remaining.erase(minEdge->
id);
176 while (!remaining.empty()) {
178 double minDist = std::numeric_limits<double>::max();
179 bool minFront =
false;
180 for (
long long int wayID : remaining) {
186 if (frontDist < minDist) {
191 if (backDist < minDist) {
197 if (minDist > mergeRelationsThreshold) {
199 for (
long long int wayID : remaining) {
213 if (length > mergeRelationsThreshold) {
215 "' (name:" + e->
name +
" reason: found gap of " +
toString(minDist) +
217 "')\n Total length of remaining ways: " +
toString(length) +
"m.");
230 remaining.erase(minEdge->
id);
238 for (
long long int wayID : rel->myWays) {
247 for (EdgeMap::iterator i = edges.begin(); i != edges.end(); ++i) {
253 if (!e->
standalone && mergeRelationsThreshold >= 0) {
274 std::string unknownPolyType =
"";
275 for (std::map<std::string, std::string>::iterator it = e->
myAttributes.begin(); it != e->
myAttributes.end(); ++it) {
276 const std::string& key = it->first;
277 const std::string& value = it->second;
278 const std::string fullType = key +
"." + value;
279 if (tm.
has(key +
"." + value)) {
280 index =
addPolygon(e, vec, tm.
get(fullType), fullType, index, useName, toFill, ignorePruning, withAttributes);
281 }
else if (tm.
has(key)) {
282 index =
addPolygon(e, vec, tm.
get(key), fullType, index, useName, toFill, ignorePruning, withAttributes);
284 unknownPolyType = fullType;
288 if (index == 0 && !def.
discard && unknownPolyType !=
"") {
289 addPolygon(e, vec, def, unknownPolyType, index, useName, toFill, ignorePruning, withAttributes);
295 for (std::map<long long int, PCOSMNode*>::iterator i = nodes.begin(); i != nodes.end(); ++i) {
308 std::string unKnownPOIType =
"";
309 for (std::map<std::string, std::string>::iterator it = n->
myAttributes.begin(); it != n->
myAttributes.end(); ++it) {
310 const std::string& key = it->first;
311 const std::string& value = it->second;
312 const std::string fullType = key +
"." + value;
313 if (tm.
has(key +
"." + value)) {
314 index =
addPOI(n, pos, tm.
get(fullType), fullType, index, useName, toFill, ignorePruning, withAttributes);
315 }
else if (tm.
has(key)) {
316 index =
addPOI(n, pos, tm.
get(key), fullType, index, useName, toFill, ignorePruning, withAttributes);
318 unKnownPOIType = fullType;
322 if (index == 0 && !def.
discard && unKnownPOIType !=
"") {
323 addPOI(n, pos, def, unKnownPOIType, index, useName, toFill, ignorePruning, withAttributes);
327 for (std::map<long long int, PCOSMNode*>::const_iterator i = nodes.begin(); i != nodes.end(); ++i) {
331 for (EdgeMap::iterator i = edges.begin(); i != edges.end(); ++i) {
335 for (Relations::iterator i = relations.begin(); i != relations.end(); ++i) {
354 const bool closedShape = vec.front() == vec.back();
355 const std::string idSuffix = (index == 0 ?
"" :
"#" +
toString(index));
361 if (withAttributes) {
364 if (!toFill.
add(poly, ignorePruning)) {
375 int index,
bool useName,
PCPolyContainer& toFill,
bool ignorePruning,
bool withAttributes) {
379 const std::string idSuffix = (index == 0 ?
"" :
"#" +
toString(index));
384 def.
color, pos,
false,
"", 0, 0, (
double)def.
layer);
385 if (withAttributes) {
388 if (!toFill.
add(poi, ignorePruning)) {
401 bool withAttributes,
MsgHandler& errorHandler) :
402 SUMOSAXHandler(
"osm - file"), myWithAttributes(withAttributes), myErrorHandler(errorHandler),
403 myToFill(toFill), myLastNodeID(-1) {}
411 myParentElements.push_back(element);
414 long long int id = attrs.
get<
long long int>(
SUMO_ATTR_ID,
nullptr, ok);
419 if (myToFill.find(
id) == myToFill.end()) {
432 myToFill[toAdd->
id] = toAdd;
435 if (element ==
SUMO_TAG_TAG && myParentElements.size() > 2 && myParentElements[myParentElements.size() - 2] ==
SUMO_TAG_NODE
436 && myLastNodeID != -1) {
441 myToFill[myLastNodeID]->name = value;
442 }
else if (key ==
"") {
443 myErrorHandler.inform(
"Empty key in a a tag while parsing node '" +
toString(myLastNodeID) +
"' occurred.");
449 myToFill[myLastNodeID]->myAttributes[key] = value;
459 myParentElements.pop_back();
471 myAdditionalWays(additionalWays),
472 myRelations(relations),
473 myWithAttributes(withAttributes),
474 myErrorHandler(errorHandler),
475 myCurrentRelation(nullptr) {
485 myParentElements.push_back(element);
488 myCurrentWays.clear();
490 if (action ==
"delete") {
491 myCurrentRelation =
nullptr;
494 myCurrentRelation->keep =
false;
496 myCurrentRelation->id = attrs.
get<
long long int>(
SUMO_ATTR_ID,
nullptr, ok);
497 myRelations.push_back(myCurrentRelation);
500 }
else if (myCurrentRelation ==
nullptr) {
508 if (role ==
"outer" || role ==
"inner") {
510 if (memberType ==
"way") {
511 myCurrentWays.push_back(ref);
518 && myCurrentRelation !=
nullptr) {
523 myErrorHandler.inform(
"Empty key in a a tag while parsing way '" +
toString(myCurrentRelation) +
"' occurred.");
530 myCurrentRelation->name = value;
532 myCurrentRelation->keep =
true;
533 for (std::vector<long long int>::iterator it = myCurrentWays.begin(); it != myCurrentWays.end(); ++it) {
534 myAdditionalWays[*it] = myCurrentRelation;
537 myCurrentRelation->myAttributes[key] = value;
544 myParentElements.pop_back();
546 myCurrentRelation->myWays = myCurrentWays;
547 myCurrentRelation =
nullptr;
548 myCurrentWays.clear();
559 bool withAttributes,
MsgHandler& errorHandler) :
561 myWithAttributes(withAttributes),
562 myErrorHandler(errorHandler),
563 myOSMNodes(osmNodes),
565 myAdditionalWays(additionalWays) {
575 myParentElements.push_back(element);
579 const long long int id = attrs.
get<
long long int>(
SUMO_ATTR_ID,
nullptr, ok);
581 if (action ==
"delete" || !ok) {
582 myCurrentEdge =
nullptr;
586 myCurrentEdge->id = id;
587 myCurrentEdge->myIsClosed =
false;
588 myCurrentEdge->standalone =
false;
589 myKeep = (myAdditionalWays.find(
id) != myAdditionalWays.end());
592 if (element ==
SUMO_TAG_ND && myCurrentEdge !=
nullptr) {
594 const long long int ref = attrs.
get<
long long int>(
SUMO_ATTR_REF,
nullptr, ok);
596 if (myOSMNodes.find(ref) == myOSMNodes.end()) {
600 myCurrentEdge->myCurrentNodes.push_back(ref);
604 if (element ==
SUMO_TAG_TAG && myParentElements.size() > 2 && myParentElements[myParentElements.size() - 2] ==
SUMO_TAG_WAY
605 && myCurrentEdge !=
nullptr) {
610 myErrorHandler.inform(
"Empty key in a a tag while parsing way '" +
toString(myCurrentEdge->id) +
"' occurred.");
617 myCurrentEdge->name = value;
620 myCurrentEdge->standalone =
true;
622 myCurrentEdge->myAttributes[key] = value;
629 myParentElements.pop_back();
630 if (element ==
SUMO_TAG_WAY && myCurrentEdge !=
nullptr) {
632 RelationsMap::const_iterator it = myAdditionalWays.find(myCurrentEdge->id);
633 if (it != myAdditionalWays.end()) {
634 myCurrentEdge->myAttributes.insert((*it).second->myAttributes.begin(), (*it).second->myAttributes.end());
636 myEdgeMap[myCurrentEdge->id] = myCurrentEdge;
638 delete myCurrentEdge;
640 myCurrentEdge =
nullptr;