Skip to content

Commit

Permalink
Update geom package to latest version (go-spatial#619)
Browse files Browse the repository at this point in the history
* update geom package
* created a provider.Tile implementation in the provider package and migrated slippy.NewTile calls to provider.NewTile
* remove extraneous tileBuffer parameter to seedWorker
* remove no longer needed stub for atlas.Tile
  • Loading branch information
ear7h authored and gdey committed Apr 21, 2020
1 parent 70d23e2 commit befba2e
Show file tree
Hide file tree
Showing 37 changed files with 957 additions and 329 deletions.
2 changes: 1 addition & 1 deletion atlas/atlas.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (a *Atlas) SeedMapTile(ctx context.Context, m Map, z, x, y uint) error {
return ErrMissingCache
}

tile := slippy.NewTile(z, x, y, float64(m.TileBuffer), m.SRID)
tile := slippy.NewTile(z, x, y)

// encode the tile
b, err := m.Encode(ctx, tile)
Expand Down
4 changes: 3 additions & 1 deletion atlas/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,10 @@ func (m Map) Encode(ctx context.Context, tile *slippy.Tile) ([]byte, error) {
// on completion let the wait group know
defer wg.Done()

ptile := provider.NewTile(tile.Z, tile.X, tile.Y,
uint(m.TileBuffer), uint(m.SRID))
// fetch layer from data provider
err := l.Provider.TileFeatures(ctx, l.ProviderLayerName, tile, func(f *provider.Feature) error {
err := l.Provider.TileFeatures(ctx, l.ProviderLayerName, ptile, func(f *provider.Feature) error {
// skip row if geometry collection empty.
g, ok := f.Geometry.(geom.Collection)
if ok && len(g.Geometries()) == 0 {
Expand Down
5 changes: 2 additions & 3 deletions atlas/map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/golang/protobuf/proto"

"github.com/go-spatial/geom/slippy"
"github.com/go-spatial/tegola"
"github.com/go-spatial/tegola/atlas"
"github.com/go-spatial/tegola/internal/p"
vectorTile "github.com/go-spatial/tegola/mvt/vector_tile"
Expand Down Expand Up @@ -294,7 +293,7 @@ func TestEncode(t *testing.T) {
},
},
},
tile: slippy.NewTile(2, 3, 4, 64, tegola.WebMercator),
tile: slippy.NewTile(2, 3, 4),
expected: vectorTile.Tile{
Layers: []*vectorTile.Tile_Layer{
{
Expand Down Expand Up @@ -352,7 +351,7 @@ func TestEncode(t *testing.T) {
},
},
},
tile: slippy.NewTile(2, 3, 4, 64, tegola.WebMercator),
tile: slippy.NewTile(2, 3, 4),
expected: vectorTile.Tile{
Layers: []*vectorTile.Tile_Layer{
{
Expand Down
7 changes: 0 additions & 7 deletions atlas/tile.go

This file was deleted.

2 changes: 1 addition & 1 deletion cmd/tegola/cmd/cache/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,6 @@ func (f Format) ParseTile(val string) (tile *slippy.Tile, err error) {
if err != nil {
return nil, err
}
tile = slippy.NewTile(z, x, y, 0, tegola.WebMercator)
tile = slippy.NewTile(z, x, y)
return tile, nil
}
14 changes: 4 additions & 10 deletions cmd/tegola/cmd/cache/seed_purge.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/go-spatial/cobra"
"github.com/go-spatial/geom/slippy"
"github.com/go-spatial/tegola"
"github.com/go-spatial/tegola/atlas"
"github.com/go-spatial/tegola/internal/log"
"github.com/go-spatial/tegola/maths"
Expand Down Expand Up @@ -128,12 +127,7 @@ func seedPurgeCmdValidatePersistent(cmd *cobra.Command, args []string) error {
case "purge":
seedPurgeWorker = purgeWorker
case "seed":
var pf64 *float64
if Config.TileBuffer != nil {
f64 := float64(*Config.TileBuffer)
pf64 = &f64
}
seedPurgeWorker = seedWorker(pf64, cacheOverwrite)
seedPurgeWorker = seedWorker(cacheOverwrite)
default:

return fmt.Errorf("expected purge/seed got (%v) for command name", cmdName)
Expand Down Expand Up @@ -206,8 +200,8 @@ func generateTilesForBounds(ctx context.Context, bounds [4]float64, zooms []uint
defer tce.Close()
for _, z := range zooms {
// get the tiles at the corners given the bounds and zoom
corner1 := slippy.NewTileLatLon(z, bounds[1], bounds[0], 0, tegola.WebMercator)
corner2 := slippy.NewTileLatLon(z, bounds[3], bounds[2], 0, tegola.WebMercator)
corner1 := slippy.NewTileLatLon(z, bounds[1], bounds[0])
corner2 := slippy.NewTileLatLon(z, bounds[3], bounds[2])

// x,y initials and finals
_, xi, yi := corner1.ZXY()
Expand All @@ -233,7 +227,7 @@ func generateTilesForBounds(ctx context.Context, bounds [4]float64, zooms []uint
// loop columns
for y := yi; y <= yf; y++ {
select {
case tce.channel <- slippy.NewTile(z, x, y, 0, tegola.WebMercator):
case tce.channel <- slippy.NewTile(z, x, y):
case <-ctx.Done():
// we have been cancelled
break MainLoop
Expand Down
13 changes: 6 additions & 7 deletions cmd/tegola/cmd/cache/seed_purge_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"testing"

"github.com/go-spatial/geom/slippy"
"github.com/go-spatial/tegola"
)

type sTiles []*slippy.Tile
Expand Down Expand Up @@ -119,16 +118,16 @@ func TestGenerateTilesForBounds(t *testing.T) {
"max_zoom=0": {
zooms: []uint{0},
bounds: worldBounds,
tiles: sTiles{slippy.NewTile(0, 0, 0, 0, tegola.WebMercator)},
tiles: sTiles{slippy.NewTile(0, 0, 0)},
},
"min_zoom=1 max_zoom=1": {
zooms: []uint{1},
bounds: worldBounds,
tiles: sTiles{
slippy.NewTile(1, 0, 0, 0, tegola.WebMercator),
slippy.NewTile(1, 0, 1, 0, tegola.WebMercator),
slippy.NewTile(1, 1, 0, 0, tegola.WebMercator),
slippy.NewTile(1, 1, 1, 0, tegola.WebMercator),
slippy.NewTile(1, 0, 0),
slippy.NewTile(1, 0, 1),
slippy.NewTile(1, 1, 0),
slippy.NewTile(1, 1, 1),
},
},
"min_zoom=1 max_zoom=1 bounds=180,90,0,0": {
Expand All @@ -140,7 +139,7 @@ func TestGenerateTilesForBounds(t *testing.T) {
* produced as 1/1/0 and not 1/1/1 but the code is identical, so not sure
* what the difference is.
*/
slippy.NewTile(1, 1, 1, 0, tegola.WebMercator),
slippy.NewTile(1, 1, 1),
},
},
}
Expand Down
15 changes: 7 additions & 8 deletions cmd/tegola/cmd/cache/tile_list_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"testing"

"github.com/go-spatial/geom/slippy"
"github.com/go-spatial/tegola"
)

func TestGenerateTilesForTileList(t *testing.T) {
Expand Down Expand Up @@ -82,20 +81,20 @@ func TestGenerateTilesForTileList(t *testing.T) {
format: defaultTileNameFormat,
zooms: []uint{13, 14, 15},
tiles: sTiles{
slippy.NewTile(13, 150, 390, 0, tegola.WebMercator),
slippy.NewTile(14, 300, 781, 0, tegola.WebMercator),
slippy.NewTile(15, 600, 1562, 0, tegola.WebMercator),
slippy.NewTile(15, 600, 1563, 0, tegola.WebMercator),
slippy.NewTile(15, 601, 1562, 0, tegola.WebMercator),
slippy.NewTile(15, 601, 1563, 0, tegola.WebMercator),
slippy.NewTile(13, 150, 390),
slippy.NewTile(14, 300, 781),
slippy.NewTile(15, 600, 1562),
slippy.NewTile(15, 600, 1563),
slippy.NewTile(15, 601, 1562),
slippy.NewTile(15, 601, 1563),
},
},
{
tileFilename: "testdata/list.tiles",
format: defaultTileNameFormat,
explicit: true,
tiles: sTiles{
slippy.NewTile(14, 300, 781, 0, tegola.WebMercator),
slippy.NewTile(14, 300, 781),
},
},
}
Expand Down
23 changes: 11 additions & 12 deletions cmd/tegola/cmd/cache/tile_name_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"testing"

"github.com/go-spatial/geom/slippy"
"github.com/go-spatial/tegola"
)

func TestGenerateTilesForTileName(t *testing.T) {
Expand Down Expand Up @@ -52,29 +51,29 @@ func TestGenerateTilesForTileName(t *testing.T) {

tests := map[string]tcase{
"max_zoom=0 tile-name=0/0/0": {
tile: slippy.NewTile(0, 0, 0, 0, tegola.WebMercator),
tile: slippy.NewTile(0, 0, 0),
explicit: true,
tiles: sTiles{
slippy.NewTile(0, 0, 0, 0, tegola.WebMercator),
slippy.NewTile(0, 0, 0),
},
},
"max_zoom=0 tile-name=14/300/781": {
tile: slippy.NewTile(14, 300, 781, 0, tegola.WebMercator),
tile: slippy.NewTile(14, 300, 781),
explicit: true,
tiles: sTiles{
slippy.NewTile(14, 300, 781, 0, tegola.WebMercator),
slippy.NewTile(14, 300, 781),
},
},
"min_zoom= 13 max_zoom=15 tile-name=14/300/781": {
tile: slippy.NewTile(14, 300, 781, 0, tegola.WebMercator),
tile: slippy.NewTile(14, 300, 781),
zooms: []uint{13, 14, 15},
tiles: sTiles{
slippy.NewTile(13, 150, 390, 0, tegola.WebMercator),
slippy.NewTile(14, 300, 781, 0, tegola.WebMercator),
slippy.NewTile(15, 600, 1562, 0, tegola.WebMercator),
slippy.NewTile(15, 600, 1563, 0, tegola.WebMercator),
slippy.NewTile(15, 601, 1562, 0, tegola.WebMercator),
slippy.NewTile(15, 601, 1563, 0, tegola.WebMercator),
slippy.NewTile(13, 150, 390),
slippy.NewTile(14, 300, 781),
slippy.NewTile(15, 600, 1562),
slippy.NewTile(15, 600, 1563),
slippy.NewTile(15, 601, 1562),
slippy.NewTile(15, 601, 1563),
},
},
}
Expand Down
7 changes: 1 addition & 6 deletions cmd/tegola/cmd/cache/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (s seedPurgeWorkerTileError) Error() string {
return fmt.Sprintf("error %v tile (%+v): %v", cmd, s.Tile, s.Err)
}

func seedWorker(tileBuffer *float64, overwrite bool) func(ctx context.Context, mt MapTile) error {
func seedWorker(overwrite bool) func(ctx context.Context, mt MapTile) error {
return func(ctx context.Context, mt MapTile) error {
// track how long the tile generation is taking
t := time.Now()
Expand Down Expand Up @@ -74,11 +74,6 @@ func seedWorker(tileBuffer *float64, overwrite bool) func(ctx context.Context, m
}
}

// set tile buffer if it was configured by the user
if tileBuffer != nil {
mt.Tile.Buffer = float64(*tileBuffer)
}

// seed the tile
if err = atlas.SeedMapTile(ctx, m, z, x, y); err != nil {
if err == context.Canceled {
Expand Down
3 changes: 1 addition & 2 deletions cmd/xyz2svg/cmd/draw.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/go-spatial/cobra"
"github.com/go-spatial/geom"
"github.com/go-spatial/geom/slippy"
"github.com/go-spatial/tegola"
"github.com/go-spatial/tegola/cmd/internal/register"
"github.com/go-spatial/tegola/config"
Expand Down Expand Up @@ -147,7 +146,7 @@ func drawCommand(cmd *cobra.Command, args []string) {
func drawFeatures(pname string, tiler provider.Tiler, layers []string, gid int, dfn *drawFilename) error {
ctx := context.Background()
ttile := tegola.NewTile(dfn.z, dfn.x, dfn.y)
slippyTile := slippy.NewTile(dfn.z, dfn.x, dfn.y, tegola.DefaultTileBuffer, tegola.WebMercator)
slippyTile := provider.NewTile(dfn.z, dfn.x, dfn.y, tegola.DefaultTileBuffer, tegola.WebMercator)
for _, name := range layers {
count := 0
err := tiler.TileFeatures(ctx, name, slippyTile, func(f *provider.Feature) error {
Expand Down
4 changes: 1 addition & 3 deletions provider/postgis/postgis.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ import (

"github.com/go-spatial/geom"
"github.com/go-spatial/geom/encoding/wkb"
"github.com/go-spatial/geom/slippy"
"github.com/go-spatial/tegola"
"github.com/go-spatial/tegola/provider"

"github.com/go-spatial/tegola/dict"
)

Expand Down Expand Up @@ -434,7 +432,7 @@ func (p Provider) inspectLayerGeomType(l *Layer) error {
sql = strings.Replace(sql, "!ZOOM!", "ANY('{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24}')", 1)

// we need a tile to run our sql through the replacer
tile := slippy.NewTile(0, 0, 0, 64, tegola.WebMercator)
tile := provider.NewTile(0, 0, 0, 64, tegola.WebMercator)

// normal replacer
sql, err = replaceTokens(sql, l.srid, tile)
Expand Down
Loading

0 comments on commit befba2e

Please sign in to comment.