unmarshal items in writer
parent
0b4bda5ef2
commit
c314f01886
|
@ -175,6 +175,11 @@ func idFromKeyBuf(buf []byte) int64 {
|
||||||
return int64(bin.BigEndian.Uint64(buf))
|
return int64(bin.BigEndian.Uint64(buf))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RawItem struct {
|
||||||
|
Id int64
|
||||||
|
Data []byte
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Cache) Close() {
|
func (c *Cache) Close() {
|
||||||
if c.db != nil {
|
if c.db != nil {
|
||||||
c.db.Close()
|
c.db.Close()
|
||||||
|
|
|
@ -61,8 +61,8 @@ func (p *WaysCache) GetWay(id int64) (*element.Way, error) {
|
||||||
return way, nil
|
return way, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *WaysCache) Iter() chan *element.Way {
|
func (p *WaysCache) Iter() chan RawItem {
|
||||||
ways := make(chan *element.Way, 1024)
|
ways := make(chan RawItem, 1024)
|
||||||
go func() {
|
go func() {
|
||||||
ro := levigo.NewReadOptions()
|
ro := levigo.NewReadOptions()
|
||||||
ro.SetFillCache(false)
|
ro.SetFillCache(false)
|
||||||
|
@ -70,12 +70,7 @@ func (p *WaysCache) Iter() chan *element.Way {
|
||||||
defer it.Close()
|
defer it.Close()
|
||||||
it.SeekToFirst()
|
it.SeekToFirst()
|
||||||
for ; it.Valid(); it.Next() {
|
for ; it.Valid(); it.Next() {
|
||||||
way, err := binary.UnmarshalWay(it.Value())
|
ways <- RawItem{idFromKeyBuf(it.Key()), it.Value()}
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
way.Id = idFromKeyBuf(it.Key())
|
|
||||||
ways <- way
|
|
||||||
}
|
}
|
||||||
close(ways)
|
close(ways)
|
||||||
}()
|
}()
|
||||||
|
|
|
@ -2,6 +2,7 @@ package writer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"goposm/cache"
|
"goposm/cache"
|
||||||
|
"goposm/cache/binary"
|
||||||
"goposm/database"
|
"goposm/database"
|
||||||
"goposm/element"
|
"goposm/element"
|
||||||
"goposm/geom"
|
"goposm/geom"
|
||||||
|
@ -15,12 +16,12 @@ import (
|
||||||
|
|
||||||
type WayWriter struct {
|
type WayWriter struct {
|
||||||
OsmElemWriter
|
OsmElemWriter
|
||||||
ways chan *element.Way
|
ways chan cache.RawItem
|
||||||
lineStringTagMatcher *mapping.TagMatcher
|
lineStringTagMatcher *mapping.TagMatcher
|
||||||
polygonTagMatcher *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,
|
insertBuffer database.RowInserter, lineStringTagMatcher *mapping.TagMatcher,
|
||||||
polygonTagMatcher *mapping.TagMatcher, progress *stats.Statistics, srid int) *OsmElemWriter {
|
polygonTagMatcher *mapping.TagMatcher, progress *stats.Statistics, srid int) *OsmElemWriter {
|
||||||
ww := WayWriter{
|
ww := WayWriter{
|
||||||
|
@ -44,8 +45,15 @@ func (ww *WayWriter) loop() {
|
||||||
geos := geos.NewGeos()
|
geos := geos.NewGeos()
|
||||||
geos.SetHandleSrid(ww.srid)
|
geos.SetHandleSrid(ww.srid)
|
||||||
defer geos.Finish()
|
defer geos.Finish()
|
||||||
for w := range ww.ways {
|
for item := range ww.ways {
|
||||||
ww.progress.AddWays(1)
|
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)
|
inserted, err := ww.osmCache.InsertedWays.IsInserted(w.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
|
|
Loading…
Reference in New Issue