30#define JUNCTION_TAZ_MISSING_HELP "\nSet option '--junction-taz' or load a TAZ-file"
44template<
class E,
class L,
class N>
49 std::vector<const E*>& into,
const std::string& rid,
bool isFrom,
bool& ok,
bool forceEdge =
false) {
51 WRITE_ERROR(
TL(
"Cannot convert geo-positions because the network has no geo-reference"));
66 if (best ==
nullptr) {
70 const E* bestEdge = &best->getEdge();
71 while (bestEdge->isInternal()) {
72 bestEdge = bestEdge->getSuccessors().front();
76 bestEdge =
getTaz(pos, bestEdge, isFrom);
80 if (bestEdge !=
nullptr) {
81 into.push_back(bestEdge);
87 if (positions.size() == 1 || into.empty() || into.back() != bestEdge) {
88 into.push_back(bestEdge);
115 const float cmin[2] = {(float) b.
xmin(), (float) b.
ymin()};
116 const float cmax[2] = {(float) b.
xmax(), (float) b.
ymax()};
117 std::set<const Named*> lanes;
119 t->
Search(cmin, cmax, sv);
121 double minDist = std::numeric_limits<double>::max();
122 const L* best =
nullptr;
123 for (
const Named* o : lanes) {
124 const L* cand =
static_cast<const L*
>(o);
125 if (!cand->allowsVehicleClass(vClass)) {
128 double dist = cand->getShape().distance2D(pos);
129 if (dist < minDist) {
139 if (closestEdge ==
nullptr) {
142 const N* fromJunction = closestEdge->getFromJunction();
143 const N* toJunction = closestEdge->getToJunction();
144 const bool fromCloser = (fromJunction->getPosition().distanceSquaredTo2D(pos) <
145 toJunction->getPosition().distanceSquaredTo2D(pos));
146 const E* fromSource =
retrieveEdge(fromJunction->getID() +
"-source");
147 const E* fromSink =
retrieveEdge(fromJunction->getID() +
"-sink");
148 const E* toSource =
retrieveEdge(toJunction->getID() +
"-source");
149 const E* toSink =
retrieveEdge(toJunction->getID() +
"-sink");
150 if (fromSource ==
nullptr || fromSink ==
nullptr) {
154 if (toSource ==
nullptr || toSink ==
nullptr) {
158 const bool fromPossible = isFrom ? fromSource->getSuccessors(vClass).size() > 0 : fromSink->getPredecessors().size() > 0;
159 const bool toPossible = isFrom ? toSource->getSuccessors(vClass).size() > 0 : toSink->getPredecessors().size() > 0;
161 if (fromCloser && fromPossible) {
163 return isFrom ? fromSource : fromSink;
164 }
else if (!fromCloser && toPossible) {
166 return isFrom ? toSource : toSink;
170 return isFrom ? fromSource : fromSink;
172 return isFrom ? toSource : toSink;
180 if (closestEdge ==
nullptr) {
183 std::vector<const E*> cands;
185 for (
const E* e : closestEdge->getPredecessors()) {
186 if (e->isTazConnector()) {
191 for (
const E* e : closestEdge->getSuccessors()) {
192 if (e->isTazConnector()) {
197 if (cands.size() == 0) {
201 if (cands.size() > 1) {
204 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)