2013-05-21 11:50:10 +04:00
|
|
|
package writer
|
|
|
|
|
|
|
|
import (
|
2015-04-30 10:42:49 +03:00
|
|
|
"sync"
|
|
|
|
|
2014-08-04 17:19:35 +04:00
|
|
|
"github.com/omniscale/imposm3/cache"
|
|
|
|
"github.com/omniscale/imposm3/database"
|
|
|
|
"github.com/omniscale/imposm3/element"
|
2015-04-30 10:42:49 +03:00
|
|
|
geomp "github.com/omniscale/imposm3/geom"
|
2014-08-04 17:19:35 +04:00
|
|
|
"github.com/omniscale/imposm3/geom/geos"
|
|
|
|
"github.com/omniscale/imposm3/mapping"
|
|
|
|
"github.com/omniscale/imposm3/stats"
|
2013-05-21 11:50:10 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
type NodeWriter struct {
|
2013-05-28 14:54:19 +04:00
|
|
|
OsmElemWriter
|
2014-05-05 12:21:46 +04:00
|
|
|
nodes chan *element.Node
|
2014-06-19 13:51:15 +04:00
|
|
|
pointMatcher mapping.NodeMatcher
|
2013-05-21 11:50:10 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 12:21:46 +04:00
|
|
|
func NewNodeWriter(
|
|
|
|
osmCache *cache.OSMCache,
|
|
|
|
nodes chan *element.Node,
|
|
|
|
inserter database.Inserter,
|
|
|
|
progress *stats.Statistics,
|
2014-06-19 13:51:15 +04:00
|
|
|
matcher mapping.NodeMatcher,
|
2014-05-05 12:21:46 +04:00
|
|
|
srid int,
|
|
|
|
) *OsmElemWriter {
|
2013-05-21 11:50:10 +04:00
|
|
|
nw := NodeWriter{
|
2013-05-28 14:54:19 +04:00
|
|
|
OsmElemWriter: OsmElemWriter{
|
2013-10-28 11:26:51 +04:00
|
|
|
osmCache: osmCache,
|
|
|
|
progress: progress,
|
|
|
|
wg: &sync.WaitGroup{},
|
|
|
|
inserter: inserter,
|
|
|
|
srid: srid,
|
2013-05-28 14:54:19 +04:00
|
|
|
},
|
2014-05-05 12:21:46 +04:00
|
|
|
pointMatcher: matcher,
|
|
|
|
nodes: nodes,
|
2013-05-21 11:50:10 +04:00
|
|
|
}
|
2013-05-28 14:54:19 +04:00
|
|
|
nw.OsmElemWriter.writer = &nw
|
|
|
|
return &nw.OsmElemWriter
|
2013-05-21 11:50:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (nw *NodeWriter) loop() {
|
2013-05-24 12:08:38 +04:00
|
|
|
geos := geos.NewGeos()
|
2013-06-19 11:19:21 +04:00
|
|
|
geos.SetHandleSrid(nw.srid)
|
2013-05-21 11:50:10 +04:00
|
|
|
defer geos.Finish()
|
|
|
|
|
|
|
|
for n := range nw.nodes {
|
|
|
|
nw.progress.AddNodes(1)
|
2014-06-19 13:51:15 +04:00
|
|
|
if matches := nw.pointMatcher.MatchNode(n); len(matches) > 0 {
|
2013-11-08 19:03:58 +04:00
|
|
|
if nw.expireor != nil {
|
|
|
|
nw.expireor.Expire(n.Long, n.Lat)
|
2013-07-12 17:12:56 +04:00
|
|
|
}
|
2016-11-22 19:06:58 +03:00
|
|
|
nw.NodeToSrid(n)
|
2015-04-30 10:42:49 +03:00
|
|
|
point, err := geomp.Point(geos, *n)
|
2013-05-21 11:50:10 +04:00
|
|
|
if err != nil {
|
2014-04-28 13:43:25 +04:00
|
|
|
if errl, ok := err.(ErrorLevel); !ok || errl.Level() > 0 {
|
|
|
|
log.Warn(err)
|
2013-05-21 11:50:10 +04:00
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
2013-06-19 11:19:21 +04:00
|
|
|
|
2015-04-30 10:42:49 +03:00
|
|
|
geom, err := geomp.AsGeomElement(geos, point)
|
2013-06-19 11:19:21 +04:00
|
|
|
if err != nil {
|
2013-11-07 18:48:55 +04:00
|
|
|
log.Warn(err)
|
2013-06-19 11:19:21 +04:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2013-07-30 10:17:47 +04:00
|
|
|
if nw.limiter != nil {
|
2015-04-30 10:42:49 +03:00
|
|
|
parts, err := nw.limiter.Clip(geom.Geom)
|
2013-05-28 10:59:59 +04:00
|
|
|
if err != nil {
|
2013-11-07 18:48:55 +04:00
|
|
|
log.Warn(err)
|
2013-05-28 10:59:59 +04:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
if len(parts) >= 1 {
|
2015-04-30 10:42:49 +03:00
|
|
|
if err := nw.inserter.InsertPoint(n.OSMElem, geom, matches); err != nil {
|
2014-04-28 13:43:25 +04:00
|
|
|
log.Warn(err)
|
|
|
|
continue
|
|
|
|
}
|
2013-05-28 10:59:59 +04:00
|
|
|
}
|
|
|
|
} else {
|
2015-04-30 10:42:49 +03:00
|
|
|
if err := nw.inserter.InsertPoint(n.OSMElem, geom, matches); err != nil {
|
2014-04-28 13:43:25 +04:00
|
|
|
log.Warn(err)
|
|
|
|
continue
|
|
|
|
}
|
2013-05-21 11:50:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nw.wg.Done()
|
|
|
|
}
|