Fix error handling, attempt to stop POI flapping.
This commit is contained in:
parent
e4e4ac260f
commit
f879acf25d
2 changed files with 12 additions and 7 deletions
|
@ -2,7 +2,7 @@ package openname
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"archive/zip"
|
"archive/zip"
|
||||||
"log"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/dhconnelly/rtreego"
|
"github.com/dhconnelly/rtreego"
|
||||||
|
@ -11,7 +11,7 @@ import (
|
||||||
func BuildIndex(filename string) (*rtreego.Rtree, error) {
|
func BuildIndex(filename string) (*rtreego.Rtree, error) {
|
||||||
r, err := zip.OpenReader(filename)
|
r, err := zip.OpenReader(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
return nil, fmt.Errorf("error opening %s fo reading: %v", filename, err)
|
||||||
}
|
}
|
||||||
defer r.Close()
|
defer r.Close()
|
||||||
rt := rtreego.NewTree(2, 25, 50)
|
rt := rtreego.NewTree(2, 25, 50)
|
||||||
|
@ -21,12 +21,12 @@ func BuildIndex(filename string) (*rtreego.Rtree, error) {
|
||||||
}
|
}
|
||||||
rc, err := f.Open()
|
rc, err := f.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
return nil, fmt.Errorf("erorr opening %s: %v", filename, err)
|
||||||
}
|
}
|
||||||
defer rc.Close()
|
|
||||||
s, err := NewScanner(rc)
|
s, err := NewScanner(rc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error reading %s: %v", f.Name, err)
|
rc.Close()
|
||||||
|
return nil, fmt.Errorf("error reading %s: %v", f.Name, err)
|
||||||
}
|
}
|
||||||
for s.Scan() {
|
for s.Scan() {
|
||||||
r := s.Record()
|
r := s.Record()
|
||||||
|
@ -35,8 +35,10 @@ func BuildIndex(filename string) (*rtreego.Rtree, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err = s.Err(); err != nil {
|
if err = s.Err(); err != nil {
|
||||||
log.Fatalf("Error parsing %s: %v", f.Name, err)
|
rc.Close()
|
||||||
|
return nil, fmt.Errorf("error parsing %s: %v", f.Name, err)
|
||||||
}
|
}
|
||||||
|
rc.Close()
|
||||||
}
|
}
|
||||||
return rt, nil
|
return rt, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,6 +78,7 @@ func (gs *GPXSummarizer) SummarizeTrack(filename string) (*TrackSummary, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
var prevPlace string
|
var prevPlace string
|
||||||
|
var prevPlacePoint rtreego.Point
|
||||||
var prevPoint rtreego.Point
|
var prevPoint rtreego.Point
|
||||||
var prevHeight float64
|
var prevHeight float64
|
||||||
|
|
||||||
|
@ -96,6 +97,7 @@ func (gs *GPXSummarizer) SummarizeTrack(filename string) (*TrackSummary, error)
|
||||||
if init {
|
if init {
|
||||||
s.Start = nn.Name
|
s.Start = nn.Name
|
||||||
prevPlace = nn.Name
|
prevPlace = nn.Name
|
||||||
|
prevPlacePoint = thisPoint
|
||||||
prevPoint = thisPoint
|
prevPoint = thisPoint
|
||||||
prevHeight = thisHeight
|
prevHeight = thisHeight
|
||||||
s.PointsOfInterest = append(s.PointsOfInterest, POI{nn.Name, 0.0})
|
s.PointsOfInterest = append(s.PointsOfInterest, POI{nn.Name, 0.0})
|
||||||
|
@ -106,9 +108,10 @@ func (gs *GPXSummarizer) SummarizeTrack(filename string) (*TrackSummary, error)
|
||||||
if ascent := thisHeight - prevHeight; ascent > 0 {
|
if ascent := thisHeight - prevHeight; ascent > 0 {
|
||||||
s.Ascent += ascent
|
s.Ascent += ascent
|
||||||
}
|
}
|
||||||
if insideLoc(thisPoint, nn) && nn.Name != prevPlace {
|
if insideLoc(thisPoint, nn) && nn.Name != prevPlace && distance(thisPoint, prevPlacePoint) > 0.2 {
|
||||||
s.PointsOfInterest = append(s.PointsOfInterest, POI{nn.Name, s.Distance})
|
s.PointsOfInterest = append(s.PointsOfInterest, POI{nn.Name, s.Distance})
|
||||||
prevPlace = nn.Name
|
prevPlace = nn.Name
|
||||||
|
prevPlacePoint = thisPoint
|
||||||
}
|
}
|
||||||
prevPoint = thisPoint
|
prevPoint = thisPoint
|
||||||
prevHeight = thisHeight
|
prevHeight = thisHeight
|
||||||
|
|
Loading…
Reference in a new issue