Add counties to output (% of ride spent in each county)
This commit is contained in:
parent
f0b45fd4c6
commit
340612e566
7 changed files with 47 additions and 24 deletions
1
.gitattributes
vendored
1
.gitattributes
vendored
|
@ -1 +1,2 @@
|
|||
*.bin filter=lfs diff=lfs merge=lfs -text
|
||||
pkg/placenames/data.go diff=nodiff
|
||||
|
|
|
@ -24,12 +24,13 @@ func main() {
|
|||
os.Args[1],
|
||||
func(r *openname.Record) error {
|
||||
b := placenames.NamedBoundary{
|
||||
Name: r.Name,
|
||||
Type: r.LocalType,
|
||||
Xmin: r.MbrXMin,
|
||||
Ymin: r.MbrYMin,
|
||||
Xmax: r.MbrXMax,
|
||||
Ymax: r.MbrYMax}
|
||||
Name: r.Name,
|
||||
Type: r.LocalType,
|
||||
County: r.CountyUnitary,
|
||||
Xmin: r.MbrXMin,
|
||||
Ymin: r.MbrYMin,
|
||||
Xmax: r.MbrXMax,
|
||||
Ymax: r.MbrYMax}
|
||||
return enc.Encode(b)
|
||||
},
|
||||
openname.FilterType("populatedPlace"),
|
||||
|
|
|
@ -36,7 +36,7 @@ type Record struct {
|
|||
DistrictBoroughUri string
|
||||
DistrictBoroughType string
|
||||
CountyUnitary string
|
||||
ConutyUnitaryUri string
|
||||
CountyUnitaryUri string
|
||||
CountyUnitaryType string
|
||||
Region string
|
||||
RegionUri string
|
||||
|
@ -143,7 +143,7 @@ func parseRecord(xs []string) (*Record, error) {
|
|||
DistrictBoroughUri: xs[22],
|
||||
DistrictBoroughType: xs[23],
|
||||
CountyUnitary: xs[24],
|
||||
ConutyUnitaryUri: xs[25],
|
||||
CountyUnitaryUri: xs[25],
|
||||
CountyUnitaryType: xs[26],
|
||||
Region: xs[27],
|
||||
RegionUri: xs[28],
|
||||
|
|
File diff suppressed because one or more lines are too long
BIN
pkg/placenames/placenames.bin
(Stored with Git LFS)
BIN
pkg/placenames/placenames.bin
(Stored with Git LFS)
Binary file not shown.
|
@ -12,12 +12,13 @@ import (
|
|||
)
|
||||
|
||||
type NamedBoundary struct {
|
||||
Name string
|
||||
Type string
|
||||
Xmin float64
|
||||
Ymin float64
|
||||
Xmax float64
|
||||
Ymax float64
|
||||
Name string
|
||||
Type string
|
||||
County string
|
||||
Xmin float64
|
||||
Ymin float64
|
||||
Xmax float64
|
||||
Ymax float64
|
||||
}
|
||||
|
||||
func (b *NamedBoundary) Bounds() *rtreego.Rect {
|
||||
|
|
|
@ -84,6 +84,7 @@ type TrackSummary struct {
|
|||
Descent float64
|
||||
PointsOfInterest []POI
|
||||
RefreshmentStops []RefreshmentStop `json:",omitempty"`
|
||||
Counties map[string]int
|
||||
}
|
||||
|
||||
func (gs *GPXSummarizer) SummarizeTrack(r io.Reader, stops *rtreego.Rtree) (*TrackSummary, error) {
|
||||
|
@ -94,6 +95,7 @@ func (gs *GPXSummarizer) SummarizeTrack(r io.Reader, stops *rtreego.Rtree) (*Tra
|
|||
var s TrackSummary
|
||||
s.Name = g.Metadata.Name
|
||||
s.Time = g.Metadata.Time
|
||||
s.Counties = make(map[string]int)
|
||||
for _, l := range g.Metadata.Link {
|
||||
if strings.HasPrefix(l.HREF, "http") {
|
||||
s.Link = l.HREF
|
||||
|
@ -128,19 +130,22 @@ func (gs *GPXSummarizer) SummarizeTrack(r io.Reader, stops *rtreego.Rtree) (*Tra
|
|||
prevPlacePoint = thisPoint
|
||||
prevPoint = thisPoint
|
||||
s.PointsOfInterest = append(s.PointsOfInterest, POI{Name: nn.Name, Type: nn.Type, Distance: 0.0})
|
||||
s.Counties[nn.County]++
|
||||
init = false
|
||||
continue
|
||||
}
|
||||
s.Distance += distance(thisPoint, prevPoint)
|
||||
dE += thisPoint[0] - start[0]
|
||||
dN += thisPoint[1] - start[1]
|
||||
if nn.Contains(thisPoint) &&
|
||||
nn.Name != prevPlace &&
|
||||
distance(thisPoint, prevPlacePoint) > gs.minDist &&
|
||||
populatedPlaceRank[nn.Type] >= gs.minSettlementRank {
|
||||
s.PointsOfInterest = append(s.PointsOfInterest, POI{Name: nn.Name, Type: nn.Type, Distance: s.Distance})
|
||||
prevPlace = nn.Name
|
||||
prevPlacePoint = thisPoint
|
||||
if nn.Contains(thisPoint) {
|
||||
s.Counties[nn.County]++
|
||||
if nn.Name != prevPlace &&
|
||||
distance(thisPoint, prevPlacePoint) > gs.minDist &&
|
||||
populatedPlaceRank[nn.Type] >= gs.minSettlementRank {
|
||||
s.PointsOfInterest = append(s.PointsOfInterest, POI{Name: nn.Name, Type: nn.Type, Distance: s.Distance})
|
||||
prevPlace = nn.Name
|
||||
prevPlacePoint = thisPoint
|
||||
}
|
||||
}
|
||||
if stops != nil {
|
||||
stop, ok := stops.NearestNeighbor(thisPoint).(*cafes.RefreshmentStop)
|
||||
|
@ -160,9 +165,24 @@ func (gs *GPXSummarizer) SummarizeTrack(r io.Reader, stops *rtreego.Rtree) (*Tra
|
|||
s.Finish = prevPlace
|
||||
s.Direction = calcDirection(dE, dN)
|
||||
s.Ascent, s.Descent = calcUphillDownhill(elevations)
|
||||
s.Counties = toPercentages(s.Counties)
|
||||
return &s, nil
|
||||
}
|
||||
|
||||
func toPercentages(m map[string]int) map[string]int {
|
||||
t := 0
|
||||
for _, v := range m {
|
||||
t += v
|
||||
}
|
||||
for k, v := range m {
|
||||
m[k] = v * 100 / t
|
||||
if m[k] == 0 {
|
||||
delete(m, k)
|
||||
}
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func calcDirection(dE, dN float64) string {
|
||||
if dN == 0 {
|
||||
if dE >= 0 {
|
||||
|
|
Loading…
Reference in a new issue