-
Notifications
You must be signed in to change notification settings - Fork 1
/
worker.go
70 lines (57 loc) · 1.55 KB
/
worker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"fmt"
"io/ioutil"
"log"
"sync"
"github.com/ryankurte/go-mapbox/lib"
"github.com/ryankurte/go-mapbox/lib/base"
"github.com/ryankurte/go-mapbox/lib/maps"
)
func terrainWorker(mapBox *mapbox.Mapbox, queue chan xyz, directory string, workwg *sync.WaitGroup) {
for xyz := range queue {
// fetch tile
highDPI := false
log.Println("Fetch tile", xyz)
tile, err := mapBox.Maps.GetTile(maps.MapIDTerrainRGB, xyz.x, xyz.y, xyz.z, maps.MapFormatPngRaw, highDPI)
if nil != err {
// panic(err)
log.Println(err)
workwg.Done()
continue
}
// log.Println("Parsing tile", xyz)
// fileHandler, err := os.Create(fmt.Sprintf("tmp/%v_%v_%v.csv", xyz.x, xyz.y, xyz.z))
// if nil != err {
// panic(err)
// }
// defer fileHandler.Close()
// create temp file
basename := fmt.Sprintf("%v_%v_%v_*.csv", xyz.x, xyz.y, xyz.z)
fileHandler, err := ioutil.TempFile(directory, basename)
if nil != err {
panic(err)
}
defer fileHandler.Close()
//.end
fmt.Fprintf(fileHandler, "x,y,z\n")
for x := 0; x < tile.Bounds().Max.X; x++ {
for y := 0; y < tile.Bounds().Max.Y; y++ {
loc, err := tile.PixelToLocation(float64(x), float64(y))
if nil != err {
log.Println(err)
continue
}
ll := base.Location{Latitude: loc.Latitude, Longitude: loc.Longitude}
elevation, err := tile.GetAltitude(ll)
if nil != err {
log.Println(err)
continue
}
line := fmt.Sprintf("%v,%v,%v\n", loc.Longitude, loc.Latitude, elevation)
fmt.Fprintf(fileHandler, line)
}
}
workwg.Done()
}
}