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 (
|
||||
"archive/zip"
|
||||
"log"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/dhconnelly/rtreego"
|
||||
|
@ -11,7 +11,7 @@ import (
|
|||
func BuildIndex(filename string) (*rtreego.Rtree, error) {
|
||||
r, err := zip.OpenReader(filename)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return nil, fmt.Errorf("error opening %s fo reading: %v", filename, err)
|
||||
}
|
||||
defer r.Close()
|
||||
rt := rtreego.NewTree(2, 25, 50)
|
||||
|
@ -21,12 +21,12 @@ func BuildIndex(filename string) (*rtreego.Rtree, error) {
|
|||
}
|
||||
rc, err := f.Open()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return nil, fmt.Errorf("erorr opening %s: %v", filename, err)
|
||||
}
|
||||
defer rc.Close()
|
||||
s, err := NewScanner(rc)
|
||||
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() {
|
||||
r := s.Record()
|
||||
|
@ -35,8 +35,10 @@ func BuildIndex(filename string) (*rtreego.Rtree, error) {
|
|||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
|
|
|
@ -78,6 +78,7 @@ func (gs *GPXSummarizer) SummarizeTrack(filename string) (*TrackSummary, error)
|
|||
}
|
||||
|
||||
var prevPlace string
|
||||
var prevPlacePoint rtreego.Point
|
||||
var prevPoint rtreego.Point
|
||||
var prevHeight float64
|
||||
|
||||
|
@ -96,6 +97,7 @@ func (gs *GPXSummarizer) SummarizeTrack(filename string) (*TrackSummary, error)
|
|||
if init {
|
||||
s.Start = nn.Name
|
||||
prevPlace = nn.Name
|
||||
prevPlacePoint = thisPoint
|
||||
prevPoint = thisPoint
|
||||
prevHeight = thisHeight
|
||||
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 {
|
||||
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})
|
||||
prevPlace = nn.Name
|
||||
prevPlacePoint = thisPoint
|
||||
}
|
||||
prevPoint = thisPoint
|
||||
prevHeight = thisHeight
|
||||
|
|
Loading…
Reference in a new issue