mirror of https://github.com/dsoprea/go-exif.git
gps.go: Fix known S2 mishandling that can lead to an invalid cell
parent
8d79b03fc5
commit
a30f27f681
18
gps.go
18
gps.go
|
@ -1,13 +1,16 @@
|
||||||
package exif
|
package exif
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/geo/s1"
|
|
||||||
"github.com/golang/geo/s2"
|
"github.com/golang/geo/s2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrGpsCoordinatesNotValid = errors.New("GPS coordinates not valid")
|
||||||
|
)
|
||||||
|
|
||||||
type GpsDegrees struct {
|
type GpsDegrees struct {
|
||||||
Orientation byte
|
Orientation byte
|
||||||
|
@ -28,7 +31,6 @@ func (d GpsDegrees) Decimal() float64 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type GpsInfo struct {
|
type GpsInfo struct {
|
||||||
Latitude, Longitude GpsDegrees
|
Latitude, Longitude GpsDegrees
|
||||||
Altitude int
|
Altitude int
|
||||||
|
@ -43,12 +45,12 @@ func (gi *GpsInfo) S2CellId() s2.CellID {
|
||||||
latitude := gi.Latitude.Decimal()
|
latitude := gi.Latitude.Decimal()
|
||||||
longitude := gi.Longitude.Decimal()
|
longitude := gi.Longitude.Decimal()
|
||||||
|
|
||||||
ll := s2.LatLng{
|
ll := s2.LatLngFromDegrees(latitude, longitude)
|
||||||
s1.Angle(latitude),
|
cellId := s2.CellIDFromLatLng(ll)
|
||||||
s1.Angle(longitude),
|
|
||||||
|
if cellId.IsValid() == false {
|
||||||
|
panic(ErrGpsCoordinatesNotValid)
|
||||||
}
|
}
|
||||||
|
|
||||||
ll.Normalized()
|
return cellId
|
||||||
|
|
||||||
return s2.CellIDFromLatLng(ll)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue