Add filters to opennames processing. Filter out suburban areas.
This commit is contained in:
parent
9296c8441e
commit
2f9e0e66e3
5 changed files with 112 additions and 29 deletions
33
cmd/localtypes/main.go
Normal file
33
cmd/localtypes/main.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"sort"
|
||||
|
||||
"github.com/ray1729/gpx-utils/pkg/openname"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.SetFlags(0)
|
||||
if len(os.Args) != 2 {
|
||||
log.Fatal("Usage: %s OPNAME_CSV_ZIP", os.Args[0])
|
||||
}
|
||||
var records []*openname.Record
|
||||
openname.ProcessFile(
|
||||
os.Args[1],
|
||||
func(r *openname.Record) error {
|
||||
records = append(records, r)
|
||||
return nil
|
||||
},
|
||||
openname.FilterType("populatedPlace"),
|
||||
openname.FilterWithinRadius(544945, 258410, 20000),
|
||||
)
|
||||
sort.Slice(records, func(i, j int) bool {
|
||||
return records[i].Name < records[j].Name
|
||||
})
|
||||
for _, r := range records {
|
||||
fmt.Printf("%s,%s\n", r.Name, r.LocalType)
|
||||
}
|
||||
}
|
|
@ -1,10 +1,12 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/gob"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/ray1729/gpx-utils/pkg/openname"
|
||||
"github.com/ray1729/gpx-utils/pkg/placenames"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -12,7 +14,28 @@ func main() {
|
|||
if len(os.Args) != 3 {
|
||||
log.Fatal("Usage: %s INFILE OUTFILE", os.Args[0])
|
||||
}
|
||||
if err := openname.Save(os.Args[1], os.Args[2]); err != nil {
|
||||
wc, err := os.OpenFile(os.Args[2], os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0644)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer wc.Close()
|
||||
enc := gob.NewEncoder(wc)
|
||||
err = openname.ProcessFile(
|
||||
os.Args[1],
|
||||
func(r *openname.Record) error {
|
||||
b := placenames.NamedBoundary{
|
||||
Name: r.Name,
|
||||
Xmin: r.MbrXMin,
|
||||
Ymin: r.MbrYMin,
|
||||
Xmax: r.MbrXMax,
|
||||
Ymax: r.MbrYMax}
|
||||
return enc.Encode(b)
|
||||
},
|
||||
openname.FilterType("populatedPlace"),
|
||||
openname.FilterLocalType("Suburban Area").Complement(),
|
||||
openname.FilterAreaGt(0),
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue