libosmscout  0.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules
osmscout::SimpleRoutingService Class Reference

#include <SimpleRoutingService.h>

+ Inheritance diagram for osmscout::SimpleRoutingService:

Public Member Functions

RoutingResult CalculateRouteViaCoords (RoutingProfile &profile, const std::vector< GeoCoord > &via, const Distance &radius, const RoutingParameter &parameter)
 Calculate a route going through all the via points. More...
 
void Close ()
 Close the routing service. More...
 
void DumpStatistics ()
 
RoutePositionResult GetClosestRoutableNode (const GeoCoord &coord, const RoutingProfile &profile, const Distance &radius) const
 Returns the closest routable object (area or way) relative to the given coordinate. More...
 
ClosestRoutableObjectResult GetClosestRoutableObject (const GeoCoord &location, Vehicle vehicle, const Distance &maxRadius)
 Returns the closest routeable object (area or way) relative to the given coordinate. More...
 
std::map< DatabaseId, std::string > GetDatabaseMapping () const override
 
RoutePositionResult GetRoutableNode (const ObjectFileRef &objRef, const RoutingProfile &profile) const
 Return routable node on specific object, when this object is routable and usable by provided profile. More...
 
TypeConfigRef GetTypeConfig () const
 Returns the type configuration of the underlying db instance. More...
 
bool IsOpen () const
 Returns true, if the routing service has been successfully opened, else false. More...
 
bool Open ()
 Opens the routing service. More...
 
 SimpleRoutingService (const DatabaseRef &database, const RouterParameter &parameter, const std::string &filenamebase)
 Create a new instance of the routing service. More...
 
 ~SimpleRoutingService () override
 
- Public Member Functions inherited from osmscout::AbstractRoutingService< RoutingProfile >
 AbstractRoutingService (const RouterParameter &parameter)
 
RoutingResult CalculateRoute (RoutingProfile &state, const RoutePosition &start, const RoutePosition &target, const std::optional< osmscout::Bearing > &bearing, const RoutingParameter &parameter)
 Calculate a route. More...
 
virtual std::map< DatabaseId, std::string > GetDatabaseMapping () const=0
 Get current mapping of DatabaseId to db path than be used later for lookup objects in description. More...
 
RoutePointsResult TransformRouteDataToPoints (const RouteData &data)
 Transforms the route into a list of points. More...
 
RouteDescriptionResult TransformRouteDataToRouteDescription (const RouteData &data)
 Transform the route into a RouteDescription. More...
 
RouteWayResult TransformRouteDataToWay (const RouteData &data)
 Transforms the route into a Way (with empty type) More...
 
 ~AbstractRoutingService () override
 
- Public Member Functions inherited from osmscout::RoutingService
 RoutingService ()
 
virtual ~RoutingService ()
 

Protected Member Functions

bool CanUse (const RoutingProfile &profile, DatabaseId database, const RouteNode &routeNode, size_t pathIndex) override
 
bool CanUseBackward (const RoutingProfile &profile, const DatabaseId &database, const WayRef &way) override
 
bool CanUseForward (const RoutingProfile &profile, const DatabaseId &database, const WayRef &way) override
 
bool GetAreaByOffset (const DBFileOffset &offset, AreaRef &area) override
 
bool GetAreasByOffset (const std::set< DBFileOffset > &areaOffsets, std::unordered_map< DBFileOffset, AreaRef > &areaMap) override
 
double GetCostLimit (const RoutingProfile &profile, DatabaseId database, const Distance &targetDistance) override
 
double GetCosts (const RoutingProfile &profile, DatabaseId database, const RouteNode &routeNode, size_t inPathIndex, size_t outPathIndex) override
 
double GetCosts (const RoutingProfile &profile, DatabaseId database, const WayRef &way, const Distance &wayLength) override
 
std::string GetCostString (const RoutingProfile &profile, DatabaseId database, double cost) const override
 
double GetEstimateCosts (const RoutingProfile &profile, DatabaseId database, const Distance &targetDistance) override
 
std::vector< DBIdGetNodeTwins (const RoutingProfile &state, DatabaseId database, Id id) override
 
bool GetRouteNode (const DBId &id, RouteNodeRef &node) override
 Return the route node for the given db offset. More...
 
bool GetRouteNodes (const std::set< DBId > &routeNodeIds, std::unordered_map< DBId, RouteNodeRef > &routeNodeMap) override
 
double GetUTurnCost (const RoutingProfile &profile, const DatabaseId databaseId) override
 
Vehicle GetVehicle (const RoutingProfile &profile) override
 
bool GetWayByOffset (const DBFileOffset &offset, WayRef &way) override
 
bool GetWaysByOffset (const std::set< DBFileOffset > &wayOffsets, std::unordered_map< DBFileOffset, WayRef > &wayMap) override
 
bool ResolveRouteDataJunctions (RouteData &route) override
 
- Protected Member Functions inherited from osmscout::AbstractRoutingService< RoutingProfile >
void AddNodes (RouteData &route, DatabaseId database, Id startNodeId, size_t startNodeIndex, const ObjectFileRef &object, size_t idCount, bool oneway, size_t targetNodeIndex)
 
bool GetRNode (const RoutingProfile &state, const RoutePosition &position, const WayRef &way, size_t routeNodeIndex, const RouteNodeRef &routeNode, const GeoCoord &startCoord, const GeoCoord &targetCoord, RNodeRef &node)
 
void GetStartBackwardRouteNode (const RoutingProfile &state, const DatabaseId &database, const WayRef &way, size_t nodeIndex, RouteNodeRef &routeNode, size_t &routeNodeIndex)
 
void GetStartForwardRouteNode (const RoutingProfile &state, const DatabaseId &database, const WayRef &way, size_t nodeIndex, RouteNodeRef &routeNode, size_t &routeNodeIndex)
 
bool GetStartNodes (const RoutingProfile &state, const RoutePosition &position, GeoCoord &startCoord, const GeoCoord &targetCoord, RouteNodeRef &forwardRouteNode, RouteNodeRef &backwardRouteNode, RNodeRef &forwardRNode, RNodeRef &backwardRNode)
 The start position is at the given position defined by an object and the index of the node within the object. More...
 
void GetTargetBackwardRouteNode (const RoutingProfile &state, const DatabaseId &database, const WayRef &way, size_t nodeIndex, RouteNodeRef &routeNode)
 Return the route node that allows navigating to the given node in backward direction. More...
 
void GetTargetForwardRouteNode (const RoutingProfile &state, const DatabaseId &database, const WayRef &way, size_t nodeIndex, RouteNodeRef &routeNode)
 Return the route node that allows navigating to the given node in forward direction. More...
 
bool GetTargetNodes (const RoutingProfile &state, const RoutePosition &position, GeoCoord &targetCoord, RouteNodeRef &forwardNode, RouteNodeRef &backwardNode)
 The target position is at the given position defined by an object and the index of the node within the object. More...
 
bool GetWayStartNodes (const RoutingProfile &state, const RoutePosition &position, GeoCoord &startCoord, const GeoCoord &targetCoord, RouteNodeRef &forwardRouteNode, RouteNodeRef &backwardRouteNode, RNodeRef &forwardRNode, RNodeRef &backwardRNode)
 The start position is at the given way and the index of the node within the object. More...
 
bool GetWayTargetNodes (const RoutingProfile &state, const RoutePosition &position, GeoCoord &targetCoord, RouteNodeRef &forwardNode, RouteNodeRef &backwardNode)
 The target position is at the given position defined by an object and the index of the node within the object. More...
 
void ResolveRNodeChainToList (const RNode &finalRouteNode, const ClosedSet &closedSet, std::list< VNode > &nodes)
 
bool ResolveRNodesToRouteData (const RoutingProfile &state, const std::list< VNode > &nodes, const RoutePosition &start, const RoutePosition &target, RouteData &route)
 
bool RestrictInitialUTurn (const RoutingProfile &state, const Bearing &vehicleBearing, const RoutePosition &start, RNodeRef startForwardNode, RNodeRef startBackwardNode)
 
virtual bool WalkPaths (const RoutingProfile &state, RNodeRef &current, RouteNodeRef &currentRouteNode, OpenList &openList, OpenMap &openMap, ClosedSet &closedSet, RoutingResult &result, const RoutingParameter &parameter, const GeoCoord &targetCoord, const Vehicle &vehicle, size_t &nodesIgnoredCount, Distance &currentMaxDistance, const Distance &overallDistance, const double &costLimit)
 
virtual bool WalkToOtherDatabases (const RoutingProfile &state, RNodeRef &current, RouteNodeRef &currentRouteNode, OpenList &openList, OpenMap &openMap, const ClosedSet &closedSet)
 

Additional Inherited Members

- Static Public Member Functions inherited from osmscout::RoutingService
static std::string GetData2Filename (const std::string &filenamebase)
 
static std::string GetDataFilename (const std::string &filenamebase)
 
static std::string GetIndexFilename (const std::string &filenamebase)
 
- Static Public Attributes inherited from osmscout::RoutingService
static const char *const DEFAULT_FILENAME_BASE = "router"
 Relative filebase name for touting data as generated by default by the importer. More...
 
static const char *const FILENAME_INTERSECTIONS_DAT = "intersections.dat"
 Relative filename of the intersection data file. More...
 
static const char *const FILENAME_INTERSECTIONS_IDX = "intersections.idx"
 Relative filename of the intersection index file. More...
 
- Protected Types inherited from osmscout::RoutingService
using ClosedSet = std::unordered_set< VNode, ClosedNodeHasher >
 
using OpenList = std::set< RNodeRef, RNodeCostCompare >
 
using OpenListRef = std::set< RNodeRef, RNodeCostCompare >::iterator
 
using OpenMap = std::unordered_map< DBId, OpenListRef >
 
using RNodeRef = std::shared_ptr< RNode >
 
- Protected Attributes inherited from osmscout::AbstractRoutingService< RoutingProfile >
bool debugPerformance
 

Detailed Description

The RoutingService implements functionality in the context of routing. The following functions are available:

  • Calculation of a route from a start node to a target node
  • Transformation of the resulting route to a Way
  • Transformation of the resulting route to a simple list of points
  • Transformation of the resulting route to a routing description with is the base for further transformations to a textual or visual description of the route
  • Returning the closest route-able node to given geolocation

Constructor & Destructor Documentation

◆ SimpleRoutingService()

osmscout::SimpleRoutingService::SimpleRoutingService ( const DatabaseRef database,
const RouterParameter parameter,
const std::string &  filenamebase 
)

Create a new instance of the routing service.

Parameters
databaseA valid reference to a db instance
parameterAn instance to the parameter object holding further paramterization

◆ ~SimpleRoutingService()

osmscout::SimpleRoutingService::~SimpleRoutingService ( )
override

References Close().

Member Function Documentation

◆ CalculateRouteViaCoords()

RoutingResult osmscout::SimpleRoutingService::CalculateRouteViaCoords ( RoutingProfile profile,
const std::vector< GeoCoord > &  via,
const Distance radius,
const RoutingParameter parameter 
)

◆ CanUse()

bool osmscout::SimpleRoutingService::CanUse ( const RoutingProfile profile,
DatabaseId  database,
const RouteNode routeNode,
size_t  pathIndex 
)
overrideprotectedvirtual

◆ CanUseBackward()

bool osmscout::SimpleRoutingService::CanUseBackward ( const RoutingProfile profile,
const DatabaseId database,
const WayRef way 
)
overrideprotectedvirtual

◆ CanUseForward()

bool osmscout::SimpleRoutingService::CanUseForward ( const RoutingProfile profile,
const DatabaseId database,
const WayRef way 
)
overrideprotectedvirtual

◆ Close()

void osmscout::SimpleRoutingService::Close ( )

Close the routing service.

References osmscout::RoutingDatabase::Close().

Referenced by ~SimpleRoutingService().

◆ DumpStatistics()

void osmscout::SimpleRoutingService::DumpStatistics ( )

◆ GetAreaByOffset()

bool osmscout::SimpleRoutingService::GetAreaByOffset ( const DBFileOffset offset,
AreaRef area 
)
overrideprotectedvirtual

◆ GetAreasByOffset()

bool osmscout::SimpleRoutingService::GetAreasByOffset ( const std::set< DBFileOffset > &  areaOffsets,
std::unordered_map< DBFileOffset, AreaRef > &  areaMap 
)
overrideprotectedvirtual

◆ GetClosestRoutableNode()

RoutePositionResult osmscout::SimpleRoutingService::GetClosestRoutableNode ( const GeoCoord coord,
const RoutingProfile profile,
const Distance radius 
) const

Returns the closest routable object (area or way) relative to the given coordinate.

The result should be use as input for the router to define routing start or end point.

Note
The returned node may in fact not be routable, it is just the closest node to the given position on a routable way or area.
The actual object may not be within the given radius due to internal search index resolution.
Parameters
coordcoordinate of the search center
profileRouting profile to use. It defines Vehicle to use and allowed objects.
radiusThe maximum radius to search in from the search center
Returns
A reference to a node on a way or area that is routable (if returned route position is valid)

References osmscout::GeoBox::BoxByCenterAndRadius(), osmscout::RoutingProfile::CanUse(), osmscout::DistanceToSegment(), osmscout::Log::Error(), osmscout::GetEllipsoidalDistance(), osmscout::GeoCoord::GetLat(), osmscout::GeoCoord::GetLon(), osmscout::RoutingProfile::GetVehicle(), osmscout::log, and osmscout::TypeInfoSet::Set().

Referenced by CalculateRouteViaCoords().

◆ GetClosestRoutableObject()

ClosestRoutableObjectResult osmscout::SimpleRoutingService::GetClosestRoutableObject ( const GeoCoord location,
Vehicle  vehicle,
const Distance maxRadius 
)

Returns the closest routeable object (area or way) relative to the given coordinate.

The result should be use for typical "object you are traveling on" information as used by routing applications.

Note
The returned node may in fact not be routable, it is just the closest node to the given position on a routable way or area.
The actual object may not be within the given radius due to internal search index resolution.
This is a simple solution that does not track any spast state. A better implementation should hold on recently travels coordinates and ways or areas and do some tolerance error handling in case of GPS jitter effects.
Parameters
coordcoordinate of the search center
vehicleThe vehicle to use
maxRadiusThe maximum radius to search in from the search center
Returns
A convinient description of the clostest routable object (if valid)

References osmscout::TypeInfoSet::Empty(), osmscout::AreaRegionSearchResult::GetAreaResults(), osmscout::FeatureLabelReader< F, V >::GetLabel(), osmscout::WayRegionSearchResult::GetWayResults(), osmscout::Distance::Max(), and osmscout::TypeInfoSet::Set().

◆ GetCostLimit()

double osmscout::SimpleRoutingService::GetCostLimit ( const RoutingProfile profile,
DatabaseId  database,
const Distance targetDistance 
)
overrideprotectedvirtual

◆ GetCosts() [1/2]

double osmscout::SimpleRoutingService::GetCosts ( const RoutingProfile profile,
DatabaseId  database,
const RouteNode routeNode,
size_t  inPathIndex,
size_t  outPathIndex 
)
overrideprotectedvirtual

◆ GetCosts() [2/2]

double osmscout::SimpleRoutingService::GetCosts ( const RoutingProfile profile,
DatabaseId  database,
const WayRef way,
const Distance wayLength 
)
overrideprotectedvirtual

◆ GetCostString()

std::string osmscout::SimpleRoutingService::GetCostString ( const RoutingProfile profile,
DatabaseId  database,
double  cost 
) const
overrideprotectedvirtual

◆ GetDatabaseMapping()

std::map< DatabaseId, std::string > osmscout::SimpleRoutingService::GetDatabaseMapping ( ) const
override

◆ GetEstimateCosts()

double osmscout::SimpleRoutingService::GetEstimateCosts ( const RoutingProfile profile,
DatabaseId  database,
const Distance targetDistance 
)
overrideprotectedvirtual

◆ GetNodeTwins()

std::vector< DBId > osmscout::SimpleRoutingService::GetNodeTwins ( const RoutingProfile state,
DatabaseId  database,
Id  id 
)
overrideprotectedvirtual

◆ GetRoutableNode()

RoutePositionResult osmscout::SimpleRoutingService::GetRoutableNode ( const ObjectFileRef objRef,
const RoutingProfile profile 
) const

Return routable node on specific object, when this object is routable and usable by provided profile.

Parameters
objRef
profileRouting profile to use. It defines Vehicle to use and allowed objects.
Returns
routable node on object (way)

References osmscout::RoutingProfile::CanUse(), osmscout::Log::Error(), osmscout::ObjectFileRef::GetFileOffset(), osmscout::ObjectFileRef::GetName(), osmscout::GetSphericalDistance(), osmscout::ObjectFileRef::IsWay(), osmscout::log, and osmscout::Distance::Zero().

◆ GetRouteNode()

bool osmscout::SimpleRoutingService::GetRouteNode ( const DBId id,
RouteNodeRef node 
)
overrideprotectedvirtual

Return the route node for the given db offset.

Parameters
idDatabase and Offset in given db
nodeNode instance to write the result back
Returns
True, if the node could be loaded, else false

Implements osmscout::AbstractRoutingService< RoutingProfile >.

References osmscout::RoutingDatabase::GetRouteNode().

◆ GetRouteNodes()

bool osmscout::SimpleRoutingService::GetRouteNodes ( const std::set< DBId > &  routeNodeIds,
std::unordered_map< DBId, RouteNodeRef > &  routeNodeMap 
)
overrideprotectedvirtual

◆ GetTypeConfig()

TypeConfigRef osmscout::SimpleRoutingService::GetTypeConfig ( ) const

Returns the type configuration of the underlying db instance.

Returns
A valid type configuration or null if the db is not valid

◆ GetUTurnCost()

double osmscout::SimpleRoutingService::GetUTurnCost ( const RoutingProfile profile,
const DatabaseId  databaseId 
)
overrideprotectedvirtual

◆ GetVehicle()

Vehicle osmscout::SimpleRoutingService::GetVehicle ( const RoutingProfile profile)
overrideprotectedvirtual

◆ GetWayByOffset()

bool osmscout::SimpleRoutingService::GetWayByOffset ( const DBFileOffset offset,
WayRef way 
)
overrideprotectedvirtual

◆ GetWaysByOffset()

bool osmscout::SimpleRoutingService::GetWaysByOffset ( const std::set< DBFileOffset > &  wayOffsets,
std::unordered_map< DBFileOffset, WayRef > &  wayMap 
)
overrideprotectedvirtual

◆ IsOpen()

bool osmscout::SimpleRoutingService::IsOpen ( ) const

Returns true, if the routing service has been successfully opened, else false.

Returns
True, if the routing service has been successfully opened

◆ Open()

bool osmscout::SimpleRoutingService::Open ( )

Opens the routing service.

This loads the routing graph for the given vehicle

Returns
false on error, else true

References osmscout::RoutingDatabase::Open().

◆ ResolveRouteDataJunctions()

bool osmscout::SimpleRoutingService::ResolveRouteDataJunctions ( RouteData route)
overrideprotectedvirtual

The documentation for this class was generated from the following files: