29 #define JUNCTION_TAZ_MISSING_HELP "\nSet option '--junction-taz' or load a TAZ-file"
43 template<
class E,
class L,
class N>
57 std::vector<const E*>& into,
const std::string& rid,
bool isFrom,
bool& ok) {
59 WRITE_ERROR(
TL(
"Cannot convert geo-positions because the network has no geo-reference"));
73 if (best ==
nullptr) {
79 if (best !=
nullptr) {
84 if (positions.size() == 1 || into.empty() || into.back() != best) {
99 const float cmin[2] = {(float) b.
xmin(), (float) b.
ymin()};
100 const float cmax[2] = {(float) b.
xmax(), (float) b.
ymax()};
101 std::set<const Named*> lanes;
103 t->
Search(cmin, cmax, sv);
105 double minDist = std::numeric_limits<double>::max();
106 const L* best =
nullptr;
107 for (
const Named* o : lanes) {
108 const L* cand =
static_cast<const L*
>(o);
109 if (!cand->allowsVehicleClass(vClass)) {
112 double dist = cand->getShape().distance2D(pos);
113 if (dist < minDist) {
118 if (best ==
nullptr) {
121 const E* bestEdge = &best->getEdge();
122 while (bestEdge->isInternal()) {
123 bestEdge = bestEdge->getSuccessors().front();
131 if (closestEdge ==
nullptr) {
134 const N* fromJunction = closestEdge->getFromJunction();
135 const N* toJunction = closestEdge->getToJunction();
136 const bool fromCloser = (fromJunction->getPosition().distanceSquaredTo2D(pos) <
137 toJunction->getPosition().distanceSquaredTo2D(pos));
138 const E* fromSource =
retrieveEdge(fromJunction->getID() +
"-source");
139 const E* fromSink =
retrieveEdge(fromJunction->getID() +
"-sink");
140 const E* toSource =
retrieveEdge(toJunction->getID() +
"-source");
141 const E* toSink =
retrieveEdge(toJunction->getID() +
"-sink");
142 if (fromSource ==
nullptr || fromSink ==
nullptr) {
146 if (toSource ==
nullptr || toSink ==
nullptr) {
150 const bool fromPossible = isFrom ? fromSource->getSuccessors(vClass).size() > 0 : fromSink->getPredecessors().size() > 0;
151 const bool toPossible = isFrom ? toSource->getSuccessors(vClass).size() > 0 : toSink->getPredecessors().size() > 0;
153 if (fromCloser && fromPossible) {
155 return isFrom ? fromSource : fromSink;
156 }
else if (!fromCloser && toPossible) {
158 return isFrom ? toSource : toSink;
162 return isFrom ? fromSource : fromSink;
164 return isFrom ? toSource : toSink;
#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(bool matchJunctions, double matchDistance, MsgHandler *errorOutput)
const E * getClosestEdge(const Position &pos, double distance, SUMOVehicleClass vClass)
find closest edge within distance for the given position or nullptr
void parseGeoEdges(const PositionVector &positions, bool geo, SUMOVehicleClass vClass, std::vector< const E * > &into, const std::string &rid, bool isFrom, bool &ok)
MapMatcher & operator=(const MapMatcher &s)=delete
Invalidated assignment operator.
NamedRTree * getLaneTree()
initialize lane-RTree
MapMatcher(const MapMatcher &s)=delete
Invalidated copy constructor.
const E * getJunctionTaz(const Position &pos, const E *closestEdge, SUMOVehicleClass vClass, bool isFrom)
find closest junction taz given the closest edge
virtual void initLaneTree(NamedRTree *tree)=0
MsgHandler * myErrorOutput
NamedRTree * myLaneTree
RTree for finding lanes.
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.