import nodes into db
parent
32373dec32
commit
5c174a3ff6
|
@ -314,6 +314,27 @@ func (p *NodesCache) GetNode(id int64) (*element.Node, error) {
|
||||||
return node, nil
|
return node, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *NodesCache) Iter() chan *element.Node {
|
||||||
|
node := make(chan *element.Node)
|
||||||
|
go func() {
|
||||||
|
ro := levigo.NewReadOptions()
|
||||||
|
ro.SetFillCache(false)
|
||||||
|
it := p.db.NewIterator(ro)
|
||||||
|
defer it.Close()
|
||||||
|
it.SeekToFirst()
|
||||||
|
for ; it.Valid(); it.Next() {
|
||||||
|
nodes, err := binary.UnmarshalNode(it.Value())
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
node <- nodes
|
||||||
|
}
|
||||||
|
close(node)
|
||||||
|
}()
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func (p *WaysCache) PutWay(way *element.Way) error {
|
func (p *WaysCache) PutWay(way *element.Way) error {
|
||||||
keyBuf := idToKeyBuf(way.Id)
|
keyBuf := idToKeyBuf(way.Id)
|
||||||
data, err := binary.MarshalWay(way)
|
data, err := binary.MarshalWay(way)
|
||||||
|
|
35
goposm.go
35
goposm.go
|
@ -238,6 +238,8 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
way := osmCache.Ways.Iter()
|
way := osmCache.Ways.Iter()
|
||||||
|
way = make(chan *element.Way)
|
||||||
|
close(way)
|
||||||
|
|
||||||
diffCache := cache.NewDiffCache(*cachedir)
|
diffCache := cache.NewDiffCache(*cachedir)
|
||||||
if err = diffCache.Remove(); err != nil {
|
if err = diffCache.Remove(); err != nil {
|
||||||
|
@ -349,11 +351,42 @@ func main() {
|
||||||
}
|
}
|
||||||
waitFill.Wait()
|
waitFill.Wait()
|
||||||
close(wayChan)
|
close(wayChan)
|
||||||
|
diffCache.Coords.Close()
|
||||||
|
|
||||||
|
nodes := osmCache.Nodes.Iter()
|
||||||
|
points := tagmapping.PointMatcher()
|
||||||
|
geos := geos.NewGEOS()
|
||||||
|
defer geos.Finish()
|
||||||
|
for n := range nodes {
|
||||||
|
progress.AddNodes(1)
|
||||||
|
if matches := points.Match(n.OSMElem); len(matches) > 0 {
|
||||||
|
proj.NodeToMerc(n)
|
||||||
|
node := element.Node{}
|
||||||
|
node.Id = n.Id
|
||||||
|
node.Tags = n.Tags
|
||||||
|
node.Geom, err = geom.PointWKB(geos, *n)
|
||||||
|
if err != nil {
|
||||||
|
if err, ok := err.(ErrorLevel); ok {
|
||||||
|
if err.Level() <= 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.Println(err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, match := range matches {
|
||||||
|
row := match.Row(&node.OSMElem)
|
||||||
|
writeChan <- writer.InsertElement{match.Table, row}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
// fmt.Println(r)
|
||||||
|
}
|
||||||
close(writeChan)
|
close(writeChan)
|
||||||
waitBuffer.Wait()
|
waitBuffer.Wait()
|
||||||
close(writeDBChan)
|
close(writeDBChan)
|
||||||
waitDb.Wait()
|
waitDb.Wait()
|
||||||
diffCache.Coords.Close()
|
|
||||||
}
|
}
|
||||||
progress.Stop()
|
progress.Stop()
|
||||||
|
|
||||||
|
|
|
@ -24,3 +24,7 @@ func NodesToMerc(nodes []element.Node) {
|
||||||
nodes[i].Long, nodes[i].Lat = wgsToMerc(nd.Long, nd.Lat)
|
nodes[i].Long, nodes[i].Lat = wgsToMerc(nd.Long, nd.Lat)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NodeToMerc(node *element.Node) {
|
||||||
|
node.Long, node.Lat = wgsToMerc(node.Long, node.Lat)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue