Skip to content

Commit

Permalink
using signal direction as additional hint of possible driving directi…
Browse files Browse the repository at this point in the history
…on. refs #14512
  • Loading branch information
namdre committed Mar 15, 2024
1 parent ec8a6d3 commit fc10775
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
30 changes: 27 additions & 3 deletions src/netimport/NIImporter_OpenStreetMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,10 @@ NIImporter_OpenStreetMap::insertEdge(Edge* e, int index, NBNode* from, NBNode* t
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;
Expand All @@ -532,9 +536,16 @@ NIImporter_OpenStreetMap::insertEdge(Edge* e, int index, NBNode* from, NBNode* t
sc.insert(ptStops.back());
}
}
nodeDirection = n->myRailDirection;
Position pos(n->lon, n->lat, n->ele);
shape.push_back(pos);
}
if (e->myRailDirection == WAY_UNKNOWN && nodeDirection != WAY_UNKNOWN && nodeDirection != WAY_FORWARD) {
//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);
}
Expand Down Expand Up @@ -571,6 +582,7 @@ NIImporter_OpenStreetMap::insertEdge(Edge* e, int index, NBNode* from, NBNode* t
// 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) {
Expand Down Expand Up @@ -725,7 +737,7 @@ NIImporter_OpenStreetMap::insertEdge(Edge* e, int index, NBNode* from, NBNode* t
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 ? LaneSpreadFunction::RIGHT : LaneSpreadFunction::CENTER;
(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;
}
Expand Down Expand Up @@ -970,6 +982,14 @@ NIImporter_OpenStreetMap::NodesHandler::myStartElement(int element, const SUMOSA
myCurrentNode->railwayBufferStop = true;
} else if (key == "railway" && value.find("crossing") != std::string::npos) {
myCurrentNode->railwayCrossing = true;
} else if (key == "railway:signal:direction") {
if (value == "both") {
myCurrentNode->myRailDirection = WAY_BOTH;
} else if (value == "backward") {
myCurrentNode->myRailDirection = WAY_BACKWARD;
} else if (value == "forward") {
myCurrentNode->myRailDirection = WAY_FORWARD;
}
} else if (StringUtils::startsWith(key, "railway:signal") || (key == "railway" && value == "signal")) {
std::string kv = key + "=" + value;
std::string kglob = key + "=";
Expand Down Expand Up @@ -1500,8 +1520,12 @@ NIImporter_OpenStreetMap::EdgesHandler::myStartElement(int element, const SUMOSA
} else if (key == "railway:preferred_direction") {
if (value == "both") {
myCurrentEdge->myRailDirection = WAY_BOTH;
} else if (value == "backward") {
myCurrentEdge->myRailDirection = WAY_BACKWARD;
} else if (myCurrentEdge->myRailDirection == WAY_UNKNOWN) {
if (value == "backward") {
myCurrentEdge->myRailDirection = WAY_BACKWARD;
} else if (value == "forward") {
myCurrentEdge->myRailDirection = WAY_FORWARD;
}
}
} else if (key == "railway:bidirectional") {
if (value == "regular") {
Expand Down
26 changes: 15 additions & 11 deletions src/netimport/NIImporter_OpenStreetMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ class NIImporter_OpenStreetMap {
static void loadNetwork(const OptionsCont& oc, NBNetBuilder& nb);

protected:

/** @enum CycleWayType
* @brief details on the kind of cycleway along this road
*/
enum WayType {
WAY_NONE = 0,
WAY_FORWARD = 1,
WAY_BACKWARD = 2,
WAY_BOTH = WAY_FORWARD | WAY_BACKWARD,
WAY_UNKNOWN = 4
};

/** @brief An internal representation of an OSM-node
*/
struct NIOSMNode : public Parameterised {
Expand All @@ -83,6 +95,7 @@ class NIImporter_OpenStreetMap {
ptStopPosition(false), ptStopLength(0), name(""),
permissions(SVC_IGNORING),
positionMeters(std::numeric_limits<double>::max()),
myRailDirection(WAY_UNKNOWN),
node(nullptr) { }

/// @brief The node's id
Expand Down Expand Up @@ -115,6 +128,8 @@ class NIImporter_OpenStreetMap {
std::string position;
/// @brief position converted to m (using highest precision available)
double positionMeters;
/// @brief Information about the direction(s) of railway usage
WayType myRailDirection;
/// @brief the NBNode that was instantiated
NBNode* node;

Expand All @@ -132,17 +147,6 @@ class NIImporter_OpenStreetMap {
protected:


/** @enum CycleWayType
* @brief details on the kind of cycleway along this road
*/
enum WayType {
WAY_NONE = 0,
WAY_FORWARD = 1,
WAY_BACKWARD = 2,
WAY_BOTH = WAY_FORWARD | WAY_BACKWARD,
WAY_UNKNOWN = 4
};

enum ParkingType {
PARKING_NONE = 0,
PARKING_LEFT = 1,
Expand Down

0 comments on commit fc10775

Please sign in to comment.