Documentation ¶
Index ¶
- Constants
- func ExponentialDistribution(beta, x float64) float64
- 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
- type CandidateLayer
- type Edge
- 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 MapEngine
- type MapMatcher
- func (matcher *MapMatcher) FindShortestPath(source, target *GPSMeasurement, statesRadiusMeters float64) (MatcherResult, error)
- func (matcher *MapMatcher) PrepareViterbi(obsStates map[int]*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)
Constants ¶
const (
// EarthRadius Approximate radius of Earth
EarthRadius = 6370986.884258304
)
Variables ¶
This section is empty.
Functions ¶
func ExponentialDistribution ¶
ExponentialDistribution 1 / (β*exp(-x/β)), beta = 1/λ
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
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 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(t time.Time, lon, lat float64, srid ...int) *GPSMeasurement
NewGPSMeasurement Returns pointer to created GPSMeasurement
t - time.Time (will be converted to UnixTimestamp and used for 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 ¶
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 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 graph - Graph(E,V). It wraps ch.Graph (see https://github.com/chentoz/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, graphFileName 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) FindShortestPath ¶
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 map[int]*CandidateLayer, routeLengths map[int]map[int]float64, gpsMeasurements []*GPSMeasurement) (*viterbi.Viterbi, error)
PrepareViterbi Prepares engine for doing Viterbi's algorithm (see https://github.com/chentoz/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 Path s2.Polyline }
MatcherResult Representation of map mathicng algorithm's output
Observations - set of ObservationResult Probability - probability got from Viterbi's algotithm Path - final path as s2.Polyline
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 }
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
type RoadPosition ¶
type RoadPosition struct { RoadPositionID int GraphEdge *Edge GraphVertex int64 Projected *GeoPoint }
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
func NewRoadPositionFromLonLat ¶
func NewRoadPositionFromLonLat(stateID int, graphVertex int64, e *Edge, lon, lat float64, srid ...int) *RoadPosition
NewRoadPositionFromLonLat Returns pointer to created State
stateID - unique identifier for state graphVertex - indentifier of vertex which is closest to Observation 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, graphVertex int64, e *Edge, latLng *s2.LatLng, srid ...int) *RoadPosition
NewRoadPositionFromS2LatLng Returns pointer to created State
stateID - unique identifier for state graphVertex - indentifier of vertex which is closest to Observation 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/chentoz/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