Skip to content

Commit

Permalink
added ability to state the srid of the bounds for cache
Browse files Browse the repository at this point in the history
  • Loading branch information
gdey committed Dec 31, 2024
1 parent 3c176df commit bbe84d7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Tegola is a vector tile server delivering [Mapbox Vector Tiles](https://github.c

```
tegola is a vector tile server
Version: v0.17.0
Version: v0.21.0
Usage:
tegola [command]
Expand Down
24 changes: 15 additions & 9 deletions cmd/tegola/cmd/cache/seed_purge.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cache

import (
"context"
"errors"
"fmt"
"runtime"
"strings"
Expand Down Expand Up @@ -48,8 +49,8 @@ var (
cacheOverwrite bool
// cacheBounds is the bounds that the cache is within. defaults to -180, -85.0511, 180, 85.0511
cacheBounds string
// cacheBoundsWGS84 is the grid system that the bounds is at. If set then we should use WGS84, otherwise assume it's in Pseudo-Mercator
cacheBoundsWGS84 bool
// cacheBoundsSRID is the srid of grid system that the bounds is at. Should Default to 4326
cacheBoundsSRID int
// cacheMap is the name of the map
cacheMap string
// cacheLogThreshold is cache threshold while seeding, to log output for tiles that take longer than this (in milliseconds) to render
Expand Down Expand Up @@ -79,7 +80,7 @@ func init() {
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)")

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")
SeedPurgeCmd.PersistentFlags().BoolVarP(&cacheBoundsWGS84, "wgs84", "", false, "the grid system for bounds. This flag indicates that the grid is WGS 84; otherwise it's assumed to be in Pseudo-Mercator")
SeedPurgeCmd.Flags().IntVarP(&cacheBoundsSRID, "bounds-srid", "", int(proj.EPSG4326), "the srid of the grid system for bounds.")

SeedPurgeCmd.PersistentPreRunE = seedPurgeCmdValidatePersistent
SeedPurgeCmd.PreRunE = seedPurgeCmdValidate
Expand Down Expand Up @@ -147,6 +148,15 @@ func seedPurgeCmdValidatePersistent(cmd *cobra.Command, args []string) error {
}

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

// validate and set bounds flag
boundsParts := strings.Split(strings.TrimSpace(cacheBounds), ",")
Expand Down Expand Up @@ -195,11 +205,7 @@ func seedPurgeCommand(_ *cobra.Command, _ []string) (err error) {
}
}()

srid := proj.EPSGCode(proj.EPSG3857)
if cacheBoundsWGS84 {
srid = proj.EPSG4326
}
grid := slippy.NewGrid(srid, 0)
grid := slippy.NewGrid(proj.EPSGCode(cacheBoundsSRID), 0)

log.Info("zoom list: ", zooms)
tileChannel := generateTilesForBounds(ctx, seedPurgeBounds, zooms, grid)
Expand All @@ -214,7 +220,7 @@ func generateTilesForBounds(ctx context.Context, bounds [4]float64, zooms []uint
}

if grid == nil {
grid = slippy.NewGrid(proj.EPSG3857, 0)
grid = slippy.NewGrid(proj.EPSGCode(cacheBoundsSRID), 0)
}

go func() {
Expand Down

0 comments on commit bbe84d7

Please sign in to comment.