Allow minimum distance between POI and minimum settlement to be overridden
This commit is contained in:
parent
4ae3bcbd37
commit
f0b45fd4c6
2 changed files with 30 additions and 5 deletions
|
@ -19,9 +19,11 @@ import (
|
|||
func main() {
|
||||
log.SetFlags(0)
|
||||
stopNames := flag.String("stops", "", "Source for refreshment stops")
|
||||
minDist := flag.Float64("min-dist", 0.2, "Minimum distance (km) between points of interest")
|
||||
minSettlement := flag.String("min-settlement", "Other Settlement", "Exclude populated places smaller than this (City, Town, Village, Hamlet, Other Settlement)")
|
||||
flag.Parse()
|
||||
if flag.NArg() != 1 {
|
||||
log.Fatal("Usage: %s [--stops=ctccambridge|cyclingmaps] GPX_FILE_OR_DIRECTORY")
|
||||
log.Fatal("Usage: %s [--stops=ctccambridge|cyclingmaps] [--min-dist X] [--min-settlement S] GPX_FILE_OR_DIRECTORY")
|
||||
}
|
||||
inFile := flag.Arg(0)
|
||||
info, err := os.Stat(inFile)
|
||||
|
@ -40,6 +42,8 @@ func main() {
|
|||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
gs.SetMinDistance(*minDist)
|
||||
gs.SetMinSettlement(*minSettlement)
|
||||
if info.IsDir() {
|
||||
err = summarizeDirectory(gs, stops, inFile)
|
||||
} else {
|
||||
|
|
|
@ -13,9 +13,19 @@ import (
|
|||
"github.com/ray1729/gpx-utils/pkg/cafes"
|
||||
)
|
||||
|
||||
var populatedPlaceRank = map[string]int{
|
||||
"City": 5,
|
||||
"Town": 4,
|
||||
"Village": 3,
|
||||
"Hamlet": 3,
|
||||
"Other Settlement": 1,
|
||||
}
|
||||
|
||||
type GPXSummarizer struct {
|
||||
poi *rtreego.Rtree
|
||||
trans osgb.CoordinateTransformer
|
||||
minDist float64
|
||||
minSettlementRank int
|
||||
}
|
||||
|
||||
func NewGPXSummarizer() (*GPXSummarizer, error) {
|
||||
|
@ -27,7 +37,15 @@ func NewGPXSummarizer() (*GPXSummarizer, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &GPXSummarizer{poi: rt, trans: trans}, nil
|
||||
return &GPXSummarizer{poi: rt, trans: trans, minDist: 0.2, minSettlementRank: 1}, nil
|
||||
}
|
||||
|
||||
func (gs *GPXSummarizer) SetMinSettlement(t string) {
|
||||
gs.minSettlementRank = populatedPlaceRank[t]
|
||||
}
|
||||
|
||||
func (gs *GPXSummarizer) SetMinDistance(d float64) {
|
||||
gs.minDist = d
|
||||
}
|
||||
|
||||
func distance(p1, p2 rtreego.Point) float64 {
|
||||
|
@ -116,7 +134,10 @@ func (gs *GPXSummarizer) SummarizeTrack(r io.Reader, stops *rtreego.Rtree) (*Tra
|
|||
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) > 0.2 {
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue