convert first column value
parent
84bc8e0fb1
commit
560f659b5b
|
@ -220,6 +220,23 @@ func NewMapping(filename string) (*Mapping, error) {
|
||||||
return &mapping, nil
|
return &mapping, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Bool(val string, tags map[string]string, elem interface{}) interface{} {
|
||||||
|
if val == "" || val == "0" || val == "false" || val == "no" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func Direction(val string, tags map[string]string, elem interface{}) interface{} {
|
||||||
|
if val == "1" || val == "yes" || val == "true" {
|
||||||
|
return 1
|
||||||
|
} else if val == "-1" {
|
||||||
|
return -1
|
||||||
|
} else {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// data := `
|
// data := `
|
||||||
// {
|
// {
|
||||||
|
|
|
@ -22,8 +22,9 @@ type DB interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ColumnSpec struct {
|
type ColumnSpec struct {
|
||||||
Name string
|
Name string
|
||||||
Type string
|
Type string
|
||||||
|
Value func(string, map[string]string, interface{}) interface{}
|
||||||
}
|
}
|
||||||
type TableSpec struct {
|
type TableSpec struct {
|
||||||
Name string
|
Name string
|
||||||
|
@ -65,7 +66,11 @@ func (spec *TableSpec) WayValues(way element.Way) []interface{} {
|
||||||
if !ok {
|
if !ok {
|
||||||
values = append(values, nil)
|
values = append(values, nil)
|
||||||
} else {
|
} else {
|
||||||
values = append(values, v)
|
if col.Value != nil {
|
||||||
|
values = append(values, col.Value(v, way.Tags, way))
|
||||||
|
} else {
|
||||||
|
values = append(values, v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return values
|
return values
|
||||||
|
@ -216,7 +221,7 @@ func (pg *PostGIS) InsertWays(ways []element.Way, spec TableSpec) error {
|
||||||
for _, w := range ways {
|
for _, w := range ways {
|
||||||
_, err := stmt.Exec(spec.WayValues(w)...)
|
_, err := stmt.Exec(spec.WayValues(w)...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &SQLInsertError{SQLError{sql, err}, w}
|
return &SQLInsertError{SQLError{sql, err}, spec.WayValues(w)}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
13
goposm.go
13
goposm.go
|
@ -248,26 +248,27 @@ func main() {
|
||||||
waitFill := sync.WaitGroup{}
|
waitFill := sync.WaitGroup{}
|
||||||
wayChan := make(chan []element.Way)
|
wayChan := make(chan []element.Way)
|
||||||
waitDb := &sync.WaitGroup{}
|
waitDb := &sync.WaitGroup{}
|
||||||
config := db.Config{
|
conf := db.Config{
|
||||||
Type: "postgres",
|
Type: "postgres",
|
||||||
ConnectionParams: *connection,
|
ConnectionParams: *connection,
|
||||||
Srid: 3857,
|
Srid: 3857,
|
||||||
Schema: "public",
|
Schema: "public",
|
||||||
}
|
}
|
||||||
pg, err := db.Open(config)
|
pg, err := db.Open(conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
specs := []db.TableSpec{
|
specs := []db.TableSpec{
|
||||||
{
|
{
|
||||||
"goposm_test",
|
"goposm_test",
|
||||||
config.Schema,
|
conf.Schema,
|
||||||
[]db.ColumnSpec{
|
[]db.ColumnSpec{
|
||||||
{"name", "VARCHAR"},
|
{"name", "VARCHAR", nil},
|
||||||
{"highway", "VARCHAR"},
|
{"highway", "VARCHAR", nil},
|
||||||
|
{"oneway", "SMALLINT", config.Direction},
|
||||||
},
|
},
|
||||||
"GEOMETRY",
|
"GEOMETRY",
|
||||||
config.Srid,
|
conf.Srid,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
err = pg.Init(specs)
|
err = pg.Init(specs)
|
||||||
|
|
Loading…
Reference in New Issue