unmarshal items in writer

master
Oliver Tonnhofer 2013-06-20 14:21:20 +02:00
parent 0b4bda5ef2
commit c314f01886
3 changed files with 19 additions and 11 deletions

5
cache/osm.go vendored
View File

@ -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()

11
cache/ways.go vendored
View File

@ -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)
}()

View File

@ -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)