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.
Deprecated: This package is deprecated and will be removed in the next major release. It is used with the router engine which was replaced by github.com/nextmv-io/sdk/measure/osrm.
Index ¶
- func DistanceDurationMatrices(c Client, points []route.Point, parallelQueries int) (distance, duration route.ByIndex, err error)deprecated
- func DistanceMatrix(c Client, points []route.Point, parallelQueries int) (route.ByIndex, error)deprecated
- func DurationMatrix(c Client, points []route.Point, parallelQueries int) (route.ByIndex, error)deprecated
- func Polyline(c Client, points []route.Point) (string, []string, error)deprecated
- type Clientdeprecated
- type ClientOptiondeprecated
- type Endpointdeprecated
- type Errordeprecated
- type Legdeprecated
- type Routedeprecated
- type RouteResponsedeprecated
- type Stepdeprecated
- type TableOptionsdeprecated
- func ParallelRuns(runs int) TableOptionsdeprecated
- func WithDistance() TableOptionsdeprecated
- func WithDuration() TableOptionsdeprecated
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DistanceDurationMatrices
deprecated
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.
Deprecated: This package is deprecated and will be removed in the next major release. It is used with the router engine which was replaced by github.com/nextmv-io/sdk/measure/osrm.
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
deprecated
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.
Deprecated: This package is deprecated and will be removed in the next major release. It is used with the router engine which was replaced by github.com/nextmv-io/sdk/measure/osrm.
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
deprecated
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.
Deprecated: This package is deprecated and will be removed in the next major release. It is used with the router engine which was replaced by github.com/nextmv-io/sdk/measure/osrm.
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:
func Polyline
deprecated
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.
Deprecated: This package is deprecated and will be removed in the next major release. It is used with the router engine which was replaced by github.com/nextmv-io/sdk/measure/osrm.
Types ¶
type Client
deprecated
type Client interface {
// Table requests a distance and/or duration table from an OSRM server.
//
// Deprecated: This package is deprecated and will be removed in the next major release.
// It is used with the router engine which was replaced by
// [github.com/nextmv-io/sdk/measure/osrm].
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.
//
// Deprecated: This package is deprecated and will be removed in the next major release.
// It is used with the router engine which was replaced by
// [github.com/nextmv-io/sdk/measure/osrm].
Get(uri string) ([]byte, error)
// IgnoreEmpty removes empty / zero points from the request before sending
// it to the OSRM server. The indices of the points will be maintained.
// Distances / durations for these points will be set to 0.
//
// Deprecated: This package is deprecated and will be removed in the next major release.
// It is used with the router engine which was replaced by
// [github.com/nextmv-io/sdk/measure/osrm].
IgnoreEmpty(ignore bool)
// 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.
//
// Deprecated: This package is deprecated and will be removed in the next major release.
// It is used with the router engine which was replaced by
// [github.com/nextmv-io/sdk/measure/osrm].
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.
//
// Deprecated: This package is deprecated and will be removed in the next major release.
// It is used with the router engine which was replaced by
// [github.com/nextmv-io/sdk/measure/osrm].
ScaleFactor(factor float64) error
// MaxTableSize should be configured with the same value as the OSRM
// server's max-table-size setting, default is 100
//
// Deprecated: This package is deprecated and will be removed in the next major release.
// It is used with the router engine which was replaced by
// [github.com/nextmv-io/sdk/measure/osrm].
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.
//
// Deprecated: This package is deprecated and will be removed in the next major release.
// It is used with the router engine which was replaced by
// [github.com/nextmv-io/sdk/measure/osrm].
Polyline(points []route.Point) (string, []string, error)
}
Client represents an OSRM client.
Deprecated: This package is deprecated and will be removed in the next major release. It is used with the router engine which was replaced by github.com/nextmv-io/sdk/measure/osrm.
func DefaultClient
deprecated
DefaultClient creates a new OSRM Client.
Deprecated: This package is deprecated and will be removed in the next major release. It is used with the router engine which was replaced by github.com/nextmv-io/sdk/measure/osrm.
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
deprecated
func NewClient(host string, opts ...ClientOption) Client
NewClient returns a new OSRM Client.
Deprecated: This package is deprecated and will be removed in the next major release. It is used with the router engine which was replaced by github.com/nextmv-io/sdk/measure/osrm.
type ClientOption
deprecated
type ClientOption func(*client)
ClientOption can pass options to be used with an OSRM client.
Deprecated: This package is deprecated and will be removed in the next major release. It is used with the router engine which was replaced by github.com/nextmv-io/sdk/measure/osrm.
func WithCache
deprecated
func WithCache(maxItems int) ClientOption
WithCache configures the maximum number of results cached.
Deprecated: This package is deprecated and will be removed in the next major release. It is used with the router engine which was replaced by github.com/nextmv-io/sdk/measure/osrm.
func WithClientTransport
deprecated
func WithClientTransport(rt http.RoundTripper) ClientOption
WithClientTransport overwrites the RoundTripper used by the internal http.Client.
Deprecated: This package is deprecated and will be removed in the next major release. It is used with the router engine which was replaced by github.com/nextmv-io/sdk/measure/osrm.
type Endpoint
deprecated
type Endpoint string
Endpoint defines the OSRM endpoint to be used.
Deprecated: This package is deprecated and will be removed in the next major release. It is used with the router engine which was replaced by github.com/nextmv-io/sdk/measure/osrm.
const ( // TableEndpoint is used to retrieve distance and duration matrices. // // Deprecated: This package is deprecated and will be removed in the next major release. // It is used with the router engine which was replaced by // [github.com/nextmv-io/sdk/measure/osrm]. TableEndpoint Endpoint = "table" // RouteEndpoint is used to retrieve polylines for a set of points. // // Deprecated: This package is deprecated and will be removed in the next major release. // It is used with the router engine which was replaced by // [github.com/nextmv-io/sdk/measure/osrm]. RouteEndpoint Endpoint = "route" )
type Error
deprecated
added in
v0.27.1
type Error struct {
// contains filtered or unexported fields
}
Error is an error that reflects an error that is the user's fault.
Deprecated: This package is deprecated and will be removed in the next major release. It is used with the router engine which was replaced by github.com/nextmv-io/sdk/measure/osrm.
func NewError
deprecated
added in
v0.27.1
NewError returns a new NewError.
Deprecated: This package is deprecated and will be removed in the next major release. It is used with the router engine which was replaced by github.com/nextmv-io/sdk/measure/osrm.
func (Error) IsInputError ¶ added in v0.27.1
IsInputError returns true if the error is the user's fault.
type Leg
deprecated
type Leg struct {
Steps []Step `json:"steps"`
}
Leg partially represents the OSRM Leg object.
Deprecated: This package is deprecated and will be removed in the next major release. It is used with the router engine which was replaced by github.com/nextmv-io/sdk/measure/osrm.
type Route
deprecated
Route partially represents the OSRM Route object.
Deprecated: This package is deprecated and will be removed in the next major release. It is used with the router engine which was replaced by github.com/nextmv-io/sdk/measure/osrm.
type RouteResponse
deprecated
type RouteResponse struct {
Code string `json:"code"`
Routes []Route `json:"routes"`
Message string `json:"message"`
}
RouteResponse holds the route response from the OSRM server.
Deprecated: This package is deprecated and will be removed in the next major release. It is used with the router engine which was replaced by github.com/nextmv-io/sdk/measure/osrm.
type Step
deprecated
type Step struct {
Geometry string `json:"geometry"`
}
Step partially represents the OSRM Step object.
Deprecated: This package is deprecated and will be removed in the next major release. It is used with the router engine which was replaced by github.com/nextmv-io/sdk/measure/osrm.
type TableOptions
deprecated
type TableOptions func(*tableConfig)
TableOptions is a function that configures a tableConfig.
Deprecated: This package is deprecated and will be removed in the next major release. It is used with the router engine which was replaced by github.com/nextmv-io/sdk/measure/osrm.
func ParallelRuns
deprecated
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.
Deprecated: This package is deprecated and will be removed in the next major release. It is used with the router engine which was replaced by github.com/nextmv-io/sdk/measure/osrm.
func WithDistance
deprecated
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.
Deprecated: This package is deprecated and will be removed in the next major release. It is used with the router engine which was replaced by github.com/nextmv-io/sdk/measure/osrm.
func WithDuration
deprecated
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.
Deprecated: This package is deprecated and will be removed in the next major release. It is used with the router engine which was replaced by github.com/nextmv-io/sdk/measure/osrm.