forked from omniscale/imposm3
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimposm3.go
112 lines (98 loc) · 2.42 KB
/
imposm3.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package main
import (
"fmt"
"imposm3/cache"
golog "log"
"os"
"runtime"
"imposm3/cache/query"
"imposm3/config"
"imposm3/diff"
"imposm3/geom/limit"
"imposm3/import_"
"imposm3/logging"
"imposm3/stats"
)
var log = logging.NewLogger("")
func printCmds() {
fmt.Fprintf(os.Stderr, "Usage: %s COMMAND [args]\n\n", os.Args[0])
fmt.Println("Available commands:")
fmt.Println("\timport")
fmt.Println("\tdiff")
fmt.Println("\tquery-cache")
fmt.Println("\tversion")
}
func main() {
golog.SetFlags(golog.LstdFlags | golog.Lshortfile)
if os.Getenv("GOMAXPROCS") == "" {
runtime.GOMAXPROCS(runtime.NumCPU())
}
if len(os.Args) <= 1 {
printCmds()
logging.Shutdown()
os.Exit(1)
}
switch os.Args[1] {
case "import":
config.ParseImport(os.Args[2:])
if config.BaseOptions.Httpprofile != "" {
stats.StartHttpPProf(config.BaseOptions.Httpprofile)
}
import_.Import()
case "diff":
config.ParseDiffImport(os.Args[2:])
if config.BaseOptions.Httpprofile != "" {
stats.StartHttpPProf(config.BaseOptions.Httpprofile)
}
if config.BaseOptions.Quiet {
logging.SetQuiet(true)
}
var geometryLimiter *limit.Limiter
if config.BaseOptions.LimitTo != "" {
var err error
step := log.StartStep("Reading limitto geometries")
geometryLimiter, err = limit.NewFromGeoJsonWithBuffered(
config.BaseOptions.LimitTo,
config.BaseOptions.LimitToCacheBuffer,
)
if err != nil {
log.Fatal(err)
}
log.StopStep(step)
}
osmCache := cache.NewOSMCache(config.BaseOptions.CacheDir)
err := osmCache.Open()
if err != nil {
log.Fatal("osm cache: ", err)
}
defer osmCache.Close()
diffCache := cache.NewDiffCache(config.BaseOptions.CacheDir)
err = diffCache.Open()
if err != nil {
log.Fatal("diff cache: ", err)
}
// @todo create a construction where the diffs are processed from the openstreetmap url when
// no diff files are given as argument
for _, oscFile := range config.DiffFlags.Args() {
err := diff.Update(oscFile, geometryLimiter, nil, osmCache, diffCache, false)
if err != nil {
osmCache.Close()
diffCache.Close()
log.Fatal(err)
}
}
// explicitly Close since os.Exit prevents defers
osmCache.Close()
diffCache.Close()
case "query-cache":
query.Query(os.Args[2:])
case "version":
fmt.Println(imposmVersion)
os.Exit(0)
default:
printCmds()
log.Fatalf("invalid command: '%s'", os.Args[1])
}
logging.Shutdown()
os.Exit(0)
}