Documentation
¶
Index ¶
- Constants
- Variables
- func ExponentialDistribution(beta, x float64) float64
- func ExtractCutUpFrom(polyline s2.Polyline, projected s2.Point, projectedIdx int) (s2.Polyline, s2.Polyline)
- func ExtractCutUpTo(polyline s2.Polyline, projected s2.Point, projectedIdx int) (s2.Polyline, s2.Polyline)
- func GeoJSONToS2PointFeature(pts *geojson.Geometry) (s2.Point, error)
- func GeoJSONToS2PolylineFeature(pts *geojson.Geometry) (*s2.Polyline, error)
- func LogExponentialDistribution(beta, x float64) float64
- func LogNormalDistribution(sigma, x float64) float64
- func NormalDistribution(sigma, x float64) float64
- func S2PointToGeoJSONFeature(pt *s2.Point) *geojson.Feature
- func S2PolylineToGeoJSONFeature(pts s2.Polyline) *geojson.Feature
- func WithGPSTime(t time.Time) func(*GPSMeasurement)
- type CandidateLayer
- type Edge
- type EdgeResult
- type GPSMeasurement
- type GPSMeasurements
- type GPSTrack
- type GeoPoint
- type HmmProbabilities
- func (hp *HmmProbabilities) EmissionLogProbability(value float64) float64
- func (hp *HmmProbabilities) EmissionProbability(value float64) float64
- func (hp *HmmProbabilities) TransitionLogProbability(routeLength, linearDistance, timeDiff float64) (float64, error)
- func (hp *HmmProbabilities) TransitionProbability(routeLength, linearDistance, timeDiff float64) (float64, error)
- type Isochrone
- type IsochronesResult
- type MapEngine
- type MapMatcher
- func (matcher *MapMatcher) FindIsochrones(source *GPSMeasurement, maxCost float64, maxNearestRadius float64) (IsochronesResult, error)
- func (matcher *MapMatcher) FindShortestPath(source, target *GPSMeasurement, statesRadiusMeters float64) (MatcherResult, error)
- func (matcher *MapMatcher) PrepareViterbi(obsStates []*CandidateLayer, routeLengths map[int]map[int]float64, ...) (*viterbi.Viterbi, error)
- func (matcher *MapMatcher) Run(gpsMeasurements []*GPSMeasurement, statesRadiusMeters float64, maxStates int) (MatcherResult, error)
- type MatcherResult
- type NearestObject
- type ObservationResult
- type RoadPosition
- type RoadPositions
- type S2Storage
- func (storage *S2Storage) AddEdge(edgeID uint64, edge *Edge) error
- func (storage *S2Storage) NearestNeighborsInRadius(pt s2.Point, radius float64, n int) ([]NearestObject, error)
- func (storage *S2Storage) SearchInRadius(pt s2.Point, radius float64) (map[uint64]float64, error)
- func (storage *S2Storage) SearchInRadiusLonLat(lon, lat float64, radius float64) (map[uint64]float64, error)
- type Vertex
Constants ¶
const ( ViterbiDebug = false ROUTE_LENGTH_THRESHOLD = 9_999_999_999.0 )
const (
// EarthRadius Approximate radius of Earth
EarthRadius = 6370986.884258304
)
Variables ¶
var ( ErrMinumimGPSMeasurements = fmt.Errorf("number of gps measurements need to be 3 atleast") ErrCandidatesNotFound = fmt.Errorf("there is no a single GPS point having candidates") ErrTimeDifference = fmt.Errorf("time difference between subsequent location measurements must be >= 0") ErrSourceNotFound = fmt.Errorf("can't find closest edge for 'source' point") ErrSourceHasMoreEdges = fmt.Errorf("more than 1 edge for 'source' point") ErrTargetNotFound = fmt.Errorf("can't find closest edge for 'target' point") ErrTargetHasMoreEdges = fmt.Errorf("more than 1 edge for 'target' point") ErrPathNotFound = fmt.Errorf("path not found") ErrSameVertex = fmt.Errorf("same vertex") )
Functions ¶
func ExponentialDistribution ¶
ExponentialDistribution 1 / (β*exp(-x/β)), beta = 1/λ
func ExtractCutUpFrom ¶ added in v0.7.0
func ExtractCutUpFrom(polyline s2.Polyline, projected s2.Point, projectedIdx int) (s2.Polyline, s2.Polyline)
ExtractCutUpFrom cuts geometry between neighbor of the projected point index in the polyline and last point
func ExtractCutUpTo ¶ added in v0.7.0
func ExtractCutUpTo(polyline s2.Polyline, projected s2.Point, projectedIdx int) (s2.Polyline, s2.Polyline)
ExtractCutUpTo cuts geometry between very first point and neighbor of the projected point index in the polyline
func GeoJSONToS2PointFeature ¶ added in v0.5.0
GeoJSONToS2PointFeature Returns s2.Point representation of *geojson.Geometry (of Point type)
func GeoJSONToS2PolylineFeature ¶
GeoJSONToS2PolylineFeature Returns *s2.Polyline representation of *geojson.Geometry (of LineString type)
func LogExponentialDistribution ¶
LogExponentialDistribution ln(1/β) - (x/β), beta = 1/λ
func LogNormalDistribution ¶
LogNormalDistribution https://en.wikipedia.org/wiki/Log-normal_distribution
func NormalDistribution ¶
NormalDistribution https://en.wikipedia.org/wiki/Normal_distribution
func S2PointToGeoJSONFeature ¶
S2PointToGeoJSONFeature Returns GeoJSON representation of *s2.Point
func S2PolylineToGeoJSONFeature ¶
S2PolylineToGeoJSONFeature Returns GeoJSON representation of *s2.Polyline
func WithGPSTime ¶ added in v0.6.0
func WithGPSTime(t time.Time) func(*GPSMeasurement)
WithGPSTime sets user defined time for GPS measurement
Types ¶
type CandidateLayer ¶
type CandidateLayer struct { Observation *GPSMeasurement States RoadPositions EmissionLogProbabilities []emission TransitionLogProbabilities []transition }
CandidateLayer Wrapper around Observation
Observation - observation itself States - set of projections on road network EmissionLogProbabilities - emission probabilities between Observation and corresponding States TransitionLogProbabilities - transition probabilities between States
func NewCandidateLayer ¶
func NewCandidateLayer(observation *GPSMeasurement, states RoadPositions) *CandidateLayer
NewCandidateLayer Returns pointer to created CandidateLayer
func (*CandidateLayer) AddEmissionProbability ¶
func (ts *CandidateLayer) AddEmissionProbability(candidate *RoadPosition, emissionLogProbability float64)
AddEmissionProbability Append emission probability to slice of emission probablities
func (*CandidateLayer) AddTransitionProbability ¶
func (ts *CandidateLayer) AddTransitionProbability(fromPosition, toPosition *RoadPosition, transitionLogProbability float64)
AddTransitionProbability Append transition probability to slice of transition probablities
type Edge ¶
Edge Representation of segment of road (edge in graph)
ID - unique identifier Source - identifier of source vertex Target - identifier of target vertex Weight - cost of moving on edge (usually it is length or time) Polyline - geometry of edge, pointer to s2.Polyline (wrapper)
type EdgeResult ¶ added in v0.6.0
type GPSMeasurement ¶
type GPSMeasurement struct { *GeoPoint // contains filtered or unexported fields }
GPSMeasurement Representation of telematic data
id - unique identifier dateTime - timestamp GeoPoint - latitude(Y)/longitude(X), pointer to GeoPoint (wrapper)
func NewGPSMeasurement ¶
func NewGPSMeasurement(id int, lon, lat float64, srid int, options ...func(*GPSMeasurement)) *GPSMeasurement
NewGPSMeasurement Returns pointer to created GPSMeasurement
id - unique identifier lon - longitude (X for SRID = 0) lat - latitude (Y for SRID = 0) srid - SRID (see https://en.wikipedia.org/wiki/Spatial_reference_system), if not provided then SRID(4326) is used. 0 and 4326 are supported.
func NewGPSMeasurementFromID ¶
func NewGPSMeasurementFromID(id int, lon, lat float64, srid ...int) *GPSMeasurement
NewGPSMeasurementFromID Returns pointer to created GPSMeasurement
id - unique identifier (will be converted to time.Time also) lon - longitude (X for SRID = 0) lat - latitude (Y for SRID = 0) srid - SRID (see https://en.wikipedia.org/wiki/Spatial_reference_system), if not provided then SRID(4326) is used. 0 and 4326 are supported.
func (*GPSMeasurement) ID ¶
func (gps *GPSMeasurement) ID() int
ID Returns generated identifier for GPS-point
func (*GPSMeasurement) TM ¶ added in v0.2.4
func (gps *GPSMeasurement) TM() time.Time
TM Returns generated (or provided) timestamp for GPS-point
type GeoPoint ¶
GeoPoint Wrapper around of s2.Point
Needs additional field "srid" to determine what algorithm has to be used to calculate distance between objects SRID = 0, Euclidean distance SRID = 4326 (WGS84), Distance on sphere
func NewEuclideanPoint ¶
NewEuclideanPoint Returns pointer to created GeoPoint with SRID = 0
func NewWGS84Point ¶
NewWGS84Point Returns pointer to created GeoPoint with SRID = 4326
func (*GeoPoint) DistanceTo ¶
DistanceTo Compute distance between two points.
Algorithm of distance calculation depends on SRID. SRID = 0, Euclidean distance SRID = 4326 (WGS84), Distance on sphere
type HmmProbabilities ¶
type HmmProbabilities struct {
// contains filtered or unexported fields
}
HmmProbabilities Parameters used in evaluating of Normal Distribution and Exponentional Distribution
func HmmProbabilitiesDefault ¶
func HmmProbabilitiesDefault() *HmmProbabilities
HmmProbabilitiesDefault Constructor for creating HmmProbabilities with default values Sigma - standard deviation of the normal distribution [m] used for modeling the GPS error Beta - beta parameter of the exponential distribution used for modeling transition probabilities
func NewHmmProbabilities ¶
func NewHmmProbabilities(sigma, beta float64) *HmmProbabilities
NewHmmProbabilities Constructor for creating HmmProbabilities with provided values
func (*HmmProbabilities) EmissionLogProbability ¶
func (hp *HmmProbabilities) EmissionLogProbability(value float64) float64
EmissionLogProbability Evaluate emission probability (log-normal distribution is used)
func (*HmmProbabilities) EmissionProbability ¶
func (hp *HmmProbabilities) EmissionProbability(value float64) float64
EmissionProbability Evaluate emission probability (normal distribution is used). Absolute distance [m] between GPS measurement and map matching candidate.
func (*HmmProbabilities) TransitionLogProbability ¶
func (hp *HmmProbabilities) TransitionLogProbability(routeLength, linearDistance, timeDiff float64) (float64, error)
TransitionLogProbability Evaluate transition probability (log-exponential distribution is used)
func (*HmmProbabilities) TransitionProbability ¶
func (hp *HmmProbabilities) TransitionProbability(routeLength, linearDistance, timeDiff float64) (float64, error)
TransitionProbability Evaluate transition probability (exponential distribution is used)
type IsochronesResult ¶ added in v0.5.0
type IsochronesResult []*Isochrone
IsochronesResult Representation of isochrones algorithm's output
type MapEngine ¶
type MapEngine struct {
// contains filtered or unexported fields
}
MapEngine Engine for solving finding shortest path and KNN problems edges - set of edges (map[from_vertex]map[to_vertex]Edge) s2Storage - datastore for B-tree. It is used for solving KNN problem s2StorageVertices - datastore for graph vertices (with geometry property) graph - Graph(E,V). It wraps ch.Graph (see https://github.com/LdDl/ch/blob/master/graph.go#L17). It used for solving finding shortest path problem.
func NewMapEngine ¶
NewMapEngine Returns pointer to created MapEngine with provided parameters
storageLevel - level for S2 degree - degree of b-tree
func NewMapEngineDefault ¶
func NewMapEngineDefault() *MapEngine
NewMapEngineDefault Returns pointer to created MapEngine with default parameters
type MapMatcher ¶
type MapMatcher struct {
// contains filtered or unexported fields
}
MapMatcher Engine for solving map matching problem
hmmParams - parameters of Hidden Markov Model engine - wrapper around MapEngine (for KNN and finding shortest path problems)
func NewMapMatcher ¶
func NewMapMatcher(props *HmmProbabilities, edgesFilename string) (*MapMatcher, error)
NewMapMatcher Returns pointer to created MapMatcher with provided parameters
props - parameters of Hidden Markov Model
func NewMapMatcherDefault ¶
func NewMapMatcherDefault() *MapMatcher
NewMapMatcherDefault Returns pointer to created MapMatcher with default parameters
func (*MapMatcher) FindIsochrones ¶ added in v0.5.0
func (matcher *MapMatcher) FindIsochrones(source *GPSMeasurement, maxCost float64, maxNearestRadius float64) (IsochronesResult, error)
FindIsochrones Find shortest path between two obserations (not necessary GPS points).
NOTICE: this function snaps point to only one nearest vertex (without multiple candidates for provided point) source - source for outcoming isochrones maxCost - max cost restriction for single isochrone line maxNearestRadius - max radius of search for nearest vertex
func (*MapMatcher) FindShortestPath ¶ added in v0.3.0
func (matcher *MapMatcher) FindShortestPath(source, target *GPSMeasurement, statesRadiusMeters float64) (MatcherResult, error)
FindShortestPath Find shortest path between two obserations (not necessary GPS points).
NOTICE: this function snaps point to nearest edges simply (without multiple 'candidates' for each observation) gpsMeasurements - Two observations statesRadiusMeters - maximum radius to search nearest polylines
func (*MapMatcher) PrepareViterbi ¶
func (matcher *MapMatcher) PrepareViterbi(obsStates []*CandidateLayer, routeLengths map[int]map[int]float64, gpsMeasurements []*GPSMeasurement) (*viterbi.Viterbi, error)
PrepareViterbi Prepares engine for doing Viterbi's algorithm (see https://github.com/LdDl/viterbi/blob/master/viterbi.go#L25)
states - set of States gpsMeasurements - set of Observations
func (*MapMatcher) Run ¶
func (matcher *MapMatcher) Run(gpsMeasurements []*GPSMeasurement, statesRadiusMeters float64, maxStates int) (MatcherResult, error)
Run Do magic
gpsMeasurements - Observations statesRadiusMeters - maximum radius to search nearest polylines maxStates - maximum of corresponding states
type MatcherResult ¶
type MatcherResult struct { Observations []ObservationResult Probability float64 }
MatcherResult Representation of map matching algorithm's output
Observations - set of ObservationResult Probability - probability got from Viterbi's algotithm Path - final path as s2.Polyline VerticesPath - IDs of graph vertices corresponding to traveled path
type NearestObject ¶
type NearestObject struct {
// contains filtered or unexported fields
}
NearestObject Nearest object to given point
edgeID - unique identifier distanceTo - distance to object
type ObservationResult ¶
type ObservationResult struct { Observation *GPSMeasurement MatchedEdge Edge MatchedVertex Vertex ProjectedPoint s2.Point ProjectionPointIdx int NextEdges []EdgeResult }
ObservationResult Representation of gps measurement matched to G(v,e)
Observation - gps measurement itself MatchedEdge - edge in G(v,e) corresponding to current gps measurement MatchedVertex - stands for closest vertex to the observation ProjectedPoint - projection onto the matched edge ProjectedPointIdx - index of the point in polyline which follows projection point NextEdges - set of leading edges up to next observation. Could be an empty array if observations are very close to each other or if it just last observation
type RoadPosition ¶
type RoadPosition struct { Projected *GeoPoint GraphEdge *Edge PickedGraphVertex int64 RoutingGraphVertex int64 RoadPositionID int // contains filtered or unexported fields }
RoadPosition Representation of state (in terms of Hidden Markov Model)
ID - unique identifier of state GraphEdge - pointer to closest edge in graph GraphVertex - indentifier of closest vertex Projected - point (Observation) project onto edge, pointer to GeoPoint beforeProjection - distance from starting point to projected one afterProjection - distance from projected point to last one next - index of the next vertex in s2.Polyline after the projected point
func NewRoadPositionFromLonLat ¶
func NewRoadPositionFromLonLat(stateID int, pickedGraphVertex, routingGraphVertex int64, e *Edge, lon, lat float64, srid ...int) *RoadPosition
NewRoadPositionFromLonLat Returns pointer to created State
stateID - unique identifier for state pickedGraphVertex - indentifier of vertex which is closest to Observation routingGraphVertex - indentifier of vertex which will be used in routing (initially it should match pickedGraphVertex in most cases) e - pointer to Edge lon - longitude (X for SRID = 0) lat - latitude (Y for SRID = 0) srid - SRID (see https://en.wikipedia.org/wiki/Spatial_reference_system)
func NewRoadPositionFromS2LatLng ¶
func NewRoadPositionFromS2LatLng(stateID int, pickedGraphVertex, routingGraphVertex int64, e *Edge, latLng *s2.LatLng, srid ...int) *RoadPosition
NewRoadPositionFromS2LatLng Returns pointer to created State
stateID - unique identifier for state pickedGraphVertex - indentifier of vertex which is closest to Observation routingGraphVertex - indentifier of vertex which will be used in routing (initially it should match pickedGraphVertex in most cases) e - pointer to Edge lon - longitude (X for SRID = 0) lat - latitude (Y for SRID = 0) srid - SRID (see https://en.wikipedia.org/wiki/Spatial_reference_system)
func (RoadPosition) ID ¶
func (state RoadPosition) ID() int
ID Method to fit interface State (see https://github.com/LdDl/viterbi/blob/master/viterbi.go#L9)
func (RoadPosition) String ¶
func (state RoadPosition) String() string
String Pretty format for State
type S2Storage ¶
S2Storage Spatial datastore
storageLevel - level for S2 edges - map of edges BTree - b-tree (wraps)
func NewS2Storage ¶
NewS2Storage Returns pointer to created S2Storage
storageLevel - level for S2 degree - degree of b-tree
func (*S2Storage) AddEdge ¶
AddEdge Add edge (polyline) to storage
edgeID - unique identifier edge - edge
func (*S2Storage) NearestNeighborsInRadius ¶
func (storage *S2Storage) NearestNeighborsInRadius(pt s2.Point, radius float64, n int) ([]NearestObject, error)
NearestNeighborsInRadius Returns edges in radius with max objects restriction (KNN)
pt - s2.Point radius - radius of search n - first N closest edges
func (*S2Storage) SearchInRadius ¶
SearchInRadius Returns edges in radius
pt - s2.Point radius - radius of search