-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.go
111 lines (105 loc) · 2.89 KB
/
app.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package mbt
import (
"github.com/buckhx/diglet/mbt/mvt"
"github.com/buckhx/diglet/mbt/tile_system"
"github.com/buckhx/diglet/util"
"github.com/buckhx/mbtiles"
"path/filepath"
)
type Tiles struct {
source FeatureSource
tileset *mbtiles.Tileset
args map[string]string
}
func InitTiles(srcpath, mbtpath string, upsert bool, filter []string, desc string, extent uint) (tiles Tiles, err error) {
tile_system.TileSize = extent
var ts *mbtiles.Tileset
if upsert {
ts, err = mbtiles.ReadTileset(mbtpath)
} else {
attrs := map[string]string{
"name": util.SlugBase(mbtpath),
"type": "overlay",
"version": "1",
"description": desc,
"format": "pbf.gz",
}
ts, err = mbtiles.InitTileset(mbtpath, attrs)
}
if err != nil {
return
}
src := getSource(srcpath, filter)
tiles = Tiles{
tileset: ts,
source: src,
}
return
}
func (t Tiles) Build(layerName string, zmin, zmax uint) (err error) {
for zoom := zmax; zoom >= zmin; zoom-- {
//TODO goroutine per level
util.Info("Generating tiles for zoom level: %d", zoom)
features, err := t.source.Publish()
if err != nil {
return err
}
tiles := splitFeatures(features, zoom)
for tile, features := range tiles {
aTile := mvt.NewTileAdapter(tile.X, tile.Y, tile.Z)
aLayer := aTile.NewLayer(layerName, tile_system.TileSize)
for _, feature := range features {
aFeature := feature.ToMvtAdapter(tile)
aLayer.AddFeature(aFeature)
}
gz, err := aTile.GetTileGz()
if err != nil {
return err
}
t.tileset.WriteOSMTile(tile.IntX(), tile.IntY(), tile.IntZ(), gz)
}
}
return
}
func getSource(mbtpath string, filter []string) FeatureSource {
src := filepath.Ext(mbtpath)[1:]
switch src {
case "csv":
//return NewCsvSource(mbtpath, delimiter, GeoFields{"lat": latField, "lon": lonField})
return NewCsvSource(mbtpath, filter, ",", GeoFields{"lat": "latitude", "lon": "longitude"})
case "geojson":
return NewGeojsonSource(mbtpath, filter)
default:
return nil
}
}
/*
func CsvTiles(path, delimiter, latField, lonField string) FeatureSource {
return NewCsvSource(path, delimiter, GeoFields{"lat": latField, "lon": lonField})
}
func GeojsonTiles(path string) FeatureSource {
return NewGeojsonSource(path)
}
*/
/*
func GeojsonTileset(ts *mbtiles.Tileset, gjpath string, zmin, zmax uint) {
collection := readGeoJson(gjpath)
for zoom := zmax; zoom >= zmin; zoom-- {
util.Info("Generating tiles for zoom level: %d", zoom)
tiles := splitFeatures(publishFeatureCollection(collection), zoom)
for tile, features := range tiles {
aTile := mvt.NewTileAdapter(tile.X, tile.Y, tile.Z)
aLayer := aTile.NewLayer("denver", tile_system.TileSize)
for _, feature := range features {
aFeature := feature.ToMvtAdapter(tile)
aLayer.AddFeature(aFeature)
}
gz, err := aTile.GetTileGz()
if err != nil {
panic(err)
}
ts.WriteOSMTile(tile.IntX(), tile.IntY(), tile.IntZ(), gz)
}
}
}
*/