forked from gojuno/go.osrm
-
Notifications
You must be signed in to change notification settings - Fork 2
/
match.go
75 lines (67 loc) · 1.79 KB
/
match.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package osrm
import geo "github.com/paulmach/go.geo"
// MatchRequest represents a request to the match method
type MatchRequest struct {
Profile string
Coordinates Geometry
Bearings []Bearing
Steps Steps
Annotations Annotations
Tidy Tidy
Timestamps []int64
Radiuses []float64
Hints []string
Overview Overview
Gaps Gaps
Geometries Geometries
}
// MatchResponse represents a response from the match method
type MatchResponse struct {
ResponseStatus
Matchings []Matching `json:"matchings"`
Tracepoints []*Tracepoint `json:"tracepoints"`
}
// Matching represents an array of Route objects that assemble the trace
type Matching struct {
Route
Confidence float64 `json:"confidence"`
Geometry Geometry `json:"geometry"`
}
func (r MatchRequest) request() *request {
options := matcherOptions(
stepsOptions(r.Steps, r.Annotations, r.Overview, r.Geometries),
r.Tidy,
r.Gaps,
)
if len(r.Timestamps) > 0 {
options.addInt64("timestamps", r.Timestamps...)
}
if len(r.Radiuses) > 0 {
options.addFloat("radiuses", r.Radiuses...)
}
if len(r.Hints) > 0 {
options.add("hints", r.Hints...)
}
if len(r.Bearings) > 0 {
options.set("bearings", bearings(r.Bearings))
}
return &request{
profile: r.Profile,
coords: r.Coordinates,
service: "match",
options: options,
}
}
// Tracepoint represents a matched point on a route
type Tracepoint struct {
Index int `json:"waypoint_index"`
Location geo.Point `json:"location"`
MatchingIndex int `json:"matchings_index"`
AlternativesCount int `json:"alternatives_count"`
Hint string `json:"hint"`
}
func matcherOptions(options options, tidy Tidy, gaps Gaps) options {
return options.
setStringer("tidy", tidy).
setStringer("gaps", gaps)
}