Skip to content

Commit

Permalink
fix #14599
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Mar 26, 2024
1 parent 7ceec8d commit 9a23cc2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
2 changes: 2 additions & 0 deletions data/typemap/osmPolyconvert.typ.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,6 @@
<polygonType id="railway:position" name="railway.position" color="blue" layer="1" discard="true"/>
<polygonType id="railway:position:exact" name="railway.position.exact" color="green" layer="2" discard="true"/>

<polygonType id="inner" name="inner" color="1.0,1.0,1.0" layer="0"/>

</polygonTypes>
29 changes: 26 additions & 3 deletions src/polyconvert/PCLoaderOSM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ PCLoaderOSM::loadIfSet(OptionsCont& oc, PCPolyContainer& toFill, PCTypeMap& tm)
// load relations to see which additional ways may be relevant
Relations relations;
RelationsMap additionalWays;
RelationsHandler relationsHandler(additionalWays, relations, withAttributes, *m);
std::set<long long int> innerEdges;
RelationsHandler relationsHandler(additionalWays, relations, innerEdges, withAttributes, *m);
for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
// edges
const long before = PROGRESS_BEGIN_TIME_MESSAGE("Parsing relations from osm-file '" + *file + "'");
Expand Down Expand Up @@ -148,6 +149,12 @@ PCLoaderOSM::loadIfSet(OptionsCont& oc, PCPolyContainer& toFill, PCTypeMap& tm)
for (auto it = rel->myWays.begin(); it != rel->myWays.end();) {
if (edges.count(*it) == 0 || edges[*it]->myCurrentNodes.empty()) {
it = rel->myWays.erase(it);
} else if (innerEdges.count(*it) > 0) {
// @note: it would be a good idea to merge inner shapes but
// it's difficult since there may be more than one
// independent inner shape
edges[*it]->standalone = true;
it = rel->myWays.erase(it);
} else {
numNodes += (int)edges[*it]->myCurrentNodes.size();
it++;
Expand Down Expand Up @@ -227,6 +234,14 @@ PCLoaderOSM::loadIfSet(OptionsCont& oc, PCPolyContainer& toFill, PCTypeMap& tm)
}
if (ok) {
edges[e->id] = e;
if (e->myCurrentNodes.front() != e->myCurrentNodes.back()) {
// should be filled
Position posFront = convertNodePosition(nodes[e->myCurrentNodes.front()]);
Position posBack = convertNodePosition(nodes[e->myCurrentNodes.back()]);
if (posFront.distanceTo2D(posBack) < mergeRelationsThreshold) {
e->myCurrentNodes.push_back(e->myCurrentNodes.front());
}
}
WRITE_MESSAGEF(TL("Assembled polygon from relation '%' (name:%)"), toString(rel->id), e->name);
} else {
delete e;
Expand Down Expand Up @@ -268,14 +283,17 @@ PCLoaderOSM::loadIfSet(OptionsCont& oc, PCPolyContainer& toFill, PCTypeMap& tm)
// add as many polygons as keys match defined types
int index = 0;
std::string unknownPolyType = "";
bool isInner = mergeRelationsThreshold >= 0 && innerEdges.count(e->id) != 0 && tm.has("inner");
for (std::map<std::string, std::string>::iterator it = e->myAttributes.begin(); it != e->myAttributes.end(); ++it) {
const std::string& key = it->first;
const std::string& value = it->second;
const std::string fullType = key + "." + value;
if (tm.has(key + "." + value)) {
index = addPolygon(e, vec, tm.get(fullType), fullType, index, useName, toFill, ignorePruning, withAttributes);
auto def = tm.get(isInner ? "inner" : fullType);
index = addPolygon(e, vec, def, fullType, index, useName, toFill, ignorePruning, withAttributes);
} else if (tm.has(key)) {
index = addPolygon(e, vec, tm.get(key), fullType, index, useName, toFill, ignorePruning, withAttributes);
auto def = tm.get(isInner ? "inner" : key);
index = addPolygon(e, vec, def, fullType, index, useName, toFill, ignorePruning, withAttributes);
} else if (MyKeysToInclude.count(key) > 0) {
unknownPolyType = fullType;
}
Expand Down Expand Up @@ -460,11 +478,13 @@ PCLoaderOSM::NodesHandler::myEndElement(int element) {
// ---------------------------------------------------------------------------
PCLoaderOSM::RelationsHandler::RelationsHandler(RelationsMap& additionalWays,
Relations& relations,
std::set<long long int>& innerEdges,
bool withAttributes,
MsgHandler& errorHandler) :
SUMOSAXHandler("osm - file"),
myAdditionalWays(additionalWays),
myRelations(relations),
myInnerEdges(innerEdges),
myWithAttributes(withAttributes),
myErrorHandler(errorHandler),
myCurrentRelation(nullptr) {
Expand Down Expand Up @@ -504,6 +524,9 @@ PCLoaderOSM::RelationsHandler::myStartElement(int element, const SUMOSAXAttribut
std::string memberType = attrs.get<std::string>(SUMO_ATTR_TYPE, nullptr, ok);
if (memberType == "way") {
myCurrentWays.push_back(ref);
if (role == "inner") {
myInnerEdges.insert(ref);
}
}
}
return;
Expand Down
4 changes: 4 additions & 0 deletions src/polyconvert/PCLoaderOSM.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ class PCLoaderOSM : public SUMOSAXHandler {
*/
RelationsHandler(RelationsMap& additionalWays,
Relations& relations,
std::set<long long int>& innerEdges,
bool withAttributes,
MsgHandler& errorHandler);

Expand Down Expand Up @@ -258,6 +259,9 @@ class PCLoaderOSM : public SUMOSAXHandler {
/// @brief the loaded relations
Relations& myRelations;

/// @brief the loaded edges
std::set<long long int>& myInnerEdges;

/// @brief Whether all attributes shall be stored
bool myWithAttributes;

Expand Down

0 comments on commit 9a23cc2

Please sign in to comment.