Eclipse SUMO - Simulation of Urban MObility
NIXMLShapeHandler.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // Importer for static public transport information
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
23 #include <utils/geom/Position.h>
26 #include <netbuild/NBEdgeCont.h>
27 #include <netbuild/NBEdge.h>
28 
29 #include "NIXMLShapeHandler.h"
30 
31 // ===========================================================================
32 // method definitions
33 // ===========================================================================
34 
36  ShapeHandler("polgyon - file", sc, GeoConvHelper::getNumLoaded() == 0 ? nullptr : & GeoConvHelper::getLoaded()),
37  myEdgeCont(ec)
38 {}
39 
41 NIXMLShapeHandler::getLanePos(const std::string& poiID, const std::string& laneID, double lanePos, double lanePosLat) {
42  std::string edgeID;
43  int laneIndex;
44  NBHelpers::interpretLaneID(laneID, edgeID, laneIndex);
45  NBEdge* edge = myEdgeCont.retrieve(edgeID);
46  if (edge == 0 || laneIndex < 0 || edge->getNumLanes() <= laneIndex) {
47  WRITE_ERROR("Lane '" + laneID + "' to place poi '" + poiID + "' on is not known.");
48  return Position::INVALID;
49  }
50  if (lanePos < 0) {
51  lanePos = edge->getLength() + lanePos;
52  }
53  if (lanePos < 0 || lanePos > edge->getLength()) {
54  WRITE_WARNING("lane position " + toString(lanePos) + " for poi '" + poiID + "' is not valid.");
55  }
56  return edge->getLanes()[laneIndex].shape.positionAtOffset(lanePos, -lanePosLat);
57 }
58 
59 
60 
61 /****************************************************************************/
double getLength() const
Returns the computed length of the edge.
Definition: NBEdge.h:533
NIXMLShapeHandler(ShapeContainer &sc, const NBEdgeCont &ec)
The representation of a single edge during network building.
Definition: NBEdge.h:86
const NBEdgeCont & myEdgeCont
const std::vector< NBEdge::Lane > & getLanes() const
Returns the lane definitions.
Definition: NBEdge.h:644
Storage for geometrical objects.
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:239
The XML-Handler for network loading.
Definition: ShapeHandler.h:50
static methods for processing the coordinates conversion for the current net
Definition: GeoConvHelper.h:56
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
Position getLanePos(const std::string &poiID, const std::string &laneID, double lanePos, double lanePosLat)
get position for a given laneID (Has to be implemented in all child)
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:61
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:245
static void interpretLaneID(const std::string &lane_id, std::string &edge_id, int &index)
parses edge-id and index from lane-id
Definition: NBHelpers.cpp:121
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
Definition: NBEdgeCont.cpp:245
static const Position INVALID
used to indicate that a position is valid
Definition: Position.h:285