add config file for reuse in import/diff cmd
parent
db2c8b2cfb
commit
5cb96d0871
|
@ -0,0 +1,86 @@
|
||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"flag"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
Cachedir string `json:"cachedir"`
|
||||||
|
Connection string `json:"connection"`
|
||||||
|
MappingFile string `json:"mapping"`
|
||||||
|
LimitTo string `json:"limitto"`
|
||||||
|
Srid int `json:"srid"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
connection = flag.String("connection", "", "connection parameters")
|
||||||
|
mappingFile = flag.String("mapping", "", "mapping file")
|
||||||
|
srid = flag.Int("srid", 3857, "srs id")
|
||||||
|
configFile = flag.String("config", "", "config (json)")
|
||||||
|
)
|
||||||
|
|
||||||
|
func Parse() (*Config, []error) {
|
||||||
|
config := &Config{}
|
||||||
|
if *configFile != "" {
|
||||||
|
f, err := os.Open(*configFile)
|
||||||
|
if err != nil {
|
||||||
|
return nil, []error{err}
|
||||||
|
}
|
||||||
|
decoder := json.NewDecoder(f)
|
||||||
|
|
||||||
|
err = decoder.Decode(&config)
|
||||||
|
if err != nil {
|
||||||
|
return nil, []error{err}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if *connection != "" {
|
||||||
|
config.Connection = *connection
|
||||||
|
}
|
||||||
|
if config.Srid == 0 {
|
||||||
|
config.Srid = 3857
|
||||||
|
}
|
||||||
|
if *srid != 3857 {
|
||||||
|
config.Srid = *srid
|
||||||
|
}
|
||||||
|
if *mappingFile != "" {
|
||||||
|
config.MappingFile = *mappingFile
|
||||||
|
}
|
||||||
|
|
||||||
|
errs := checkConfig(config)
|
||||||
|
return config, errs
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkConfig(config *Config) []error {
|
||||||
|
errs := []error{}
|
||||||
|
if config.Srid != 3857 {
|
||||||
|
errs = append(errs, errors.New("srid!=3857 not implemented"))
|
||||||
|
}
|
||||||
|
if config.MappingFile == "" {
|
||||||
|
errs = append(errs, errors.New("missing mapping"))
|
||||||
|
}
|
||||||
|
if config.Connection == "" {
|
||||||
|
errs = append(errs, errors.New("missing connection"))
|
||||||
|
}
|
||||||
|
|
||||||
|
return errs
|
||||||
|
}
|
||||||
|
|
||||||
|
// cpuprofile = flag.String("cpuprofile", "", "filename of cpu profile output")
|
||||||
|
// httpprofile = flag.String("httpprofile", "", "bind address for profile server")
|
||||||
|
// memprofile = flag.String("memprofile", "", "dir name of mem profile output and interval (fname:interval)")
|
||||||
|
// 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")
|
||||||
|
// optimize = flag.Bool("optimize", false, "optimize")
|
||||||
|
// diff = flag.Bool("diff", false, "enable diff support")
|
||||||
|
// mappingFile = flag.String("mapping", "", "mapping file")
|
||||||
|
// deployProduction = flag.Bool("deployproduction", false, "deploy production")
|
||||||
|
// revertDeploy = flag.Bool("revertdeploy", false, "revert deploy to production")
|
||||||
|
// removeBackup = flag.Bool("removebackup", false, "remove backups from deploy")
|
||||||
|
// limitTo = flag.String("limitto", "", "limit to geometries")
|
||||||
|
// quiet = flag.Bool("quiet", false, "quiet log output")
|
30
goposm.go
30
goposm.go
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"goposm/cache"
|
"goposm/cache"
|
||||||
|
"goposm/config"
|
||||||
"goposm/database"
|
"goposm/database"
|
||||||
_ "goposm/database/postgis"
|
_ "goposm/database/postgis"
|
||||||
"goposm/geom/clipper"
|
"goposm/geom/clipper"
|
||||||
|
@ -31,9 +32,7 @@ var (
|
||||||
read = flag.String("read", "", "read")
|
read = flag.String("read", "", "read")
|
||||||
write = flag.Bool("write", false, "write")
|
write = flag.Bool("write", false, "write")
|
||||||
optimize = flag.Bool("optimize", false, "optimize")
|
optimize = flag.Bool("optimize", false, "optimize")
|
||||||
connection = flag.String("connection", "", "connection parameters")
|
|
||||||
diff = flag.Bool("diff", false, "enable diff support")
|
diff = flag.Bool("diff", false, "enable diff support")
|
||||||
mappingFile = flag.String("mapping", "", "mapping file")
|
|
||||||
deployProduction = flag.Bool("deployproduction", false, "deploy production")
|
deployProduction = flag.Bool("deployproduction", false, "deploy production")
|
||||||
revertDeploy = flag.Bool("revertdeploy", false, "revert deploy to production")
|
revertDeploy = flag.Bool("revertdeploy", false, "revert deploy to production")
|
||||||
removeBackup = flag.Bool("removebackup", false, "remove backups from deploy")
|
removeBackup = flag.Bool("removebackup", false, "remove backups from deploy")
|
||||||
|
@ -59,6 +58,15 @@ func main() {
|
||||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||||
}
|
}
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
conf, errs := config.Parse()
|
||||||
|
if len(errs) > 0 {
|
||||||
|
log.Fatal("errors in config/options:")
|
||||||
|
for _, err := range errs {
|
||||||
|
log.Fatalf("\t%s", err)
|
||||||
|
}
|
||||||
|
logging.Shutdown()
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
if *cpuprofile != "" {
|
if *cpuprofile != "" {
|
||||||
f, err := os.Create(*cpuprofile)
|
f, err := os.Create(*cpuprofile)
|
||||||
|
@ -129,21 +137,19 @@ func main() {
|
||||||
|
|
||||||
progress := stats.StatsReporter()
|
progress := stats.StatsReporter()
|
||||||
|
|
||||||
tagmapping, err := mapping.NewMapping(*mappingFile)
|
tagmapping, err := mapping.NewMapping(conf.MappingFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
die(err)
|
die("mapping file: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var db database.DB
|
var db database.DB
|
||||||
|
|
||||||
srid := 3857 // TODO
|
|
||||||
|
|
||||||
if *write || *deployProduction || *revertDeploy || *removeBackup || *optimize {
|
if *write || *deployProduction || *revertDeploy || *removeBackup || *optimize {
|
||||||
connType := database.ConnectionType(*connection)
|
connType := database.ConnectionType(conf.Connection)
|
||||||
conf := database.Config{
|
conf := database.Config{
|
||||||
Type: connType,
|
Type: connType,
|
||||||
ConnectionParams: *connection,
|
ConnectionParams: conf.Connection,
|
||||||
Srid: srid,
|
Srid: conf.Srid,
|
||||||
}
|
}
|
||||||
db, err = database.Open(conf, tagmapping)
|
db, err = database.Open(conf, tagmapping)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -209,7 +215,7 @@ func main() {
|
||||||
|
|
||||||
relations := osmCache.Relations.Iter()
|
relations := osmCache.Relations.Iter()
|
||||||
relWriter := writer.NewRelationWriter(osmCache, diffCache, relations,
|
relWriter := writer.NewRelationWriter(osmCache, diffCache, relations,
|
||||||
db, polygonsTagMatcher, progress, srid)
|
db, polygonsTagMatcher, progress, conf.Srid)
|
||||||
relWriter.SetClipper(geometryClipper)
|
relWriter.SetClipper(geometryClipper)
|
||||||
relWriter.Start()
|
relWriter.Start()
|
||||||
|
|
||||||
|
@ -219,7 +225,7 @@ func main() {
|
||||||
|
|
||||||
ways := osmCache.Ways.Iter()
|
ways := osmCache.Ways.Iter()
|
||||||
wayWriter := writer.NewWayWriter(osmCache, diffCache, ways, db,
|
wayWriter := writer.NewWayWriter(osmCache, diffCache, ways, db,
|
||||||
lineStringsTagMatcher, polygonsTagMatcher, progress, srid)
|
lineStringsTagMatcher, polygonsTagMatcher, progress, conf.Srid)
|
||||||
wayWriter.SetClipper(geometryClipper)
|
wayWriter.SetClipper(geometryClipper)
|
||||||
wayWriter.Start()
|
wayWriter.Start()
|
||||||
|
|
||||||
|
@ -229,7 +235,7 @@ func main() {
|
||||||
|
|
||||||
nodes := osmCache.Nodes.Iter()
|
nodes := osmCache.Nodes.Iter()
|
||||||
nodeWriter := writer.NewNodeWriter(osmCache, nodes, db,
|
nodeWriter := writer.NewNodeWriter(osmCache, nodes, db,
|
||||||
pointsTagMatcher, progress, srid)
|
pointsTagMatcher, progress, conf.Srid)
|
||||||
nodeWriter.SetClipper(geometryClipper)
|
nodeWriter.SetClipper(geometryClipper)
|
||||||
nodeWriter.Start()
|
nodeWriter.Start()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue