30#define JUNCTION_TAZ_MISSING_HELP "\nSet option '--junction-taz' or load a TAZ-file"
44template<
class E,
class L,
class N>
59 std::vector<const E*>& into,
const std::string& rid,
bool isFrom,
bool& ok,
bool forceEdge =
false) {
61 WRITE_ERROR(
TL(
"Cannot convert geo-positions because the network has no geo-reference"));
76 if (best ==
nullptr) {
80 const E* bestEdge = &best->getEdge();
81 while (bestEdge->isInternal()) {
82 bestEdge = bestEdge->getSuccessors().front();
86 bestEdge =
getTaz(pos, bestEdge, isFrom);
90 if (bestEdge !=
nullptr) {
91 into.push_back(bestEdge);
97 if (positions.size() == 1 || into.empty() || into.back() != bestEdge) {
98 into.push_back(bestEdge);
112 const float cmin[2] = {(float) b.
xmin(), (float) b.
ymin()};
113 const float cmax[2] = {(float) b.
xmax(), (float) b.
ymax()};
114 std::set<const Named*> lanes;
116 t->
Search(cmin, cmax, sv);
118 double minDist = std::numeric_limits<double>::max();
119 const L* best =
nullptr;
120 for (
const Named* o : lanes) {
121 const L* cand =
static_cast<const L*
>(o);
122 if (!cand->allowsVehicleClass(vClass)) {
125 double dist = cand->getShape().distance2D(pos);
126 if (dist < minDist) {
136 if (closestEdge ==
nullptr) {
139 const N* fromJunction = closestEdge->getFromJunction();
140 const N* toJunction = closestEdge->getToJunction();
141 const bool fromCloser = (fromJunction->getPosition().distanceSquaredTo2D(pos) <
142 toJunction->getPosition().distanceSquaredTo2D(pos));
143 const E* fromSource =
retrieveEdge(fromJunction->getID() +
"-source");
144 const E* fromSink =
retrieveEdge(fromJunction->getID() +
"-sink");
145 const E* toSource =
retrieveEdge(toJunction->getID() +
"-source");
146 const E* toSink =
retrieveEdge(toJunction->getID() +
"-sink");
147 if (fromSource ==
nullptr || fromSink ==
nullptr) {
151 if (toSource ==
nullptr || toSink ==
nullptr) {
155 const bool fromPossible = isFrom ? fromSource->getSuccessors(vClass).size() > 0 : fromSink->getPredecessors().size() > 0;
156 const bool toPossible = isFrom ? toSource->getSuccessors(vClass).size() > 0 : toSink->getPredecessors().size() > 0;
158 if (fromCloser && fromPossible) {
160 return isFrom ? fromSource : fromSink;
161 }
else if (!fromCloser && toPossible) {
163 return isFrom ? toSource : toSink;
167 return isFrom ? fromSource : fromSink;
169 return isFrom ? toSource : toSink;
177 if (closestEdge ==
nullptr) {
180 std::vector<const E*> cands;
182 for (
const E* e : closestEdge->getPredecessors()) {
183 if (e->isTazConnector()) {
188 for (
const E* e : closestEdge->getSuccessors()) {
189 if (e->isTazConnector()) {
194 if (cands.size() == 0) {
198 if (cands.size() > 1) {
201 return cands.front();
#define JUNCTION_TAZ_MISSING_HELP
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
int gPrecision
the precision for floating point outputs
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
A class that stores a 2D geometrical boundary.
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
double ymin() const
Returns minimum y-coordinate.
double xmin() const
Returns minimum x-coordinate.
Boundary & grow(double by)
extends the boundary by the given amount
double ymax() const
Returns maximum y-coordinate.
double xmax() const
Returns maximum x-coordinate.
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
bool x2cartesian_const(Position &from) const
Converts the given coordinate into a cartesian using the previous initialisation.
Provides utility functions for matching locations to edges (during route parsing)
double myMapMatchingDistance
virtual E * retrieveEdge(const std::string &id)=0
MapMatcher & operator=(const MapMatcher &s)=delete
Invalidated assignment operator.
const L * getClosestLane(const Position &pos, SUMOVehicleClass vClass, double distance=-1.)
find closest lane within distance for the given position or nullptr
virtual SumoRNG * getRNG()
MapMatcher(bool matchJunctions, bool matchTAZ, double matchDistance, MsgHandler *errorOutput)
MapMatcher(const MapMatcher &s)=delete
Invalidated copy constructor.
virtual void initLaneTree(NamedRTree *tree)=0
const E * getJunctionTaz(const Position &pos, const E *closestEdge, SUMOVehicleClass vClass, bool isFrom)
find closest junction taz given the closest edge
void parseGeoEdges(const PositionVector &positions, bool geo, SUMOVehicleClass vClass, std::vector< const E * > &into, const std::string &rid, bool isFrom, bool &ok, bool forceEdge=false)
MsgHandler * myErrorOutput
NamedRTree * myLaneTree
RTree for finding lanes.
const E * getTaz(const Position &pos, const E *closestEdge, bool isFrom)
find closest junction taz given the closest edge
NamedRTree * getLaneTree()
initialize lane-RTree
virtual void inform(std::string msg, bool addType=true)
adds a new error to the list
Allows to store the object; used as context while traveling the rtree in TraCI.
Base class for objects which have an id.
A RT-tree for efficient storing of SUMO's Named objects.
int Search(const float a_min[2], const float a_max[2], const Named::StoringVisitor &c) const
Find all within search rectangle.
A point in 2D or 3D with translation and scaling methods.
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)