routingkit

package module
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package routingkit provides measures that calculate the cost of travelling between points on road networks. It relies on Open Street Map (OSM) files without the need for a 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/routingkit.

Example (CustomProfile)

The following code example shows how to create your own vehicle profile and use it with routingkit. It customizes the vehicle speed and makes it depend on the tags present. In this example the speed is fixed to a single value (defined in `customVehicleSpeedMapper`). Furthermore, only ways are allowed to be used by the `customVehicle` which have the highway tag and its value is not motorway (defined in `customVehicleTagMapFilter`). Please refer to the OpenStreetMaps [documentation on ways][osm-docs] to learn more about [tags and their values][osm-ways]. [osm-docs]: https://wiki.openstreetmap.org/wiki/Way [osm-ways]: https://wiki.openstreetmap.org/wiki/Key:highway

package main

import (
	"fmt"

	goroutingkit "github.com/nextmv-io/go-routingkit/routingkit"
	"github.com/nextmv-io/sdk/route"
	"github.com/nextmv-io/sdk/route/routingkit"
)

func main() {
	fallbackMeasure := route.ScaleByPoint(route.HaversineByPoint(), 1.3)

	// Restricts ways to defined OSM way tags.
	filter := func(id int, tags map[string]string) bool {
		// Uses the default filter to filter out ways which are not routable by
		// a car.
		if !routingkit.Car().Filter(id, tags) {
			return false
		}
		// Additionally filter out motorway and trunk (only use small
		// streets/roads).
		// Returning true here, should give different costs for the points used
		// below. The shortest path uses a 'trunk' way.
		return tags["highway"] != "motorway" && tags["highway"] != "trunk"
	}

	// Defines a speed per OSM way tag.
	speedMapper := func(_ int, tags map[string]string) int {
		return 10
	}

	// Defines the custom profile.
	p := goroutingkit.NewProfile(
		"customVehicle", // Profile name
		// TransportationMode, other values: BikeMode, PedestrianMode.
		goroutingkit.VehicleMode,
		// Prevent left turns, only for TransportationMode "VehicleMode".
		false,
		// Prevent U-turns, only for TransportationMode "VehicleMode".
		false,
		filter,
		speedMapper,
	)

	// Defines a routingkit measure using the custom profile.
	m, err := routingkit.DurationByPoint(
		"testdata/rk_test.osm.pbf",
		1000,
		1<<30,
		p,
		fallbackMeasure,
	)
	if err != nil {
		panic(err)
	}
	cost := m.Cost(

		route.Point{7.34375, 52.16391},
		route.Point{7.32165, 52.15834},
	)
	fmt.Println(int(cost))
}
Output:

1194

Index

Examples

Constants

This section is empty.

Variables

Bike constructs a bike routingkit profile.

Car constructs a car routingkit profile.

View Source
var Pedestrian = routingkit.Pedestrian

Pedestrian constructs a pedestrian routingkit profile.

Truck constructs a truck routingkit profile.

Functions

func ByPoint deprecated

func ByPoint(
	mapFile string,
	radius float64,
	cacheSize int64,
	profile routingkit.Profile,
	m route.ByPoint,
) (route.ByPoint, error)

ByPoint constructs a route.ByPoint that computes the road network distance connecting any two points found within the provided mapFile. It needs a radius in which points can be snapped to the road network, a cache size in bytes (1 << 30 = 1 GB), a profile and a measure that is used in case no travel time can be computed.

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/routingkit.

Example
package main

import (
	"fmt"

	"github.com/nextmv-io/sdk/route"
	"github.com/nextmv-io/sdk/route/routingkit"
)

func main() {
	carProfile := routingkit.Car()
	fallbackMeasure := route.ScaleByPoint(route.HaversineByPoint(), 1.3)
	byPointDistance, err := routingkit.ByPoint(
		"testdata/rk_test.osm.pbf",
		1000,
		1<<30,
		carProfile,
		fallbackMeasure,
	)
	if err != nil {
		panic(err)
	}
	cost := byPointDistance.Cost(
		route.Point{7.33745, 52.14758},
		route.Point{7.34979, 52.15149},
	)
	fmt.Println(int(cost))
}
Output:

1225

func DurationByPoint deprecated

func DurationByPoint(
	mapFile string,
	radius float64,
	cacheSize int64,
	profile routingkit.Profile,
	m route.ByPoint,
) (route.ByPoint, error)

DurationByPoint is a measure that uses routingkit to calculate car travel times between given points. It needs a .osm.pbf map file, a radius in which points can be snapped to the road network, a cache size in bytes (1 << 30 = 1 GB), a profile and a measure that is used in case no travel time can be computed.

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/routingkit.

Example
package main

import (
	"fmt"

	"github.com/nextmv-io/sdk/route"
	"github.com/nextmv-io/sdk/route/routingkit"
)

func main() {
	carProfile := routingkit.Car()
	fallbackMeasure := route.ScaleByPoint(route.HaversineByPoint(), 1.2)
	byPointDuration, err := routingkit.DurationByPoint(
		"testdata/rk_test.osm.pbf",
		1000,
		1<<30,
		carProfile,
		fallbackMeasure,
	)
	if err != nil {
		panic(err)
	}
	cost := byPointDuration.Cost(
		route.Point{7.33745, 52.14758},
		route.Point{7.34979, 52.15149},
	)
	fmt.Println(int(cost))
}
Output:

187

func DurationMatrix deprecated

func DurationMatrix(
	mapFile string,
	radius float64,
	srcs []route.Point,
	dests []route.Point,
	profile routingkit.Profile,
	m route.ByPoint,
) (route.ByIndex, error)

DurationMatrix uses the provided mapFile to construct a route.ByIndex that can find the road network durations between any point in srcs and any point in dests. In addition to the mapFile, srcs and dests it needs a radius in which points can be snapped to the road network, a profile and a measure that is used in case no travel durations can be computed.

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/routingkit.

Example
package main

import (
	"fmt"

	"github.com/nextmv-io/sdk/route"
	"github.com/nextmv-io/sdk/route/routingkit"
)

func main() {
	srcs := []route.Point{
		{7.33745, 52.14758},
		{7.32486, 52.14280},
	}
	dests := []route.Point{
		{7.34979, 52.15149},
		{7.33293, 52.13893},
	}
	fallbackMeasure := route.ScaleByPoint(route.HaversineByPoint(), 1.2)
	byIndexDistance, err := routingkit.DurationMatrix(
		"testdata/rk_test.osm.pbf",
		1000,
		srcs,
		dests,
		routingkit.Car(),
		fallbackMeasure,
	)
	if err != nil {
		panic(err)
	}
	cost := byIndexDistance.Cost(0, 1)
	fmt.Println(int(cost))
}
Output:

215

func Matrix deprecated

func Matrix(
	mapFile string,
	radius float64,
	srcs []route.Point,
	dests []route.Point,
	profile routingkit.Profile,
	m route.ByPoint,
) (route.ByIndex, error)

Matrix uses the provided mapFile to construct a route.ByIndex that can find the road network distance between any point in srcs and any point in dests. In addition to the mapFile, srcs and dests it needs a radius in which points can be snapped to the road network, a profile and a measure that is used in case no distances can be computed.

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/routingkit.

Example
package main

import (
	"fmt"

	"github.com/nextmv-io/sdk/route"
	"github.com/nextmv-io/sdk/route/routingkit"
)

func main() {
	srcs := []route.Point{
		{7.33745, 52.14758},
		{7.32486, 52.14280},
	}
	dests := []route.Point{
		{7.34979, 52.15149},
		{7.33293, 52.13893},
	}
	fallbackMeasure := route.ScaleByPoint(route.HaversineByPoint(), 1.3)
	byIndexDistance, err := routingkit.Matrix(
		"testdata/rk_test.osm.pbf",
		1000,
		srcs,
		dests,
		routingkit.Car(),
		fallbackMeasure,
	)
	if err != nil {
		panic(err)
	}
	cost := byIndexDistance.Cost(0, 1)
	fmt.Println(int(cost))
}
Output:

1219

Types

type ByIndexLoader deprecated

type ByIndexLoader struct {
	// contains filtered or unexported fields
}

ByIndexLoader can be embedded in schema structs and unmarshals a ByIndex JSON object into the appropriate implementation, including a routingkit.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/routingkit.

func (ByIndexLoader) MarshalJSON

func (l ByIndexLoader) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON representation for the underlying ByIndex.

func (*ByIndexLoader) To

func (l *ByIndexLoader) To() route.ByIndex

To returns the underlying ByIndex.

func (*ByIndexLoader) UnmarshalJSON

func (l *ByIndexLoader) UnmarshalJSON(b []byte) error

UnmarshalJSON converts the bytes into the appropriate implementation of ByIndex.

type ByPointLoader deprecated

type ByPointLoader struct {
	// contains filtered or unexported fields
}

ByPointLoader can be embedded in schema structs and unmarshals a ByPoint JSON object into the appropriate implementation, including a routingkit.ByPoint.

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/routingkit.

func (ByPointLoader) MarshalJSON

func (l ByPointLoader) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON representation for the underlying ByPoint.

func (*ByPointLoader) To

func (l *ByPointLoader) To() route.ByPoint

To returns the underlying ByPoint.

func (*ByPointLoader) UnmarshalJSON

func (l *ByPointLoader) UnmarshalJSON(b []byte) error

UnmarshalJSON converts the bytes into the appropriate implementation of ByPoint.

type DistanceClient deprecated added in v0.28.0

type DistanceClient interface {
	// Measure returns a route.ByPoint that can calculate the road network
	// distance between any two points found within the provided mapFile.
	//
	// 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/routingkit].
	Measure(radius float64, cacheSize int64, fallback route.ByPoint) (route.ByPoint, error)
	// Matrix returns a route.ByIndex that represents the road network distance
	// matrix as a measure.
	//
	// 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/routingkit].
	Matrix(srcs []route.Point, dests []route.Point) (route.ByIndex, 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/routingkit].
	Polyline(points []route.Point) (string, []string, error)
}

DistanceClient represents a RoutingKit distance 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/routingkit.

func NewDistanceClient deprecated added in v0.28.0

func NewDistanceClient(
	mapFile string,
	profile routingkit.Profile,
) (DistanceClient, error)

NewDistanceClient returns a new RoutingKit 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/routingkit.

type DurationClient deprecated added in v0.28.0

type DurationClient interface {
	// Measure returns a route.ByPoint that can calculate the road network
	// travel time between any two points found within the provided mapFile.
	//
	// 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/routingkit].
	Measure(radius float64, cacheSize int64, fallback route.ByPoint) (route.ByPoint, error)
	// Matrix returns a route.ByIndex that represents the road network travel
	// time matrix as a measure.
	//
	// 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/routingkit].
	Matrix(srcs []route.Point, dests []route.Point) (route.ByIndex, 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/routingkit].
	Polyline(points []route.Point) (string, []string, error)
}

DurationClient represents a RoutingKit duration 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/routingkit.

func NewDurationClient deprecated added in v0.28.0

func NewDurationClient(
	mapFile string,
	profile routingkit.Profile,
) (DurationClient, error)

NewDurationClient returns a new RoutingKit 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/routingkit.

type ProfileLoader deprecated

type ProfileLoader struct {
	// contains filtered or unexported fields
}

ProfileLoader can be embedded in schema structs and unmarshals a routingkit.Profile JSON object into the appropriate implementation.

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/routingkit.

func (ProfileLoader) MarshalJSON

func (l ProfileLoader) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON representation for the underlying Profile.

func (*ProfileLoader) To

To returns the underlying Profile.

func (*ProfileLoader) UnmarshalJSON

func (l *ProfileLoader) UnmarshalJSON(b []byte) error

UnmarshalJSON converts the bytes into the appropriate implementation of Profile.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL