diff --git a/pkg/openname/index.go b/pkg/openname/index.go index 38c538b..336e2d5 100644 --- a/pkg/openname/index.go +++ b/pkg/openname/index.go @@ -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 } diff --git a/pkg/openname/summarize.go b/pkg/openname/summarize.go index ed03f17..c9e513e 100644 --- a/pkg/openname/summarize.go +++ b/pkg/openname/summarize.go @@ -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