mark/skip inserted ways from mulitpolygon relations; reproject relation geometries
parent
2776061ba7
commit
decb17cb4c
|
@ -40,12 +40,13 @@ var (
|
|||
)
|
||||
|
||||
type OSMCache struct {
|
||||
Dir string
|
||||
Coords *DeltaCoordsCache
|
||||
Ways *WaysCache
|
||||
Nodes *NodesCache
|
||||
Relations *RelationsCache
|
||||
opened bool
|
||||
Dir string
|
||||
Coords *DeltaCoordsCache
|
||||
Ways *WaysCache
|
||||
Nodes *NodesCache
|
||||
Relations *RelationsCache
|
||||
InsertedWays *InsertedWaysCache
|
||||
opened bool
|
||||
}
|
||||
|
||||
func (c *OSMCache) Close() {
|
||||
|
@ -96,6 +97,11 @@ func (c *OSMCache) Open() error {
|
|||
c.Close()
|
||||
return err
|
||||
}
|
||||
c.InsertedWays, err = NewInsertedWaysCache(filepath.Join(c.Dir, "inserted_ways"))
|
||||
if err != nil {
|
||||
c.Close()
|
||||
return err
|
||||
}
|
||||
c.opened = true
|
||||
return nil
|
||||
}
|
||||
|
@ -116,6 +122,9 @@ func (c *OSMCache) Exists() bool {
|
|||
if _, err := os.Stat(filepath.Join(c.Dir, "relations")); !os.IsNotExist(err) {
|
||||
return true
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(c.Dir, "inserted_ways")); !os.IsNotExist(err) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -135,6 +144,9 @@ func (c *OSMCache) Remove() error {
|
|||
if err := os.RemoveAll(filepath.Join(c.Dir, "relations")); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.RemoveAll(filepath.Join(c.Dir, "inserted_ways")); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -220,6 +232,19 @@ func NewWaysCache(path string) (*WaysCache, error) {
|
|||
return &cache, err
|
||||
}
|
||||
|
||||
type InsertedWaysCache struct {
|
||||
Cache
|
||||
}
|
||||
|
||||
func NewInsertedWaysCache(path string) (*InsertedWaysCache, error) {
|
||||
cache := InsertedWaysCache{}
|
||||
err := cache.open(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &cache, err
|
||||
}
|
||||
|
||||
type RelationsCache struct {
|
||||
Cache
|
||||
}
|
||||
|
@ -506,3 +531,29 @@ func (p *RelationsCache) GetRelation(id int64) (*element.Relation, error) {
|
|||
func (p *Cache) Close() {
|
||||
p.db.Close()
|
||||
}
|
||||
|
||||
func (p *InsertedWaysCache) PutMembers(members []element.Member) error {
|
||||
batch := levigo.NewWriteBatch()
|
||||
defer batch.Close()
|
||||
|
||||
for _, m := range members {
|
||||
if m.Type != element.WAY {
|
||||
continue
|
||||
}
|
||||
keyBuf := idToKeyBuf(m.Id)
|
||||
batch.Put(keyBuf, []byte{})
|
||||
}
|
||||
return p.db.Write(p.wo, batch)
|
||||
}
|
||||
|
||||
func (p *InsertedWaysCache) IsInserted(id int64) (bool, error) {
|
||||
keyBuf := idToKeyBuf(id)
|
||||
data, err := p.db.Get(p.ro, keyBuf)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if data == nil {
|
||||
return false, nil
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
|
21
goposm.go
21
goposm.go
|
@ -305,6 +305,7 @@ func main() {
|
|||
fmt.Println(err)
|
||||
continue
|
||||
}
|
||||
proj.NodesToMerc(m.Way.Nodes)
|
||||
}
|
||||
|
||||
err = geom.BuildRelation(r)
|
||||
|
@ -317,11 +318,14 @@ func main() {
|
|||
row := match.Row(&r.OSMElem)
|
||||
writeChan <- writer.InsertElement{match.Table, row}
|
||||
}
|
||||
err := osmCache.InsertedWays.PutMembers(r.Members)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
// way := osmCache.Ways.Iter()
|
||||
way := make(chan *element.Way)
|
||||
close(way)
|
||||
way := osmCache.Ways.Iter()
|
||||
|
||||
for i := 0; i < runtime.NumCPU(); i++ {
|
||||
waitFill.Add(1)
|
||||
go func() {
|
||||
|
@ -332,7 +336,16 @@ func main() {
|
|||
|
||||
for w := range way {
|
||||
progress.AddWays(1)
|
||||
err := osmCache.Coords.FillWay(w)
|
||||
inserted, err := osmCache.InsertedWays.IsInserted(w.Id)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
continue
|
||||
}
|
||||
if inserted {
|
||||
continue
|
||||
}
|
||||
|
||||
err = osmCache.Coords.FillWay(w)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue