~mil/mobroute

1343aeb717d3b7606062d6fd5cf5dde25b0bad1a — Miles Alan 2 months ago 8a1ba3b
Cleanup main godoc desc & examples
1 files changed, 80 insertions(+), 39 deletions(-)

M mobroutedoc.go
M mobroutedoc.go => mobroutedoc.go +80 -39
@@ 1,29 1,31 @@
/*
Package mobroute is a library allowing you to load GTFS data and perform
routing requests against a single or multiple sources. The core algorithm
is based on Connect-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 shows integrating Mobroute's runtime
function API variants in a mobile context (Android & Linux).

All public funcionality is exposed through the single mobroute package.
Functionality outside of this package should be considered to be
implementation details, unstable, and not used by end consumers.
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):
    This is a lower-level functions that allows you to store a single
    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() call.
    initial RTInitialize() function response.

  - Oneshot functions (prefixed with Oneshot):
    Allows you to run route & other requests in a single
    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


@@ 43,44 45,83 @@ Example:

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() {
	  // (1) Create a MobrouteRuntime:
	  mobrouteRuntime, err := mobroute.RTInitialize(&mobroute.MobrouteRuntimeConfig{
		})
	  if err != nil {
	    log.Fatal("Failed to initialize Mobroute Runtime")
	  }

	  // (2) Run a Routing Request:
	  routeResult, err := mobroute.RTRoute(
	  	mobrouteRuntime,
	  	&mobroute.RouteParams{

	  	},
	  )
	  if err != nil {
	  	log.Fatal("Error running RTRoute", err)
	  }

	  log.Println("Result:", routeResult)
		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")
		}

		// (2) 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("Error running RTRoute", err)
		}

		// (3) Display Result
		jsonLegs, _ := json.Marshal(*routeResult.RouteLegs)
		log.Println("Route Legs:", string(jsonLegs))
		log.Println("Viewable map URL:", *routeResult.MapURL)
	}

Example usage pattern for Onshot functionality:
Example usage pattern for Oneshot functionality:

	// Create a MobrouteRuntime
	mobrouteRuntime, err := mobroute.RTInitialize()
	if err != nil {
	  os.Fatal("Failed to initialize Mobroute Runtime")
	// 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:
		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)
	}

	// Perform a routing request

[Transito]: http://git.sr.ht/~mil/transito
*/