Exemplo n.º 1
0
func (ex *Excavator) dredge() {
	util.Info("Starting dredger")
	defer ex.dredgers.Done()
	for {
		if val, err := ex.pbf.Decode(); err == io.EOF {
			break
		} else if err != nil {
			ex.errs <- err
			break
		} else {
			switch val := val.(type) {
			case *osmpbf.Node:
				o := &Node{val}
				if o.Valid() {
					ex.nodes <- o
				}
			case *osmpbf.Way:
				o := &Way{val}
				if o.Valid() {
					ex.ways <- o
				}
			case *osmpbf.Relation:
				ex.relations <- &Relation{val}
			default:
				ex.errs <- util.Errorf("Unknown OSM Type %T %v", val, val)
			}
		}
	}
	util.Info("Closing dredger")
}
Exemplo n.º 2
0
func (s *Shape) ToCommands() (cmds []*command) {
	switch s.geomType {
	case vt.Tile_POINT:
		move := newCmd(MoveTo, s.Head().X, s.Head().Y)
		cmds = []*command{move}
	case vt.Tile_LINESTRING:
		move := newCmd(MoveTo, s.Head().X, s.Head().Y)
		cmds = []*command{move}
		for _, p := range s.points[1:] {
			line := newCmd(LineTo, p.X, p.Y)
			cmds = append(cmds, line)
		}
	case vt.Tile_POLYGON:
		move := newCmd(MoveTo, s.Head().X, s.Head().Y)
		cmds = []*command{move}
		for _, p := range s.points[1:] {
			line := newCmd(LineTo, p.X, p.Y)
			cmds = append(cmds, line)
		}
		closep := newCmd(ClosePath)
		cmds = append(cmds, closep)
	default:
		util.Info("Unknown Geometry in ToCommands")
		cmds = []*command{}
	}
	return
}
Exemplo n.º 3
0
func geometryFromVt(vt_type vt.Tile_GeomType, vtgeom []uint32) *Geometry {
	shapes, gtype, err := vtShapes(vtgeom)
	util.Check(err)
	if vt_type != gtype {
		util.Info("Assigned GeomType did not match sniffed %v -> %v", vt_type, gtype)
	}
	return newGeometry(vt_type, shapes...)
}
Exemplo n.º 4
0
func (s *Shape) IsClockwise() bool {
	sum := 0.0
	for i, c := range s.Coordinates[:len(s.Coordinates)-1] {
		n := s.Coordinates[i+1]
		sum += (n.Lon - c.Lon) * (n.Lat + c.Lat)
	}
	if sum == 0 {
		util.Info("Shape edge sum == 0, defaulting to clockwise == true")
	}
	return sum > 0
}
Exemplo n.º 5
0
func buildTile(layer string, tf tileFeatures) *mvt.TileAdapter {
	tile, features := tf.tileFeatures()
	util.Info("Building tile %v with %d features", tile, len(features))
	aTile := mvt.NewTileAdapter(tile.X, tile.Y, tile.Z)
	aLayer := aTile.NewLayer(layer, tiles.TileSize)
	for _, feature := range features {
		aFeature := MvtAdapter(feature, tile)
		if aFeature.Valid() {
			aLayer.AddFeature(aFeature)
		}
	}
	return aTile
}
Exemplo n.º 6
0
func (ex *Excavator) Start(workers int) (err error) {
	util.Info("Excavating %s with %d workers", ex.pbfpath, workers)
	err = ex.pbf.Start(workers)
	if err != nil {
		return
	}
	ex.dredgers.Add(workers)
	for i := 0; i < workers; i++ {
		util.Info("GO DREDGE %d", i)
		go ex.dredge()
	}
	go func() {
		ex.dredgers.Wait()
		ex.Close()
		util.Info("Done excavating, closing channels")
	}()
	ex.couriers.Add(workers)
	for i := 0; i < workers; i++ {
		util.Info("GO COURIER %d", i)
		go ex.courier()
	}
	ex.couriers.Wait()
	return
}
Exemplo n.º 7
0
Arquivo: cmd.go Projeto: buckhx/diglet
		// execute
		source, err := getSource(c)
		util.Check(err)
		if force {
			os.Remove(out)
		}
		tiles, err := InitTiles(out, upsert, desc, extent)
		util.Check(err)
		err = tiles.Build(source, layer, zmin, zmax)
		util.Check(err)
		// finalize
		file, _ := os.Open(out)
		defer file.Close()
		stat, _ := file.Stat()
		exp := float64(stat.Size()) / float64(1<<20)
		util.Info("%s was successfully caught!", out)
		util.Info("Diglet gained %f MB of EXP!", exp)
	},
	Flags: []cli.Flag{
		cli.StringFlag{
			Name:  "o, output",
			Usage: "REQUIRED: Path to write mbtiles to",
		},
		cli.StringFlag{
			Name:  "input-type",
			Value: "sniff",
			Usage: "Type of input files, 'sniff' will pick type based on the extension",
		},
		cli.BoolFlag{
			Name:  "f, force",
			Usage: "Remove the existing .mbtiles file before running.",
Exemplo n.º 8
0
func wayer(ways <-chan *osm.Way) {
	for way := range ways {
		util.Info("Way: %d %s", way.ID, way.Tags)
	}
}
Exemplo n.º 9
0
func noder(nodes <-chan *osm.Node) {
	for node := range nodes {
		util.Info("Node: %d %s", node.ID, node.Tags)
	}
}