Add counties to output (% of ride spent in each county)

This commit is contained in:
Ray Miller 2020-10-31 16:17:36 +00:00
parent f0b45fd4c6
commit 340612e566
7 changed files with 47 additions and 24 deletions

1
.gitattributes vendored
View file

@ -1 +1,2 @@
*.bin filter=lfs diff=lfs merge=lfs -text *.bin filter=lfs diff=lfs merge=lfs -text
pkg/placenames/data.go diff=nodiff

View file

@ -24,12 +24,13 @@ func main() {
os.Args[1], os.Args[1],
func(r *openname.Record) error { func(r *openname.Record) error {
b := placenames.NamedBoundary{ b := placenames.NamedBoundary{
Name: r.Name, Name: r.Name,
Type: r.LocalType, Type: r.LocalType,
Xmin: r.MbrXMin, County: r.CountyUnitary,
Ymin: r.MbrYMin, Xmin: r.MbrXMin,
Xmax: r.MbrXMax, Ymin: r.MbrYMin,
Ymax: r.MbrYMax} Xmax: r.MbrXMax,
Ymax: r.MbrYMax}
return enc.Encode(b) return enc.Encode(b)
}, },
openname.FilterType("populatedPlace"), openname.FilterType("populatedPlace"),

View file

@ -36,7 +36,7 @@ type Record struct {
DistrictBoroughUri string DistrictBoroughUri string
DistrictBoroughType string DistrictBoroughType string
CountyUnitary string CountyUnitary string
ConutyUnitaryUri string CountyUnitaryUri string
CountyUnitaryType string CountyUnitaryType string
Region string Region string
RegionUri string RegionUri string
@ -143,7 +143,7 @@ func parseRecord(xs []string) (*Record, error) {
DistrictBoroughUri: xs[22], DistrictBoroughUri: xs[22],
DistrictBoroughType: xs[23], DistrictBoroughType: xs[23],
CountyUnitary: xs[24], CountyUnitary: xs[24],
ConutyUnitaryUri: xs[25], CountyUnitaryUri: xs[25],
CountyUnitaryType: xs[26], CountyUnitaryType: xs[26],
Region: xs[27], Region: xs[27],
RegionUri: xs[28], RegionUri: xs[28],

File diff suppressed because one or more lines are too long

BIN
pkg/placenames/placenames.bin (Stored with Git LFS)

Binary file not shown.

View file

@ -12,12 +12,13 @@ import (
) )
type NamedBoundary struct { type NamedBoundary struct {
Name string Name string
Type string Type string
Xmin float64 County string
Ymin float64 Xmin float64
Xmax float64 Ymin float64
Ymax float64 Xmax float64
Ymax float64
} }
func (b *NamedBoundary) Bounds() *rtreego.Rect { func (b *NamedBoundary) Bounds() *rtreego.Rect {

View file

@ -84,6 +84,7 @@ type TrackSummary struct {
Descent float64 Descent float64
PointsOfInterest []POI PointsOfInterest []POI
RefreshmentStops []RefreshmentStop `json:",omitempty"` RefreshmentStops []RefreshmentStop `json:",omitempty"`
Counties map[string]int
} }
func (gs *GPXSummarizer) SummarizeTrack(r io.Reader, stops *rtreego.Rtree) (*TrackSummary, error) { 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 var s TrackSummary
s.Name = g.Metadata.Name s.Name = g.Metadata.Name
s.Time = g.Metadata.Time s.Time = g.Metadata.Time
s.Counties = make(map[string]int)
for _, l := range g.Metadata.Link { for _, l := range g.Metadata.Link {
if strings.HasPrefix(l.HREF, "http") { if strings.HasPrefix(l.HREF, "http") {
s.Link = l.HREF s.Link = l.HREF
@ -128,19 +130,22 @@ func (gs *GPXSummarizer) SummarizeTrack(r io.Reader, stops *rtreego.Rtree) (*Tra
prevPlacePoint = thisPoint prevPlacePoint = thisPoint
prevPoint = thisPoint prevPoint = thisPoint
s.PointsOfInterest = append(s.PointsOfInterest, POI{Name: nn.Name, Type: nn.Type, Distance: 0.0}) s.PointsOfInterest = append(s.PointsOfInterest, POI{Name: nn.Name, Type: nn.Type, Distance: 0.0})
s.Counties[nn.County]++
init = false init = false
continue continue
} }
s.Distance += distance(thisPoint, prevPoint) s.Distance += distance(thisPoint, prevPoint)
dE += thisPoint[0] - start[0] dE += thisPoint[0] - start[0]
dN += thisPoint[1] - start[1] dN += thisPoint[1] - start[1]
if nn.Contains(thisPoint) && if nn.Contains(thisPoint) {
nn.Name != prevPlace && s.Counties[nn.County]++
distance(thisPoint, prevPlacePoint) > gs.minDist && if nn.Name != prevPlace &&
populatedPlaceRank[nn.Type] >= gs.minSettlementRank { distance(thisPoint, prevPlacePoint) > gs.minDist &&
s.PointsOfInterest = append(s.PointsOfInterest, POI{Name: nn.Name, Type: nn.Type, Distance: s.Distance}) populatedPlaceRank[nn.Type] >= gs.minSettlementRank {
prevPlace = nn.Name s.PointsOfInterest = append(s.PointsOfInterest, POI{Name: nn.Name, Type: nn.Type, Distance: s.Distance})
prevPlacePoint = thisPoint prevPlace = nn.Name
prevPlacePoint = thisPoint
}
} }
if stops != nil { if stops != nil {
stop, ok := stops.NearestNeighbor(thisPoint).(*cafes.RefreshmentStop) 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.Finish = prevPlace
s.Direction = calcDirection(dE, dN) s.Direction = calcDirection(dE, dN)
s.Ascent, s.Descent = calcUphillDownhill(elevations) s.Ascent, s.Descent = calcUphillDownhill(elevations)
s.Counties = toPercentages(s.Counties)
return &s, nil 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 { func calcDirection(dE, dN float64) string {
if dN == 0 { if dN == 0 {
if dE >= 0 { if dE >= 0 {