Documentation ¶
Overview ¶
Package mobroute is a library allowing you to load GTFS data and perform routing requests against a single or multiple feeds. The core algorithm is based on Connection-Scan-Algorithm (CSA) methodology. The algorithm operates offline once initial data is fetched; and is designed to be used locally and in mobile enviroments. Mobroute can be used to add public routing functionality to existing map & navigation apps or tools. For sample integrations see Transito which demonstrates integrating Mobroute's runtime library functions in a mobile context (Android & Linux).
All public funcionality is exposed through the single mobroute (git.sr.ht/~mil/mobroute) package. Functionality outside of this package should be considered to be implementation details, unstable, and not used by end consumers.
Runtime vs Oneshot Functions ¶
Library functionality is split into two categories:
Runtime functions (prefixed with RT): These are lower-level functions that allow you to store a single database connection between multiple function calls. All functions are based on a common stored database connection created via an initial RTInitialize() function response.
Oneshot functions (prefixed with Oneshot): These functions allows you to run route & other requests in a single call. This has the advantage allowing the entire request to be parameterized into single param request object. Doesn't pool the DB connection between requests. DB is opened at the start of each OneshotX function and closed at the end of the funtion
Building ¶
When building you must pass `-tags=sqlite_math_functions` to the `go build` command as this enables the underlying sqlite library to utilize math functions which Mobroute's core logic depends on.
Example:
go build -tags=sqlite_math_functions foo.go
Example Usages ¶
Example usage pattern for Runtime functionality:
// Build via: go build -tags=sqlite_math_functions example.go package main import ( "encoding/json" "git.sr.ht/~mil/mobroute" "log" ) func main() { var ( mobrouteRuntime *mobroute.MobrouteRuntime routeResult *mobroute.RouteResponse err error ) // (1) Create a MobrouteRuntime if mobrouteRuntime, err = mobroute.RTInitialize(&mobroute.MobrouteRuntimeConfig{}); err != nil { log.Fatal("Failed to initialize Mobroute Runtime: ", err) } // (2) Load GTFS Data (from Mobility Database Feed ID 1088); note (subsequent requests cached) if _, err := mobroute.RTDatabase( mobrouteRuntime, &mobroute.DatabaseParams{Op: "load", FeedIDs: []int{1088}}, ); err != nil { log.Fatal("Failed to load: ", err) } // (3) Compute GTFS-Optimized Tables; note (subsequent requests cached) if _, err := mobroute.RTDatabase( mobrouteRuntime, &mobroute.DatabaseParams{Op: "compute", FeedIDs: []int{1088}}, ); err != nil { log.Fatal("Failed to compute: ", err) } // (4) Run a Routing Request if routeResult, err = mobroute.RTRoute( mobrouteRuntime, &mobroute.RouteParams{ FeedIDs: []int{1088}, From: [2]float64{50.85728, 4.351426}, To: [2]float64{50.83214, 4.350534}, TransferCategories: []string{"f", "i"}, OutputFormats: []string{"legs", "mapurl"}, }, ); err != nil { log.Fatal("Failed to route: ", err) } // (5) Display Result jsonLegs, _ := json.Marshal(*routeResult.RouteLegs) log.Println("Route Legs:", string(jsonLegs)) log.Println("Viewable map URL:", *routeResult.MapURL) }
Example usage pattern for Oneshot functionality:
// Build via: go build -tags=sqlite_math_functions example.go package main import ( "encoding/json" "git.sr.ht/~mil/mobroute" "log" ) func main() { var ( routeResult *mobroute.RouteResponse err error ) // (1) Run a Routing Request (initializes, loads, computes, routes): if routeResult, err = mobroute.OneshotRoute(&mobroute.OneshotRouteRequest{ RouteParams: &mobroute.RouteParams{ FeedIDs: []int{1088}, From: [2]float64{50.85728, 4.351426}, To: [2]float64{50.83214, 4.350534}, TransferCategories: []string{"f", "i"}, OutputFormats: []string{"legs", "mapurl"}, }, }); err != nil { log.Fatal("Error running RTRoute", err) } // (2) Display Result jsonLegs, _ := json.Marshal(*routeResult.RouteLegs) log.Println("Route Legs:", string(jsonLegs)) log.Println("Viewable map URL:", *routeResult.MapURL) }
Index ¶
- type DatabaseParams
- type DatabaseResponse
- type DatabaseqParams
- type DatabaseqResponse
- type MobrouteRuntime
- type MobrouteRuntimeConfig
- type MobsqlRuntimeConfig
- type OneshotDatabaseRequest
- type OneshotDatabaseqRequest
- type OneshotRouteRequest
- type OneshotScheduleRequest
- type OneshotStopsRequest
- type RouteDiagnostics
- type RouteLeg
- type RouteParams
- type RouteResponse
- type RouteStopDetails
- type ScheduleParams
- type ScheduleResponse
- type StopsParams
- type StopsResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DatabaseResponse ¶ added in v0.7.0
type DatabaseResponse = apirtdatabase.DatabaseResponse
TODO
func OneshotDatabase ¶ added in v0.7.0
func OneshotDatabase(r *OneshotDatabaseRequest) (*DatabaseResponse, error)
TODO
func RTDatabase ¶ added in v0.7.0
func RTDatabase(runtime *MobrouteRuntime, paramsGiven *DatabaseParams) (*DatabaseResponse, error)
TODO
type DatabaseqResponse ¶ added in v0.7.0
type DatabaseqResponse = apirtdatabaseq.DatabaseqResponse
TODO
func OneshotDatabaseq ¶ added in v0.7.0
func OneshotDatabaseq(r *OneshotDatabaseqRequest) (*DatabaseqResponse, error)
TODO
func RTDatabaseq ¶ added in v0.7.0
func RTDatabaseq(runtime *MobrouteRuntime, paramsGiven *DatabaseqParams) (*DatabaseqResponse, error)
TODO
type MobrouteRuntime ¶ added in v0.6.0
type MobrouteRuntime = apirtinit.MobrouteRuntime
MobrouteRuntime contains the database connection & MobsqlRuntime.
func RTInitialize ¶ added in v0.6.0
func RTInitialize(params *MobrouteRuntimeConfig) (*MobrouteRuntime, error)
RTInitialize initializes a MobrouteRuntime which contains a passthrough to the MobsqlRuntime & some additional metadata.
type MobrouteRuntimeConfig ¶ added in v0.6.0
type MobrouteRuntimeConfig = apirtinit.MobrouteRuntimeConfig
MobrouteRuntimeConfig contains the MobsqlRuntimeConfig & potentially in the future some other Mobroute-specific properties for the common DB connection & Mobroute params.
type MobsqlRuntimeConfig ¶ added in v0.6.0
type MobsqlRuntimeConfig = apirtinit.MobsqlRuntimeConfig
MobsqlRuntimeConfig is just an alias for Mobsql's RuntimeConfig, see mobsql.RuntimeConfig for further documentation.
type OneshotDatabaseRequest ¶ added in v0.7.0
type OneshotDatabaseRequest = apioneshot.OneshotDatabaseRequest
TODO
type OneshotDatabaseqRequest ¶ added in v0.7.0
type OneshotDatabaseqRequest = apioneshot.OneshotDatabaseqRequest
TODO
type OneshotRouteRequest ¶ added in v0.6.0
type OneshotRouteRequest = apioneshot.OneshotRouteRequest
OneShotRouteRequest groups both the MobrouteRuntimeConfig and RouteParams
type OneshotScheduleRequest ¶ added in v0.7.0
type OneshotScheduleRequest = apioneshot.OneshotScheduleRequest
TODO
type OneshotStopsRequest ¶ added in v0.7.0
type OneshotStopsRequest = apioneshot.OneshotStopsRequest
TODO
type RouteDiagnostics ¶ added in v0.6.0
type RouteDiagnostics = diagnosticst.RouteDiagnostics
RouteDiagnostics contains diagnostic information for a routing request measuring number of seconds for specific parts of the pipeline, memory usage, and meta route information.
type RouteLeg ¶ added in v0.6.0
type RouteLeg = formatterlegs.RouteLeg
RouteLeg represents a 'leg' in a route which may be either of transfer, walk, or trip type (see the LegType field).
The Leg* properties are always present, Trip*, Transfer*, and Walk* fields may be nonnil depending on the LegType field.
type RouteParams ¶
type RouteParams = apirtroute.RouteParams
RouteParams contains the parameters for a given route request.
type RouteResponse ¶
type RouteResponse = apirtroute.RouteResponse
RouteResponse is the response for a successful routing request.
func OneshotRoute ¶ added in v0.6.0
func OneshotRoute(r *OneshotRouteRequest) (*RouteResponse, error)
OneshotRoute performs routing in a one-shot / single function fashion. All parameters for the entire request are passed in the OneShotRouteRequest.
func RTRoute ¶ added in v0.6.0
func RTRoute(runtime *MobrouteRuntime, paramsGiven *RouteParams) (*RouteResponse, error)
Route performs the routing logic, extracting from the DB the required data for CSA, running the CSA algorithm, going back to the DB to pull a few extra fields for presentation, and finally formatting the data into route legs for easy consumption.
type RouteStopDetails ¶ added in v0.6.0
type RouteStopDetails = formatterlegs.RouteStopDetails
RouteStopDetails represents a stop within a trip.
type ScheduleResponse ¶ added in v0.7.0
type ScheduleResponse = apirtschedule.ScheduleResponse
TODO
func OneshotSchedule ¶ added in v0.7.0
func OneshotSchedule(r *OneshotScheduleRequest) (*ScheduleResponse, error)
TODO
func RTSchedule ¶ added in v0.7.0
func RTSchedule(runtime *MobrouteRuntime, paramsGiven *ScheduleParams) (*ScheduleResponse, error)
TODO
type StopsResponse ¶ added in v0.7.0
type StopsResponse = apirtstops.StopsResponse
TODO
func OneshotStops ¶ added in v0.7.0
func OneshotStops(r *OneshotStopsRequest) (*StopsResponse, error)
TODO
func RTStops ¶ added in v0.7.0
func RTStops(runtime *MobrouteRuntime, paramsGiven *StopsParams) (*StopsResponse, error)
TODO
Directories ¶
Path | Synopsis |
---|---|
api
|
|
apioneshot
Package apioneshot defines oneshot functions which allows you to run particular Mobroute commands in single 'oneshot' function call rather then manually setting up a MobrouteRuntime (via RuntimeInitialize).
|
Package apioneshot defines oneshot functions which allows you to run particular Mobroute commands in single 'oneshot' function call rather then manually setting up a MobrouteRuntime (via RuntimeInitialize). |
apirtinit
Package apirtinit contains functionality for initializing a Mobroute Runtime.
|
Package apirtinit contains functionality for initializing a Mobroute Runtime. |
Package main is the CLI interface for mobroute consuming the mobroute API.
|
Package main is the CLI interface for mobroute consuming the mobroute API. |
csa_test
|
|
Package dbquery contains queries that operate on MR's 'DbConnection' type.
|
Package dbquery contains queries that operate on MR's 'DbConnection' type. |
Package dbstubquery provides SQL 'stubs' loader fns that aren't (directly) used by the routing logic (apirtroute) but are used implictily by larger queries.
|
Package dbstubquery provides SQL 'stubs' loader fns that aren't (directly) used by the routing logic (apirtroute) but are used implictily by larger queries. |
Package dbt (short for database type) contains the types for data extracted by the database by the dbquery package.
|
Package dbt (short for database type) contains the types for data extracted by the database by the dbquery package. |
util
|
|