build linestring and/or polygons depending on the mapping
parent
460f386a24
commit
00405b232b
|
@ -108,6 +108,30 @@ func (m *Mapping) RelationTagFilter() *TagFilter {
|
|||
return &TagFilter{mappings, tags}
|
||||
}
|
||||
|
||||
func (m *Mapping) PointTables() *TagFilter {
|
||||
mappings := make(map[string]map[string][]string)
|
||||
m.mappings("point", mappings)
|
||||
tags := make(map[string]bool)
|
||||
m.extraTags("point", tags)
|
||||
return &TagFilter{mappings, tags}
|
||||
}
|
||||
|
||||
func (m *Mapping) LineStringTables() *TagFilter {
|
||||
mappings := make(map[string]map[string][]string)
|
||||
m.mappings("linestring", mappings)
|
||||
tags := make(map[string]bool)
|
||||
m.extraTags("linestring", tags)
|
||||
return &TagFilter{mappings, tags}
|
||||
}
|
||||
|
||||
func (m *Mapping) PolygonTables() *TagFilter {
|
||||
mappings := make(map[string]map[string][]string)
|
||||
m.mappings("polygon", mappings)
|
||||
tags := make(map[string]bool)
|
||||
m.extraTags("polygon", tags)
|
||||
return &TagFilter{mappings, tags}
|
||||
}
|
||||
|
||||
type TagFilter struct {
|
||||
mappings map[string]map[string][]string
|
||||
extraTags map[string]bool
|
||||
|
|
|
@ -101,6 +101,15 @@ func (e *SQLError) Error() string {
|
|||
return fmt.Sprintf("SQL Error: %s in query %s", e.originalError.Error(), e.query)
|
||||
}
|
||||
|
||||
type SQLInsertError struct {
|
||||
SQLError
|
||||
data interface{}
|
||||
}
|
||||
|
||||
func (e *SQLInsertError) Error() string {
|
||||
return fmt.Sprintf("SQL Error: %s in query %s (%+v)", e.originalError.Error(), e.query, e.data)
|
||||
}
|
||||
|
||||
func (pg *PostGIS) createTable(spec TableSpec) error {
|
||||
var sql string
|
||||
var err error
|
||||
|
@ -207,7 +216,7 @@ func (pg *PostGIS) InsertWays(ways []element.Way, spec TableSpec) error {
|
|||
for _, w := range ways {
|
||||
_, err := stmt.Exec(spec.WayValues(w)...)
|
||||
if err != nil {
|
||||
return &SQLError{sql, err}
|
||||
return &SQLInsertError{SQLError{sql, err}, w}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,10 @@ type Way struct {
|
|||
Wkb []byte
|
||||
}
|
||||
|
||||
func (w *Way) IsClosed() bool {
|
||||
return len(w.Refs) >= 4 && w.Refs[0] == w.Refs[len(w.Refs)-1]
|
||||
}
|
||||
|
||||
type MemberType int
|
||||
|
||||
const (
|
||||
|
|
42
goposm.go
42
goposm.go
|
@ -265,7 +265,7 @@ func main() {
|
|||
{"name", "VARCHAR"},
|
||||
{"highway", "VARCHAR"},
|
||||
},
|
||||
"LINESTRING",
|
||||
"GEOMETRY",
|
||||
config.Srid,
|
||||
},
|
||||
}
|
||||
|
@ -289,7 +289,8 @@ func main() {
|
|||
for i := 0; i < runtime.NumCPU(); i++ {
|
||||
waitFill.Add(1)
|
||||
go func() {
|
||||
// m := mapping.WayTagFilter()
|
||||
lineStringTables := mapping.LineStringTables()
|
||||
polygonTables := mapping.PolygonTables()
|
||||
var err error
|
||||
geos := geos.NewGEOS()
|
||||
defer geos.Finish()
|
||||
|
@ -302,18 +303,41 @@ func main() {
|
|||
continue
|
||||
}
|
||||
proj.NodesToMerc(w.Nodes)
|
||||
w.Wkb, err = geom.LineStringWKB(geos, w.Nodes)
|
||||
if err != nil {
|
||||
if err, ok := err.(ErrorLevel); ok {
|
||||
if err.Level() <= 0 {
|
||||
if tables := lineStringTables.Tables(w.Tags); len(tables) > 0 {
|
||||
way := element.Way{}
|
||||
way.Id = w.Id
|
||||
way.Tags = w.Tags
|
||||
way.Wkb, err = geom.LineStringWKB(geos, w.Nodes)
|
||||
if err != nil {
|
||||
if err, ok := err.(ErrorLevel); ok {
|
||||
if err.Level() <= 0 {
|
||||
continue
|
||||
}
|
||||
}
|
||||
log.Println(err)
|
||||
continue
|
||||
}
|
||||
batch = append(batch, way)
|
||||
}
|
||||
if w.IsClosed() {
|
||||
if tables := polygonTables.Tables(w.Tags); len(tables) > 0 {
|
||||
way := element.Way{}
|
||||
way.Id = w.Id
|
||||
way.Tags = w.Tags
|
||||
way.Wkb, err = geom.PolygonWKB(geos, w.Nodes)
|
||||
if err != nil {
|
||||
if err, ok := err.(ErrorLevel); ok {
|
||||
if err.Level() <= 0 {
|
||||
continue
|
||||
}
|
||||
}
|
||||
log.Println(err)
|
||||
continue
|
||||
}
|
||||
batch = append(batch, way)
|
||||
}
|
||||
log.Println(err)
|
||||
continue
|
||||
}
|
||||
// log.Println(w.Id, w.Tags, m.Tables(w.Tags))
|
||||
batch = append(batch, *w)
|
||||
|
||||
if len(batch) >= int(dbImportBatchSize) {
|
||||
wayChan <- batch
|
||||
|
|
Loading…
Reference in New Issue