Documentation ¶
Overview ¶
Package osrm provides a client for measuring distances and durations.
An OSRM client requests distance and duration data from an OSRM server. It makes requests to construct a matrix measure.
These measures implement route.ByIndex.
Index ¶
- func DistanceDurationMatrices(c Client, points []route.Point, parallelQueries int) (distance, duration route.ByIndex, err error)
- func DistanceMatrix(c Client, points []route.Point, parallelQueries int) (route.ByIndex, error)
- func DurationMatrix(c Client, points []route.Point, parallelQueries int) (route.ByIndex, error)
- func Polyline(c Client, points []route.Point) (string, []string, error)
- type Client
- type ClientOption
- type Endpoint
- type Leg
- type Route
- type RouteResponse
- type Step
- type TableOptions
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DistanceDurationMatrices ¶
func DistanceDurationMatrices( c Client, points []route.Point, parallelQueries int, ) ( distance, duration route.ByIndex, err error, )
DistanceDurationMatrices fetches a distance and duration table from an OSRM server and returns a Matrix of each. ParallelQueries specifies the number of parallel queries to be made, pass 0 to calculate a default, based on the number of points given.
Example ¶
Please note that this example does not define an output as it requires a server and is here for illustrative purposes only.
package main import ( "fmt" "github.com/nextmv-io/sdk/route" "github.com/nextmv-io/sdk/route/osrm" ) func main() { client := osrm.DefaultClient( "YOUR-OSRM-SERVER e.g.:http://localhost:5000", true, ) points := []route.Point{ {-123.1041788, 43.9965908}, {-123.1117056, 44.0568198}, } dist, dur, err := osrm.DistanceDurationMatrices(client, points, 0) if err != nil { panic(err) } costDist := dist.Cost(0, 1) costDur := dur.Cost(0, 1) fmt.Println(costDist) fmt.Println(costDur) }
Output:
func DistanceMatrix ¶
DistanceMatrix makes a request for a distance table from an OSRM server and returns a Matrix. ParallelQueries specifies the number of parallel queries to be made, pass 0 to calculate a default, based on the number of points given.
Example ¶
Please note that this example does not define an output as it requires a server and is here for illustrative purposes only.
package main import ( "fmt" "github.com/nextmv-io/sdk/route" "github.com/nextmv-io/sdk/route/osrm" ) func main() { client := osrm.DefaultClient( "YOUR-OSRM-SERVER e.g.:http://localhost:5000", true, ) points := []route.Point{ {-123.1041788, 43.9965908}, {-123.1117056, 44.0568198}, } dist, err := osrm.DistanceMatrix(client, points, 0) if err != nil { panic(err) } cost := dist.Cost(0, 1) fmt.Println(cost) }
Output:
func DurationMatrix ¶
DurationMatrix makes a request for a duration table from an OSRM server and returns a Matrix. ParallelQueries specifies the number of parallel queries to be made, pass 0 to calculate a default, based on the number of points given.
Example ¶
Please note that this example does not define an output as it requires a server and is here for illustrative purposes only.
package main import ( "fmt" "github.com/nextmv-io/sdk/route" "github.com/nextmv-io/sdk/route/osrm" ) func main() { client := osrm.DefaultClient( "YOUR-OSRM-SERVER e.g.:http://localhost:5000", true, ) points := []route.Point{ {-123.1041788, 43.9965908}, {-123.1117056, 44.0568198}, } dur, err := osrm.DurationMatrix(client, points, 0) if err != nil { panic(err) } cost := dur.Cost(0, 1) fmt.Println(cost) }
Output:
Types ¶
type Client ¶
type Client interface { // Table requests a distance and/or duration table from an OSRM server. Table( points []route.Point, opts ...TableOptions, ) ( distance, duration [][]float64, err error, ) // Get performs a GET against the OSRM server returning the response // body and an error. Get(uri string) ([]byte, error) // SnapRadius limits snapping a point to the street network to given radius // in meters. // Setting the snap radius to a value = 0 results in an unlimited snapping // radius. SnapRadius(radius int) error // ScaleFactor is used in conjunction with duration calculations. Scales the // table duration values by this number. This does not affect distances. ScaleFactor(factor float64) error // MaxTableSize should be configured with the same value as the OSRM // server's max-table-size setting, default is 100 MaxTableSize(size int) error // Polyline requests polylines for the given points. The first parameter // returns a polyline from start to end and the second parameter returns a // list of polylines, one per leg. Polyline(points []route.Point) (string, []string, error) }
Client represents an OSRM client.
func DefaultClient ¶
DefaultClient creates a new OSRM Client.
Example ¶
Please note that this example does not define an output as it requires a server and is here for illustrative purposes only.
package main import ( "github.com/nextmv-io/sdk/route/osrm" ) func main() { client := osrm.DefaultClient( "YOUR-OSRM-SERVER e.g.:http://localhost:5000", true, ) _ = client // The client is instantiated as an example, but it is not used. }
Output:
func NewClient ¶
func NewClient(host string, opts ...ClientOption) Client
NewClient returns a new OSRM Client.
type ClientOption ¶
type ClientOption func(*client)
ClientOption can pass options to be used with an OSRM client.
func WithCache ¶
func WithCache(maxItems int) ClientOption
WithCache configures the maximum number of results cached.
func WithClientTransport ¶
func WithClientTransport(rt http.RoundTripper) ClientOption
WithClientTransport overwrites the RoundTripper used by the internal http.Client.
type Leg ¶
type Leg struct {
Steps []Step `json:"steps"`
}
Leg partially represents the OSRM Leg object.
type RouteResponse ¶
type RouteResponse struct { Code string `json:"code"` Routes []Route `json:"routes"` Message string `json:"message"` }
RouteResponse holds the route response from the OSRM server.
type Step ¶
type Step struct {
Geometry string `json:"geometry"`
}
Step partially represents the OSRM Step object.
type TableOptions ¶
type TableOptions func(*tableConfig)
TableOptions is a function that configures a tableConfig.
func ParallelRuns ¶
func ParallelRuns(runs int) TableOptions
ParallelRuns set the number of parallel calls to the OSRM server. If 0 is passed, the default value of 16 will be used.
func WithDistance ¶
func WithDistance() TableOptions
WithDistance returns a TableOptions function for composing a tableConfig with distance data enabled, telling the OSRM server to include distance data in the response table data.
func WithDuration ¶
func WithDuration() TableOptions
WithDuration returns a TableOptions function for composing a tableConfig with duration data enabled, telling the OSRM server to include duration data in the response table data.