Skip to content

Commit 141b759

Browse files
committed
When generating the seed list, we need the grid for the bounds
Added the ability to specify the srid to use. It defaults to 4326. Our old system normalized the bounds to grid, this meant that people could provide a bounds without the associated srid as long as it was either 4326 or 3853. With the change over, we were defaulting to 3853. This was the wrong default. Chanced the default 4326, and added ability to specify the srid. We will check to see if the SRID is supported by proj. For now the only srid's that are supported are 4326 and 3853.
1 parent eda30a2 commit 141b759

File tree

3 files changed

+53
-11
lines changed

3 files changed

+53
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Tegola is a vector tile server delivering [Mapbox Vector Tiles](https://github.c
2727

2828
```
2929
tegola is a vector tile server
30-
Version: v0.17.0
30+
Version: v0.21.0
3131
3232
Usage:
3333
tegola [command]

cmd/tegola/cmd/cache/seed_purge.go

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ package cache
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"runtime"
78
"strings"
89

910
"github.com/go-spatial/cobra"
1011
"github.com/go-spatial/geom"
1112
"github.com/go-spatial/geom/slippy"
13+
"github.com/go-spatial/proj"
1214
"github.com/go-spatial/tegola/atlas"
1315
"github.com/go-spatial/tegola/internal/build"
1416
gdcmd "github.com/go-spatial/tegola/internal/cmd"
@@ -41,15 +43,17 @@ Use "{{.CommandPath}} [command] --help" for more information about a command.{{e
4143

4244
// flag parameters
4345
var (
44-
// the amount of concurrency to use. defaults to the number of CPUs on the machine
46+
// cacheConcurrency is the amount of concurrency to use. defaults to the number of CPUs on the machine
4547
cacheConcurrency int
46-
// cache overwrite
48+
// cacheOverwrite determines if we should overwrite already existing files or skip them
4749
cacheOverwrite bool
48-
// bounds to cache within. default -180, -85.0511, 180, 85.0511
50+
// cacheBounds is the bounds that the cache is within. defaults to -180, -85.0511, 180, 85.0511
4951
cacheBounds string
50-
// name of the map
52+
// cacheBoundsSRID is the srid of grid system that the bounds is at. Should Default to 4326
53+
cacheBoundsSRID int
54+
// cacheMap is the name of the map
5155
cacheMap string
52-
// while seeding, on log output for tiles that take longer than this (in milliseconds) to render
56+
// cacheLogThreshold is cache threshold while seeding, to log output for tiles that take longer than this (in milliseconds) to render
5357
cacheLogThreshold int64
5458
)
5559

@@ -76,6 +80,7 @@ func init() {
7680
SeedPurgeCmd.PersistentFlags().Int64VarP(&cacheLogThreshold, "log-threshold", "", 0, "during seeding, only log tiles that take this number of milliseconds or longer to render (default all tiles)")
7781

7882
SeedPurgeCmd.Flags().StringVarP(&cacheBounds, "bounds", "", "-180,-85.0511,180,85.0511", "lng/lat bounds to seed the cache with in the format: minx, miny, maxx, maxy")
83+
SeedPurgeCmd.Flags().IntVarP(&cacheBoundsSRID, "bounds-srid", "", int(proj.EPSG4326), "the srid of the grid system for bounds.")
7984

8085
SeedPurgeCmd.PersistentPreRunE = seedPurgeCmdValidatePersistent
8186
SeedPurgeCmd.PreRunE = seedPurgeCmdValidate
@@ -143,6 +148,15 @@ func seedPurgeCmdValidatePersistent(cmd *cobra.Command, args []string) error {
143148
}
144149

145150
func seedPurgeCmdValidate(cmd *cobra.Command, args []string) (err error) {
151+
// validate the cache-bounds-srid
152+
if !proj.IsKnownConversionSRID(proj.EPSGCode(cacheBoundsSRID)) {
153+
var str strings.Builder
154+
str.WriteString(fmt.Sprintf("SRID=%d is not a know conversion ePSG code\n known codes are:", cacheBoundsSRID))
155+
for _, code := range proj.AvailableConversions() {
156+
str.WriteString(fmt.Sprintf(" %d\n", int(code)))
157+
}
158+
return errors.New(str.String())
159+
}
146160

147161
// validate and set bounds flag
148162
boundsParts := strings.Split(strings.TrimSpace(cacheBounds), ",")
@@ -191,27 +205,31 @@ func seedPurgeCommand(_ *cobra.Command, _ []string) (err error) {
191205
}
192206
}()
193207

208+
grid := slippy.NewGrid(proj.EPSGCode(cacheBoundsSRID), 0)
209+
194210
log.Info("zoom list: ", zooms)
195-
tileChannel := generateTilesForBounds(ctx, seedPurgeBounds, zooms)
211+
tileChannel := generateTilesForBounds(ctx, seedPurgeBounds, zooms, grid)
196212

197213
return doWork(ctx, tileChannel, seedPurgeMaps, cacheConcurrency, seedPurgeWorker)
198214
}
199215

200-
func generateTilesForBounds(ctx context.Context, bounds [4]float64, zooms []uint) *TileChannel {
216+
func generateTilesForBounds(ctx context.Context, bounds [4]float64, zooms []uint, grid slippy.TileGridder) *TileChannel {
201217

202218
tce := &TileChannel{
203219
channel: make(chan slippy.Tile),
204220
}
205221

206-
webmercatorGrid := slippy.NewGrid(3857, 0)
222+
if grid == nil {
223+
grid = slippy.NewGrid(proj.EPSGCode(cacheBoundsSRID), 0)
224+
}
207225

208226
go func() {
209227
defer tce.Close()
210228

211229
var extent geom.Extent = bounds
212230
for _, z := range zooms {
213231

214-
tiles, err := slippy.FromBounds(webmercatorGrid, &extent, slippy.Zoom(z))
232+
tiles, err := slippy.FromBounds(grid, &extent, slippy.Zoom(z))
215233
if err != nil {
216234
tce.setError(fmt.Errorf("got error trying to get tiles: %w", err))
217235
tce.Close()

cmd/tegola/cmd/cache/seed_purge_generator_test.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"testing"
99

1010
"github.com/go-spatial/geom/slippy"
11+
"github.com/go-spatial/proj"
1112
)
1213

1314
type sTiles []slippy.Tile
@@ -70,14 +71,15 @@ func TestGenerateTilesForBounds(t *testing.T) {
7071
zooms []uint
7172
bounds [4]float64
7273
tiles sTiles
74+
grid slippy.TileGridder
7375
err error
7476
}
7577

7678
fn := func(tc tcase) func(t *testing.T) {
7779
return func(t *testing.T) {
7880

7981
// Setup up the generator.
80-
tilechannel := generateTilesForBounds(context.Background(), tc.bounds, tc.zooms)
82+
tilechannel := generateTilesForBounds(context.Background(), tc.bounds, tc.zooms, tc.grid)
8183
tiles := make(sTiles, 0, len(tc.tiles))
8284
for tile := range tilechannel.Channel() {
8385
tiles = append(tiles, tile)
@@ -127,6 +129,28 @@ func TestGenerateTilesForBounds(t *testing.T) {
127129
slippy.Tile{Z: 1, X: 1, Y: 1},
128130
},
129131
},
132+
"min_zoom=1 max_zoom=1 bounds=5.9,45.8,10.5,47.8 WSG84": {
133+
// see: https://github.com/go-spatial/tegola/issues/880#issuecomment-2556563251
134+
zooms: []uint{10},
135+
bounds: [4]float64{5.9, 45.8, 10.5, 47.8},
136+
grid: slippy.NewGrid(proj.EPSG4326, 0),
137+
tiles: sTiles{
138+
slippy.Tile{Z: 10, X: 528, Y: 356}, slippy.Tile{Z: 10, X: 528, Y: 357}, slippy.Tile{Z: 10, X: 528, Y: 358}, slippy.Tile{Z: 10, X: 528, Y: 359}, slippy.Tile{Z: 10, X: 528, Y: 360}, slippy.Tile{Z: 10, X: 528, Y: 361}, slippy.Tile{Z: 10, X: 528, Y: 362}, slippy.Tile{Z: 10, X: 528, Y: 363}, slippy.Tile{Z: 10, X: 528, Y: 364}, slippy.Tile{Z: 10, X: 528, Y: 365},
139+
slippy.Tile{Z: 10, X: 529, Y: 356}, slippy.Tile{Z: 10, X: 529, Y: 357}, slippy.Tile{Z: 10, X: 529, Y: 358}, slippy.Tile{Z: 10, X: 529, Y: 359}, slippy.Tile{Z: 10, X: 529, Y: 360}, slippy.Tile{Z: 10, X: 529, Y: 361}, slippy.Tile{Z: 10, X: 529, Y: 362}, slippy.Tile{Z: 10, X: 529, Y: 363}, slippy.Tile{Z: 10, X: 529, Y: 364}, slippy.Tile{Z: 10, X: 529, Y: 365},
140+
slippy.Tile{Z: 10, X: 530, Y: 356}, slippy.Tile{Z: 10, X: 530, Y: 357}, slippy.Tile{Z: 10, X: 530, Y: 358}, slippy.Tile{Z: 10, X: 530, Y: 359}, slippy.Tile{Z: 10, X: 530, Y: 360}, slippy.Tile{Z: 10, X: 530, Y: 361}, slippy.Tile{Z: 10, X: 530, Y: 362}, slippy.Tile{Z: 10, X: 530, Y: 363}, slippy.Tile{Z: 10, X: 530, Y: 364}, slippy.Tile{Z: 10, X: 530, Y: 365},
141+
slippy.Tile{Z: 10, X: 531, Y: 356}, slippy.Tile{Z: 10, X: 531, Y: 357}, slippy.Tile{Z: 10, X: 531, Y: 358}, slippy.Tile{Z: 10, X: 531, Y: 359}, slippy.Tile{Z: 10, X: 531, Y: 360}, slippy.Tile{Z: 10, X: 531, Y: 361}, slippy.Tile{Z: 10, X: 531, Y: 362}, slippy.Tile{Z: 10, X: 531, Y: 363}, slippy.Tile{Z: 10, X: 531, Y: 364}, slippy.Tile{Z: 10, X: 531, Y: 365},
142+
slippy.Tile{Z: 10, X: 532, Y: 356}, slippy.Tile{Z: 10, X: 532, Y: 357}, slippy.Tile{Z: 10, X: 532, Y: 358}, slippy.Tile{Z: 10, X: 532, Y: 359}, slippy.Tile{Z: 10, X: 532, Y: 360}, slippy.Tile{Z: 10, X: 532, Y: 361}, slippy.Tile{Z: 10, X: 532, Y: 362}, slippy.Tile{Z: 10, X: 532, Y: 363}, slippy.Tile{Z: 10, X: 532, Y: 364}, slippy.Tile{Z: 10, X: 532, Y: 365},
143+
slippy.Tile{Z: 10, X: 533, Y: 356}, slippy.Tile{Z: 10, X: 533, Y: 357}, slippy.Tile{Z: 10, X: 533, Y: 358}, slippy.Tile{Z: 10, X: 533, Y: 359}, slippy.Tile{Z: 10, X: 533, Y: 360}, slippy.Tile{Z: 10, X: 533, Y: 361}, slippy.Tile{Z: 10, X: 533, Y: 362}, slippy.Tile{Z: 10, X: 533, Y: 363}, slippy.Tile{Z: 10, X: 533, Y: 364}, slippy.Tile{Z: 10, X: 533, Y: 365},
144+
slippy.Tile{Z: 10, X: 534, Y: 356}, slippy.Tile{Z: 10, X: 534, Y: 357}, slippy.Tile{Z: 10, X: 534, Y: 358}, slippy.Tile{Z: 10, X: 534, Y: 359}, slippy.Tile{Z: 10, X: 534, Y: 360}, slippy.Tile{Z: 10, X: 534, Y: 361}, slippy.Tile{Z: 10, X: 534, Y: 362}, slippy.Tile{Z: 10, X: 534, Y: 363}, slippy.Tile{Z: 10, X: 534, Y: 364}, slippy.Tile{Z: 10, X: 534, Y: 365},
145+
slippy.Tile{Z: 10, X: 535, Y: 356}, slippy.Tile{Z: 10, X: 535, Y: 357}, slippy.Tile{Z: 10, X: 535, Y: 358}, slippy.Tile{Z: 10, X: 535, Y: 359}, slippy.Tile{Z: 10, X: 535, Y: 360}, slippy.Tile{Z: 10, X: 535, Y: 361}, slippy.Tile{Z: 10, X: 535, Y: 362}, slippy.Tile{Z: 10, X: 535, Y: 363}, slippy.Tile{Z: 10, X: 535, Y: 364}, slippy.Tile{Z: 10, X: 535, Y: 365},
146+
slippy.Tile{Z: 10, X: 536, Y: 356}, slippy.Tile{Z: 10, X: 536, Y: 357}, slippy.Tile{Z: 10, X: 536, Y: 358}, slippy.Tile{Z: 10, X: 536, Y: 359}, slippy.Tile{Z: 10, X: 536, Y: 360}, slippy.Tile{Z: 10, X: 536, Y: 361}, slippy.Tile{Z: 10, X: 536, Y: 362}, slippy.Tile{Z: 10, X: 536, Y: 363}, slippy.Tile{Z: 10, X: 536, Y: 364}, slippy.Tile{Z: 10, X: 536, Y: 365},
147+
slippy.Tile{Z: 10, X: 537, Y: 356}, slippy.Tile{Z: 10, X: 537, Y: 357}, slippy.Tile{Z: 10, X: 537, Y: 358}, slippy.Tile{Z: 10, X: 537, Y: 359}, slippy.Tile{Z: 10, X: 537, Y: 360}, slippy.Tile{Z: 10, X: 537, Y: 361}, slippy.Tile{Z: 10, X: 537, Y: 362}, slippy.Tile{Z: 10, X: 537, Y: 363}, slippy.Tile{Z: 10, X: 537, Y: 364}, slippy.Tile{Z: 10, X: 537, Y: 365},
148+
slippy.Tile{Z: 10, X: 538, Y: 356}, slippy.Tile{Z: 10, X: 538, Y: 357}, slippy.Tile{Z: 10, X: 538, Y: 358}, slippy.Tile{Z: 10, X: 538, Y: 359}, slippy.Tile{Z: 10, X: 538, Y: 360}, slippy.Tile{Z: 10, X: 538, Y: 361}, slippy.Tile{Z: 10, X: 538, Y: 362}, slippy.Tile{Z: 10, X: 538, Y: 363}, slippy.Tile{Z: 10, X: 538, Y: 364}, slippy.Tile{Z: 10, X: 538, Y: 365},
149+
slippy.Tile{Z: 10, X: 539, Y: 356}, slippy.Tile{Z: 10, X: 539, Y: 357}, slippy.Tile{Z: 10, X: 539, Y: 358}, slippy.Tile{Z: 10, X: 539, Y: 359}, slippy.Tile{Z: 10, X: 539, Y: 360}, slippy.Tile{Z: 10, X: 539, Y: 361}, slippy.Tile{Z: 10, X: 539, Y: 362}, slippy.Tile{Z: 10, X: 539, Y: 363}, slippy.Tile{Z: 10, X: 539, Y: 364}, slippy.Tile{Z: 10, X: 539, Y: 365},
150+
slippy.Tile{Z: 10, X: 540, Y: 356}, slippy.Tile{Z: 10, X: 540, Y: 357}, slippy.Tile{Z: 10, X: 540, Y: 358}, slippy.Tile{Z: 10, X: 540, Y: 359}, slippy.Tile{Z: 10, X: 540, Y: 360}, slippy.Tile{Z: 10, X: 540, Y: 361}, slippy.Tile{Z: 10, X: 540, Y: 362}, slippy.Tile{Z: 10, X: 540, Y: 363}, slippy.Tile{Z: 10, X: 540, Y: 364}, slippy.Tile{Z: 10, X: 540, Y: 365},
151+
slippy.Tile{Z: 10, X: 541, Y: 356}, slippy.Tile{Z: 10, X: 541, Y: 357}, slippy.Tile{Z: 10, X: 541, Y: 358}, slippy.Tile{Z: 10, X: 541, Y: 359}, slippy.Tile{Z: 10, X: 541, Y: 360}, slippy.Tile{Z: 10, X: 541, Y: 361}, slippy.Tile{Z: 10, X: 541, Y: 362}, slippy.Tile{Z: 10, X: 541, Y: 363}, slippy.Tile{Z: 10, X: 541, Y: 364}, slippy.Tile{Z: 10, X: 541, Y: 365},
152+
},
153+
},
130154
}
131155

132156
for name, tc := range tests {

0 commit comments

Comments
 (0)