add -read/-write/-overwritecache options
parent
75a575c247
commit
6034befe52
|
@ -5,6 +5,7 @@ import (
|
||||||
"github.com/jmhodges/levigo"
|
"github.com/jmhodges/levigo"
|
||||||
"goposm/binary"
|
"goposm/binary"
|
||||||
"goposm/element"
|
"goposm/element"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -14,6 +15,7 @@ type OSMCache struct {
|
||||||
Ways *WaysCache
|
Ways *WaysCache
|
||||||
Nodes *NodesCache
|
Nodes *NodesCache
|
||||||
Relations *RelationsCache
|
Relations *RelationsCache
|
||||||
|
opened bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *OSMCache) Close() {
|
func (c *OSMCache) Close() {
|
||||||
|
@ -35,29 +37,72 @@ func (c *OSMCache) Close() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewOSMCache(dir string) (*OSMCache, error) {
|
func NewOSMCache(dir string) *OSMCache {
|
||||||
cache := &OSMCache{Dir: dir}
|
cache := &OSMCache{Dir: dir}
|
||||||
|
return cache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *OSMCache) Open() error {
|
||||||
var err error
|
var err error
|
||||||
cache.Coords, err = NewDeltaCoordsCache(filepath.Join(dir, "coords"))
|
c.Coords, err = NewDeltaCoordsCache(filepath.Join(c.Dir, "coords"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
cache.Nodes, err = NewNodesCache(filepath.Join(dir, "nodes"))
|
c.Nodes, err = NewNodesCache(filepath.Join(c.Dir, "nodes"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cache.Close()
|
c.Close()
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
cache.Ways, err = NewWaysCache(filepath.Join(dir, "ways"))
|
c.Ways, err = NewWaysCache(filepath.Join(c.Dir, "ways"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cache.Close()
|
c.Close()
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
cache.Relations, err = NewRelationsCache(filepath.Join(dir, "relations"))
|
c.Relations, err = NewRelationsCache(filepath.Join(c.Dir, "relations"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cache.Close()
|
c.Close()
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
return cache, nil
|
c.opened = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *OSMCache) Exists() bool {
|
||||||
|
if c.opened {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if _, err := os.Stat(filepath.Join(c.Dir, "coords")); !os.IsNotExist(err) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if _, err := os.Stat(filepath.Join(c.Dir, "nodes")); !os.IsNotExist(err) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if _, err := os.Stat(filepath.Join(c.Dir, "ways")); !os.IsNotExist(err) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if _, err := os.Stat(filepath.Join(c.Dir, "relations")); !os.IsNotExist(err) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *OSMCache) Remove() error {
|
||||||
|
if c.opened {
|
||||||
|
c.Close()
|
||||||
|
}
|
||||||
|
if err := os.RemoveAll(filepath.Join(c.Dir, "coords")); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := os.RemoveAll(filepath.Join(c.Dir, "nodes")); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := os.RemoveAll(filepath.Join(c.Dir, "ways")); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := os.RemoveAll(filepath.Join(c.Dir, "relations")); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type Cache struct {
|
type Cache struct {
|
||||||
|
|
35
goposm.go
35
goposm.go
|
@ -94,6 +94,10 @@ func parse(cache *cache.OSMCache, progress *stats.Statistics, filename string) {
|
||||||
var (
|
var (
|
||||||
cpuprofile = flag.String("cpuprofile", "", "filename of cpu profile output")
|
cpuprofile = flag.String("cpuprofile", "", "filename of cpu profile output")
|
||||||
cachedir = flag.String("cachedir", "/tmp/goposm", "cache directory")
|
cachedir = flag.String("cachedir", "/tmp/goposm", "cache directory")
|
||||||
|
overwritecache = flag.Bool("overwritecache", false, "overwritecache")
|
||||||
|
appendcache = flag.Bool("appendcache", false, "append cache")
|
||||||
|
read = flag.String("read", "", "read")
|
||||||
|
write = flag.Bool("write", false, "write")
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -110,7 +114,21 @@ func main() {
|
||||||
defer pprof.StopCPUProfile()
|
defer pprof.StopCPUProfile()
|
||||||
}
|
}
|
||||||
|
|
||||||
osmCache, err := cache.NewOSMCache(*cachedir)
|
osmCache := cache.NewOSMCache(*cachedir)
|
||||||
|
|
||||||
|
if *read != "" && osmCache.Exists() {
|
||||||
|
if *overwritecache {
|
||||||
|
log.Println("removing existing cache", *cachedir)
|
||||||
|
err := osmCache.Remove()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("unable to remove cache:", err)
|
||||||
|
}
|
||||||
|
} else if !*appendcache {
|
||||||
|
log.Fatal("cache already exists use -appendcache or -overwritecache")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err := osmCache.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -119,12 +137,15 @@ func main() {
|
||||||
fmt.Println("start")
|
fmt.Println("start")
|
||||||
progress := stats.StatsReporter()
|
progress := stats.StatsReporter()
|
||||||
|
|
||||||
// parse(osmCache, progress, flag.Arg(0))
|
if *read != "" {
|
||||||
|
parse(osmCache, progress, *read)
|
||||||
|
}
|
||||||
|
|
||||||
//rel := osmCache.Relations.Iter()
|
if *write {
|
||||||
//for r := range rel {
|
rel := osmCache.Relations.Iter()
|
||||||
//fmt.Println(r)
|
for r := range rel {
|
||||||
//}
|
fmt.Println(r)
|
||||||
|
}
|
||||||
|
|
||||||
way := osmCache.Ways.Iter()
|
way := osmCache.Ways.Iter()
|
||||||
refCache, err := cache.NewRefIndex("/tmp/refindex")
|
refCache, err := cache.NewRefIndex("/tmp/refindex")
|
||||||
|
@ -153,6 +174,8 @@ func main() {
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
waitFill.Wait()
|
waitFill.Wait()
|
||||||
|
}
|
||||||
|
|
||||||
//parser.PBFStats(os.Args[1])
|
//parser.PBFStats(os.Args[1])
|
||||||
fmt.Println("done")
|
fmt.Println("done")
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ func (c *counter) Print() {
|
||||||
waysPS := float64(c.ways-c.lastWays) / dur.Seconds()
|
waysPS := float64(c.ways-c.lastWays) / dur.Seconds()
|
||||||
relationsPS := float64(c.relations-c.lastRelations) / dur.Seconds()
|
relationsPS := float64(c.relations-c.lastRelations) / dur.Seconds()
|
||||||
|
|
||||||
fmt.Printf("Coords: %8.1f (%10d) Nodes: %6.1f (%9d) Ways: %6.1f (%8d) Relations: %6.1f (%7d)\n",
|
fmt.Printf("Coords: %8.1f (%10d) Nodes: %6.1f (%9d) Ways: %6.1f (%8d) Relations: %6.1f (%7d)\r\b",
|
||||||
coordsPS,
|
coordsPS,
|
||||||
c.coords,
|
c.coords,
|
||||||
nodesPS,
|
nodesPS,
|
||||||
|
|
Loading…
Reference in New Issue