2013-05-14 18:15:35 +04:00
|
|
|
package writer
|
|
|
|
|
|
|
|
import (
|
2014-06-30 10:58:22 +04:00
|
|
|
"runtime"
|
|
|
|
"sync"
|
|
|
|
|
2014-08-04 17:19:35 +04:00
|
|
|
"github.com/omniscale/imposm3/cache"
|
|
|
|
"github.com/omniscale/imposm3/database"
|
|
|
|
"github.com/omniscale/imposm3/element"
|
|
|
|
"github.com/omniscale/imposm3/expire"
|
|
|
|
"github.com/omniscale/imposm3/geom/limit"
|
|
|
|
"github.com/omniscale/imposm3/logging"
|
|
|
|
"github.com/omniscale/imposm3/proj"
|
|
|
|
"github.com/omniscale/imposm3/stats"
|
2013-05-14 18:15:35 +04:00
|
|
|
)
|
|
|
|
|
2013-11-07 18:48:55 +04:00
|
|
|
var log = logging.NewLogger("writer")
|
|
|
|
|
2013-05-21 11:50:10 +04:00
|
|
|
type ErrorLevel interface {
|
|
|
|
Level() int
|
|
|
|
}
|
|
|
|
|
2013-05-28 14:54:19 +04:00
|
|
|
type looper interface {
|
|
|
|
loop()
|
|
|
|
}
|
|
|
|
|
|
|
|
type OsmElemWriter struct {
|
2013-11-08 19:03:58 +04:00
|
|
|
osmCache *cache.OSMCache
|
|
|
|
diffCache *cache.DiffCache
|
|
|
|
progress *stats.Statistics
|
|
|
|
inserter database.Inserter
|
|
|
|
wg *sync.WaitGroup
|
|
|
|
limiter *limit.Limiter
|
|
|
|
writer looper
|
|
|
|
srid int
|
|
|
|
expireor expire.Expireor
|
|
|
|
concurrent bool
|
2013-05-28 14:54:19 +04:00
|
|
|
}
|
|
|
|
|
2013-07-30 10:17:47 +04:00
|
|
|
func (writer *OsmElemWriter) SetLimiter(limiter *limit.Limiter) {
|
|
|
|
writer.limiter = limiter
|
2013-05-28 14:54:19 +04:00
|
|
|
}
|
|
|
|
|
2013-11-04 17:33:32 +04:00
|
|
|
func (writer *OsmElemWriter) EnableConcurrent() {
|
|
|
|
writer.concurrent = true
|
|
|
|
}
|
|
|
|
|
2013-05-28 14:54:19 +04:00
|
|
|
func (writer *OsmElemWriter) Start() {
|
2013-11-04 17:33:32 +04:00
|
|
|
concurrency := 1
|
|
|
|
if writer.concurrent {
|
|
|
|
concurrency = runtime.NumCPU()
|
|
|
|
}
|
|
|
|
for i := 0; i < concurrency; i++ {
|
2013-05-28 14:54:19 +04:00
|
|
|
writer.wg.Add(1)
|
|
|
|
go writer.writer.loop()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-08 19:03:58 +04:00
|
|
|
func (writer *OsmElemWriter) SetExpireor(exp expire.Expireor) {
|
|
|
|
writer.expireor = exp
|
2013-07-12 16:57:06 +04:00
|
|
|
}
|
|
|
|
|
2013-10-29 19:32:16 +04:00
|
|
|
func (writer *OsmElemWriter) Wait() {
|
2013-05-28 14:54:19 +04:00
|
|
|
writer.wg.Wait()
|
|
|
|
}
|
2014-06-30 10:58:22 +04:00
|
|
|
|
|
|
|
func (writer *OsmElemWriter) NodesToSrid(nodes []element.Node) {
|
|
|
|
if writer.srid == 4326 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if writer.srid != 3857 {
|
|
|
|
panic("invalid srid. only 4326 and 3857 are supported")
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, nd := range nodes {
|
|
|
|
nodes[i].Long, nodes[i].Lat = proj.WgsToMerc(nd.Long, nd.Lat)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (writer *OsmElemWriter) NodeToSrid(node *element.Node) {
|
|
|
|
if writer.srid == 4326 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if writer.srid != 3857 {
|
|
|
|
panic("invalid srid. only 4326 and 3857 are supported")
|
|
|
|
}
|
|
|
|
node.Long, node.Lat = proj.WgsToMerc(node.Long, node.Lat)
|
|
|
|
}
|