2013-05-17 17:44:50 +04:00
|
|
|
package mapping
|
|
|
|
|
|
|
|
import (
|
2013-08-29 17:44:15 +04:00
|
|
|
"imposm3/element"
|
2013-05-17 17:44:50 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
func (m *Mapping) PointMatcher() *TagMatcher {
|
|
|
|
mappings := make(TagTables)
|
|
|
|
m.mappings("point", mappings)
|
|
|
|
filters := m.ElementFilters()
|
|
|
|
return &TagMatcher{mappings, m.tables("point"), filters}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Mapping) LineStringMatcher() *TagMatcher {
|
|
|
|
mappings := make(TagTables)
|
|
|
|
m.mappings("linestring", mappings)
|
|
|
|
filters := m.ElementFilters()
|
|
|
|
return &TagMatcher{mappings, m.tables("linestring"), filters}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Mapping) PolygonMatcher() *TagMatcher {
|
|
|
|
mappings := make(TagTables)
|
|
|
|
m.mappings("polygon", mappings)
|
|
|
|
filters := m.ElementFilters()
|
|
|
|
return &TagMatcher{mappings, m.tables("polygon"), filters}
|
|
|
|
}
|
|
|
|
|
|
|
|
type TagMatcher struct {
|
|
|
|
mappings TagTables
|
|
|
|
tables map[string]*TableFields
|
|
|
|
filters map[string][]ElementFilter
|
|
|
|
}
|
|
|
|
|
|
|
|
type Match struct {
|
|
|
|
Key string
|
|
|
|
Value string
|
2013-05-27 13:24:22 +04:00
|
|
|
Table DestTable
|
2013-05-17 17:44:50 +04:00
|
|
|
tableFields *TableFields
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Match) Row(elem *element.OSMElem) []interface{} {
|
|
|
|
return m.tableFields.MakeRow(elem, *m)
|
|
|
|
}
|
|
|
|
|
2013-05-23 15:09:47 +04:00
|
|
|
func (tagMatcher *TagMatcher) Match(tags *element.Tags) []Match {
|
2013-05-27 13:24:22 +04:00
|
|
|
tables := make(map[DestTable]Match)
|
2013-05-17 17:44:50 +04:00
|
|
|
|
2013-05-23 15:09:47 +04:00
|
|
|
for k, v := range *tags {
|
2013-05-17 17:44:50 +04:00
|
|
|
values, ok := tagMatcher.mappings[k]
|
|
|
|
if ok {
|
|
|
|
if tbls, ok := values["__any__"]; ok {
|
|
|
|
for _, t := range tbls {
|
2013-05-27 13:24:22 +04:00
|
|
|
tables[t] = Match{k, v, t, tagMatcher.tables[t.Name]}
|
2013-05-17 17:44:50 +04:00
|
|
|
}
|
2014-01-22 14:35:53 +04:00
|
|
|
}
|
|
|
|
if tbls, ok := values[v]; ok {
|
2013-05-17 17:44:50 +04:00
|
|
|
for _, t := range tbls {
|
2013-05-27 13:24:22 +04:00
|
|
|
tables[t] = Match{k, v, t, tagMatcher.tables[t.Name]}
|
2013-05-17 17:44:50 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var matches []Match
|
|
|
|
for t, match := range tables {
|
2013-05-27 13:24:22 +04:00
|
|
|
filters, ok := tagMatcher.filters[t.Name]
|
2013-05-17 17:44:50 +04:00
|
|
|
filteredOut := false
|
|
|
|
if ok {
|
|
|
|
for _, filter := range filters {
|
2013-05-23 15:09:47 +04:00
|
|
|
if !filter(tags) {
|
2013-05-17 17:44:50 +04:00
|
|
|
filteredOut = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !filteredOut {
|
|
|
|
matches = append(matches, match)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return matches
|
|
|
|
}
|