/
gps_measurement.go
91 lines (81 loc) · 2.35 KB
/
gps_measurement.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package horizon
import (
"time"
geojson "github.com/paulmach/go.geojson"
)
// GPSMeasurements Set of telematic data
type GPSMeasurements []*GPSMeasurement
// GPSMeasurement Representation of telematic data
/*
id - unique identifier
dateTime - timestamp
GeoPoint - latitude(Y)/longitude(X), pointer to GeoPoint (wrapper)
*/
type GPSMeasurement struct {
id int
dateTime time.Time
*GeoPoint
}
// ID Returns generated identifier for GPS-point
func (gps *GPSMeasurement) ID() int {
return gps.id
}
// TM Returns generated (or provided) timestamp for GPS-point
func (gps *GPSMeasurement) TM() time.Time {
return gps.dateTime
}
// GPSTrack Set of telematic data
type GPSTrack []*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 NewGPSMeasurement(t time.Time, lon, lat float64, srid ...int) *GPSMeasurement {
gps := GPSMeasurement{
dateTime: t,
id: int(t.Unix()),
}
if len(srid) != 0 {
switch srid[0] {
case 0:
gps.GeoPoint = NewEuclideanPoint(lon, lat)
case 4326:
gps.GeoPoint = NewWGS84Point(lon, lat)
default:
gps.GeoPoint = NewWGS84Point(lon, lat)
}
}
return &gps
}
// 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 NewGPSMeasurementFromID(id int, lon, lat float64, srid ...int) *GPSMeasurement {
dateTime := time.Now().Add(time.Duration(id) * time.Second)
gps := GPSMeasurement{
dateTime: dateTime,
id: int(dateTime.Unix()),
}
if len(srid) != 0 {
switch srid[0] {
case 0:
gps.GeoPoint = NewEuclideanPoint(lon, lat)
case 4326:
gps.GeoPoint = NewWGS84Point(lon, lat)
default:
gps.GeoPoint = NewWGS84Point(lon, lat)
}
}
return &gps
}
// GeoJSON Returns GeoJSON representation of GeoPoint
func (gp *GeoPoint) GeoJSON() *geojson.Feature {
return S2PointToGeoJSONFeature(&gp.Point)
}