From d51cda1ffc09d92af70d601c775437e20d360eee Mon Sep 17 00:00:00 2001 From: Oliver Tonnhofer Date: Tue, 14 May 2013 10:04:11 +0200 Subject: [PATCH] move config package into mapping package --- goposm.go | 20 ++++++++++---------- {config => mapping}/config.go | 2 +- mapping/filter.go | 33 --------------------------------- 3 files changed, 11 insertions(+), 44 deletions(-) rename {config => mapping}/config.go (99%) diff --git a/goposm.go b/goposm.go index 1b6ad28..53b2234 100644 --- a/goposm.go +++ b/goposm.go @@ -3,11 +3,11 @@ package main import ( "flag" "goposm/cache" - "goposm/config" "goposm/db" "goposm/element" "goposm/geom" "goposm/geom/geos" + "goposm/mapping" "goposm/parser" "goposm/proj" "goposm/stats" @@ -47,7 +47,7 @@ type ErrorLevel interface { Level() int } -func parse(cache *cache.OSMCache, progress *stats.Statistics, mapping *config.Mapping, filename string) { +func parse(cache *cache.OSMCache, progress *stats.Statistics, tagmapping *mapping.Mapping, filename string) { nodes := make(chan []element.Node) coords := make(chan []element.Node) ways := make(chan []element.Way) @@ -78,7 +78,7 @@ func parse(cache *cache.OSMCache, progress *stats.Statistics, mapping *config.Ma for i := 0; i < runtime.NumCPU(); i++ { waitCounter.Add(1) go func() { - m := mapping.WayTagFilter() + m := tagmapping.WayTagFilter() for ws := range ways { if skipWays { continue @@ -95,7 +95,7 @@ func parse(cache *cache.OSMCache, progress *stats.Statistics, mapping *config.Ma for i := 0; i < runtime.NumCPU(); i++ { waitCounter.Add(1) go func() { - m := mapping.RelationTagFilter() + m := tagmapping.RelationTagFilter() for rels := range relations { for _, r := range rels { m.Filter(r.Tags) @@ -122,7 +122,7 @@ func parse(cache *cache.OSMCache, progress *stats.Statistics, mapping *config.Ma for i := 0; i < 2; i++ { waitCounter.Add(1) go func() { - m := mapping.NodeTagFilter() + m := tagmapping.NodeTagFilter() for nds := range nodes { if skipNodes { continue @@ -214,14 +214,14 @@ func main() { progress := stats.StatsReporter() - mapping, err := config.NewMapping(*mappingFile) + tagmapping, err := mapping.NewMapping(*mappingFile) if err != nil { log.Fatal(err) } if *read != "" { osmCache.Coords.SetLinearImport(true) - parse(osmCache, progress, mapping, *read) + parse(osmCache, progress, tagmapping, *read) osmCache.Coords.SetLinearImport(false) progress.Reset() osmCache.Coords.Flush() @@ -265,7 +265,7 @@ func main() { []db.ColumnSpec{ {"name", "VARCHAR", nil}, {"highway", "VARCHAR", nil}, - {"oneway", "SMALLINT", config.Direction}, + {"oneway", "SMALLINT", mapping.Direction}, }, "GEOMETRY", conf.Srid, @@ -291,8 +291,8 @@ func main() { for i := 0; i < runtime.NumCPU(); i++ { waitFill.Add(1) go func() { - lineStringTables := mapping.LineStringTables() - polygonTables := mapping.PolygonTables() + lineStringTables := tagmapping.LineStringTables() + polygonTables := tagmapping.PolygonTables() var err error geos := geos.NewGEOS() defer geos.Finish() diff --git a/config/config.go b/mapping/config.go similarity index 99% rename from config/config.go rename to mapping/config.go index bc9ebf5..d1287b9 100644 --- a/config/config.go +++ b/mapping/config.go @@ -1,4 +1,4 @@ -package config +package mapping import ( "encoding/json" diff --git a/mapping/filter.go b/mapping/filter.go index 588b231..1aa9355 100644 --- a/mapping/filter.go +++ b/mapping/filter.go @@ -1,44 +1,11 @@ package mapping -import ( - "goposm/element" -) - type TagMap map[string]map[string]bool var PointTags TagMap var WayTags TagMap var RelationTags TagMap -type TagFilter interface { - Filter(element.Tags) bool -} - -func (m TagMap) Filter(tags element.Tags) bool { - for k, v := range tags { - values, ok := m[k] - if !ok { - delete(tags, k) - } else { - if _, ok := values["__any__"]; ok { - continue - } else if _, ok := values[v]; ok { - continue - } else { - delete(tags, k) - } - } - } - if _, ok := tags["name"]; ok && len(tags) == 1 { - delete(tags, "name") - } - if len(tags) > 0 { - return true - } else { - return false - } -} - // default mapping created from imposm defaultmapping.py // TODO make configurable func init() {