diff --git a/cache/osm.go b/cache/osm.go index f146743..cd5797d 100644 --- a/cache/osm.go +++ b/cache/osm.go @@ -175,11 +175,6 @@ func idFromKeyBuf(buf []byte) int64 { return int64(bin.BigEndian.Uint64(buf)) } -type RawItem struct { - Id int64 - Data []byte -} - func (c *Cache) Close() { if c.db != nil { c.db.Close() diff --git a/cache/ways.go b/cache/ways.go index 3dfc318..b5a4bf8 100644 --- a/cache/ways.go +++ b/cache/ways.go @@ -61,8 +61,8 @@ func (p *WaysCache) GetWay(id int64) (*element.Way, error) { return way, nil } -func (p *WaysCache) Iter() chan RawItem { - ways := make(chan RawItem, 1024) +func (p *WaysCache) Iter() chan *element.Way { + ways := make(chan *element.Way, 1024) go func() { ro := levigo.NewReadOptions() ro.SetFillCache(false) @@ -70,7 +70,12 @@ func (p *WaysCache) Iter() chan RawItem { defer it.Close() it.SeekToFirst() for ; it.Valid(); it.Next() { - ways <- RawItem{idFromKeyBuf(it.Key()), it.Value()} + way, err := binary.UnmarshalWay(it.Value()) + if err != nil { + panic(err) + } + way.Id = idFromKeyBuf(it.Key()) + ways <- way } close(ways) }() diff --git a/writer/ways.go b/writer/ways.go index 363e4ac..94859b9 100644 --- a/writer/ways.go +++ b/writer/ways.go @@ -2,7 +2,6 @@ package writer import ( "goposm/cache" - "goposm/cache/binary" "goposm/database" "goposm/element" "goposm/geom" @@ -16,12 +15,12 @@ import ( type WayWriter struct { OsmElemWriter - ways chan cache.RawItem + ways chan *element.Way lineStringTagMatcher *mapping.TagMatcher polygonTagMatcher *mapping.TagMatcher } -func NewWayWriter(osmCache *cache.OSMCache, diffCache *cache.DiffCache, ways chan cache.RawItem, +func NewWayWriter(osmCache *cache.OSMCache, diffCache *cache.DiffCache, ways chan *element.Way, insertBuffer database.RowInserter, lineStringTagMatcher *mapping.TagMatcher, polygonTagMatcher *mapping.TagMatcher, progress *stats.Statistics, srid int) *OsmElemWriter { ww := WayWriter{ @@ -45,15 +44,8 @@ func (ww *WayWriter) loop() { geos := geos.NewGeos() geos.SetHandleSrid(ww.srid) defer geos.Finish() - for item := range ww.ways { + for w := range ww.ways { ww.progress.AddWays(1) - - w, err := binary.UnmarshalWay(item.Data) - if err != nil { - panic(err) - } - w.Id = item.Id - inserted, err := ww.osmCache.InsertedWays.IsInserted(w.Id) if err != nil { log.Println(err)