From bbe84d724b0d99e21511f62f39e2178580353635 Mon Sep 17 00:00:00 2001 From: gdey Date: Tue, 31 Dec 2024 13:56:59 -0800 Subject: [PATCH] added ability to state the srid of the bounds for cache --- README.md | 2 +- cmd/tegola/cmd/cache/seed_purge.go | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 1dc5cf962..12d9dfafb 100644 --- a/README.md +++ b/README.md @@ -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] diff --git a/cmd/tegola/cmd/cache/seed_purge.go b/cmd/tegola/cmd/cache/seed_purge.go index 1bb850b29..6c6ab244d 100644 --- a/cmd/tegola/cmd/cache/seed_purge.go +++ b/cmd/tegola/cmd/cache/seed_purge.go @@ -2,6 +2,7 @@ package cache import ( "context" + "errors" "fmt" "runtime" "strings" @@ -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 @@ -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 @@ -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), ",") @@ -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) @@ -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() {