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
|
*.bin filter=lfs diff=lfs merge=lfs -text
|
||||||
|
pkg/placenames/data.go diff=nodiff
|
||||||
|
|
|
@ -26,6 +26,7 @@ func main() {
|
||||||
b := placenames.NamedBoundary{
|
b := placenames.NamedBoundary{
|
||||||
Name: r.Name,
|
Name: r.Name,
|
||||||
Type: r.LocalType,
|
Type: r.LocalType,
|
||||||
|
County: r.CountyUnitary,
|
||||||
Xmin: r.MbrXMin,
|
Xmin: r.MbrXMin,
|
||||||
Ymin: r.MbrYMin,
|
Ymin: r.MbrYMin,
|
||||||
Xmax: r.MbrXMax,
|
Xmax: r.MbrXMax,
|
||||||
|
|
|
@ -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)
BIN
pkg/placenames/placenames.bin
(Stored with Git LFS)
Binary file not shown.
|
@ -14,6 +14,7 @@ import (
|
||||||
type NamedBoundary struct {
|
type NamedBoundary struct {
|
||||||
Name string
|
Name string
|
||||||
Type string
|
Type string
|
||||||
|
County string
|
||||||
Xmin float64
|
Xmin float64
|
||||||
Ymin float64
|
Ymin float64
|
||||||
Xmax float64
|
Xmax float64
|
||||||
|
|
|
@ -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,20 +130,23 @@ 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]++
|
||||||
|
if nn.Name != prevPlace &&
|
||||||
distance(thisPoint, prevPlacePoint) > gs.minDist &&
|
distance(thisPoint, prevPlacePoint) > gs.minDist &&
|
||||||
populatedPlaceRank[nn.Type] >= gs.minSettlementRank {
|
populatedPlaceRank[nn.Type] >= gs.minSettlementRank {
|
||||||
s.PointsOfInterest = append(s.PointsOfInterest, POI{Name: nn.Name, Type: nn.Type, Distance: s.Distance})
|
s.PointsOfInterest = append(s.PointsOfInterest, POI{Name: nn.Name, Type: nn.Type, Distance: s.Distance})
|
||||||
prevPlace = nn.Name
|
prevPlace = nn.Name
|
||||||
prevPlacePoint = thisPoint
|
prevPlacePoint = thisPoint
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if stops != nil {
|
if stops != nil {
|
||||||
stop, ok := stops.NearestNeighbor(thisPoint).(*cafes.RefreshmentStop)
|
stop, ok := stops.NearestNeighbor(thisPoint).(*cafes.RefreshmentStop)
|
||||||
if ok && stop.Contains(thisPoint) && (prevStop == nil || stop.Name != prevStop.Name) {
|
if ok && stop.Contains(thisPoint) && (prevStop == nil || stop.Name != prevStop.Name) {
|
||||||
|
@ -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 {
|
||||||
|
|
Loading…
Reference in a new issue