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