Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade go-spatial/geom to latest #952

Merged
merged 2 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion atlas/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ func (m Map) encodeMVTTile(ctx context.Context, tile *slippy.Tile, params provid
// with the adoption of the new make valid routine. once implemented, the clipRegion
// calculation will need to be in the same coordinate space as the geometry the
// make valid function will be operating on.
geo = mvt.PrepareGeo(geo, tile.Extent3857(), float64(mvt.DefaultExtent))
ext, _ := ptile.Extent()
geo = mvt.PrepareGeo(geo, ext, float64(mvt.DefaultExtent))

// TODO: remove this geom conversion step once the validate function uses geom types
sg, err = convert.ToTegola(geo)
Expand Down
4 changes: 2 additions & 2 deletions atlas/map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ func TestEncode(t *testing.T) {
},
},
},
tile: slippy.NewTile(2, 3, 4),
tile: slippy.NewTile(2, 3, 3),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 is not a valid y-value at zoom 2, and the geom upgrade makes this test fail unless a valid coordinate is used.

expected: vectorTile.Tile{
Layers: []*vectorTile.Tile_Layer{
{
Expand Down Expand Up @@ -403,7 +403,7 @@ func TestEncode(t *testing.T) {
},
},
},
tile: slippy.NewTile(2, 3, 4),
tile: slippy.NewTile(2, 3, 3),
expected: vectorTile.Tile{
Layers: []*vectorTile.Tile_Layer{
{
Expand Down
52 changes: 18 additions & 34 deletions cmd/tegola/cmd/cache/seed_purge.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
"strings"

"github.com/go-spatial/cobra"
"github.com/go-spatial/geom"
"github.com/go-spatial/geom/slippy"
"github.com/go-spatial/tegola/atlas"
"github.com/go-spatial/tegola/internal/build"
gdcmd "github.com/go-spatial/tegola/internal/cmd"
"github.com/go-spatial/tegola/internal/log"
"github.com/go-spatial/tegola/maths"
"github.com/go-spatial/tegola/observability"
"github.com/go-spatial/tegola/provider"
)
Expand Down Expand Up @@ -203,46 +203,30 @@ func generateTilesForBounds(ctx context.Context, bounds [4]float64, zooms []uint
channel: make(chan *slippy.Tile),
}

webmercatorGrid, err := slippy.NewGrid(3857)
if err != nil {
tce.setError(fmt.Errorf("Could not create Web Mercator grid (3857): %s", err))
tce.Close()
return tce
}

go func() {
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])
corner2 := slippy.NewTileLatLon(z, bounds[3], bounds[2])

// x,y initials and finals
_, xi, yi := corner1.ZXY()
_, xf, yf := corner2.ZXY()

maxXYatZ := uint(maths.Exp2(uint64(z))) - 1

// ensure the initials are smaller than finals
// this breaks at the anti meridian: https://github.com/go-spatial/tegola/issues/500
if xi > xf {
xi, xf = xf, xi
}
if yi > yf {
yi, yf = yf, yi
}
var extent geom.Extent = bounds
for _, z := range zooms {

// prevent seeding out of bounds
xf = maths.Min(xf, maxXYatZ)
yf = maths.Min(yf, maxXYatZ)

MainLoop:
for x := xi; x <= xf; x++ {
// loop columns
for y := yi; y <= yf; y++ {
select {
case tce.channel <- slippy.NewTile(z, x, y):
case <-ctx.Done():
// we have been cancelled
break MainLoop
}
tiles := slippy.FromBounds(webmercatorGrid, &extent, z)
for _, tile := range tiles {
t := tile
select {
case tce.channel <- &t:
case <-ctx.Done():
// we have been cancelled
return
}
}
}
tce.Close()
}()
return tce
}
6 changes: 1 addition & 5 deletions cmd/tegola/cmd/cache/seed_purge_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,7 @@ func TestGenerateTilesForBounds(t *testing.T) {
zooms: []uint{1},
bounds: [4]float64{180.0, 90.0, 0.0, 0.0},
tiles: sTiles{
/*
* Note that the test case for this from the original had the tile being
* 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, 0),
slippy.NewTile(1, 1, 1),
},
},
Expand Down
43 changes: 43 additions & 0 deletions cmd/tegola/cmd/cache/slippy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package cache

import (
"math"

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

// rangeFamilyAt runs the given callback on every related tile at the given zoom. This could include
// the provided tile itself (if the same zoom is provided), the parent (overlapping tile at a lower zoom
// level), or children (overlapping tiles at a higher zoom level).
//
// Copied from go-spatial/geom (dc1d50720ee77122d0) since the function by this name doesn't do
// the same thing anymore. (In geom, it no longer returns ancestors or self, only descendants.
// It's also buggy because grid.ToNative/FromNative are buggy.)
//
// This function should be removed once the one in geom is updated to work as expected.
func rangeFamilyAt(t *slippy.Tile, zoom uint, f func(*slippy.Tile) error) error {
// handle ancestors and self
if zoom <= t.Z {
mag := t.Z - zoom
arg := slippy.NewTile(zoom, t.X>>mag, t.Y>>mag)
return f(arg)
}

// handle descendants
mag := zoom - t.Z
delta := uint(math.Exp2(float64(mag)))

leastX := t.X << mag
leastY := t.Y << mag

for x := leastX; x < leastX+delta; x++ {
for y := leastY; y < leastY+delta; y++ {
err := f(slippy.NewTile(zoom, x, y))
if err != nil {
return err
}
gdey marked this conversation as resolved.
Show resolved Hide resolved
}
}

return nil
}
112 changes: 112 additions & 0 deletions cmd/tegola/cmd/cache/slippy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package cache

import (
"testing"

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

func TestRangeFamilyAt(t *testing.T) {
type coord struct {
z, x, y uint
}

type tcase struct {
tile *slippy.Tile
zoomAt uint
expected []coord
}

isIn := func(arr []coord, c coord) bool {
for _, v := range arr {
if v == c {
return true
}
}

return false
}

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

coordList := make([]coord, 0, len(tc.expected))
rangeFamilyAt(tc.tile, tc.zoomAt, func(tile *slippy.Tile) error {
z, x, y := tile.ZXY()
c := coord{z, x, y}

coordList = append(coordList, c)
gdey marked this conversation as resolved.
Show resolved Hide resolved

return nil
})

if len(coordList) != len(tc.expected) {
t.Fatalf("coordinate list length, expected %d, got %d: %v \n\n %v", len(tc.expected), len(coordList), tc.expected, coordList)
}

for _, v := range tc.expected {
if !isIn(coordList, v) {
t.Logf("coordinates: %v", coordList)
t.Fatalf("coordinate exists, expected %v, got missing", v)
}
}

}
}

testcases := map[string]tcase{
"children 1": {
tile: slippy.NewTile(0, 0, 0),
zoomAt: 1,
expected: []coord{
{1, 0, 0},
{1, 0, 1},
{1, 1, 0},
{1, 1, 1},
},
},
"children 2": {
tile: slippy.NewTile(8, 3, 5),
zoomAt: 10,
expected: []coord{
{10, 12, 20},
{10, 12, 21},
{10, 12, 22},
{10, 12, 23},
//
{10, 13, 20},
{10, 13, 21},
{10, 13, 22},
{10, 13, 23},
//
{10, 14, 20},
{10, 14, 21},
{10, 14, 22},
{10, 14, 23},
//
{10, 15, 20},
{10, 15, 21},
{10, 15, 22},
{10, 15, 23},
},
},
"parent 1": {
tile: slippy.NewTile(1, 0, 0),
zoomAt: 0,
expected: []coord{
{0, 0, 0},
},
},
"parent 2": {
tile: slippy.NewTile(3, 3, 5),
zoomAt: 1,
expected: []coord{
{1, 0, 1},
},
},
}

for name, tc := range testcases {
t.Run(name, fn(tc))
}
}
3 changes: 2 additions & 1 deletion cmd/tegola/cmd/cache/tile_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func generateTilesForTileList(ctx context.Context, tilelist io.Reader, explicit
tce := &TileChannel{
channel: make(chan *slippy.Tile),
}

go func() {
defer tce.Close()

Expand Down Expand Up @@ -134,7 +135,7 @@ func generateTilesForTileList(ctx context.Context, tilelist io.Reader, explicit

for _, zoom := range zooms {
// range will include the original tile.
err = tile.RangeFamilyAt(zoom, func(tile *slippy.Tile) error {
err = rangeFamilyAt(tile, zoom, func(tile *slippy.Tile) error {
select {
case tce.channel <- tile:
case <-ctx.Done():
Expand Down
3 changes: 2 additions & 1 deletion cmd/tegola/cmd/cache/tile_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func generateTilesForTileName(ctx context.Context, tile *slippy.Tile, explicit b
tce := &TileChannel{
channel: make(chan *slippy.Tile),
}

go func() {
defer tce.Close()
if tile == nil {
Expand All @@ -98,7 +99,7 @@ func generateTilesForTileName(ctx context.Context, tile *slippy.Tile, explicit b
}
for _, zoom := range zooms {
// range will include the original tile.
err := tile.RangeFamilyAt(zoom, func(tile *slippy.Tile) error {
err := rangeFamilyAt(tile, zoom, func(tile *slippy.Tile) error {
select {
case tce.channel <- tile:
case <-ctx.Done():
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ require (
github.com/gdey/tbltest v0.0.0-20170331191646-af8abc47b052
github.com/go-redis/redis v6.9.0+incompatible
github.com/go-spatial/cobra v0.0.3-0.20181105183926-68194e4fbcc6
github.com/go-spatial/geom v0.0.0-20190821234737-802ab2533ab4
github.com/go-spatial/geom v0.0.0-20220918193402-3cd2f5a9a082
github.com/go-spatial/proj v0.2.0
github.com/go-test/deep v0.0.0-20170429201529-f49763a6ea0a
github.com/golang/protobuf v1.5.2
github.com/jackc/pgproto3/v2 v2.2.0
Expand Down
10 changes: 8 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/gdey/errors v0.0.0-20190426172550-8ebd5bc891fb/go.mod h1:PFaV7MgSRe92Wo9O2H2i1CIm7urUk10AgdSHKyBfjmQ=
github.com/gdey/tbltest v0.0.0-20170331191646-af8abc47b052 h1:uDErRK65HpAslYsynvi7QVzqNYJELGmG2ijcBT/GKJo=
github.com/gdey/tbltest v0.0.0-20170331191646-af8abc47b052/go.mod h1:O0rUOxGq87ndwSAK+YVv/8g40Wbre/OSPCU8GlgUyPk=
github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
Expand All @@ -63,8 +64,10 @@ github.com/go-redis/redis v6.9.0+incompatible h1:TYmqCy++WwnKkrf+NJA2QuKdgkpeIr3
github.com/go-redis/redis v6.9.0+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
github.com/go-spatial/cobra v0.0.3-0.20181105183926-68194e4fbcc6 h1:JZlproLIh4Xx/5QEd6pJq8g0vdwaaxufffEC6egRpVY=
github.com/go-spatial/cobra v0.0.3-0.20181105183926-68194e4fbcc6/go.mod h1:f1ZQ97aEXWRWGYAZPB9oKTvG/PejtuPD3W/TUXkMlc8=
github.com/go-spatial/geom v0.0.0-20190821234737-802ab2533ab4 h1:86C+kh/YYFdiZ+LY/zbNPcyJS9kEbbOngCDPCa3nHlA=
github.com/go-spatial/geom v0.0.0-20190821234737-802ab2533ab4/go.mod h1:ysDXHAm45k1iWrWWOFdbjksiQFWmWLeFgbeuv6n7XiY=
github.com/go-spatial/geom v0.0.0-20220918193402-3cd2f5a9a082 h1:3+Swhq7I1stScm1DE4PUWKjGJRbi+VPvisj6tFz0prs=
github.com/go-spatial/geom v0.0.0-20220918193402-3cd2f5a9a082/go.mod h1:YU06tBGGstQCUX7vMuyF44RRneTdjGxOrp8OJHu4t9Q=
github.com/go-spatial/proj v0.2.0 h1:sii5Now3GFEyR9hV2SBJFWFz95s4xSaZmP0aYDk1K6c=
github.com/go-spatial/proj v0.2.0/go.mod h1:ePHHp7ITVc4eIVW5sgG/0Eu9RMAGOQUgM/D1ZkccY+0=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
github.com/go-test/deep v0.0.0-20170429201529-f49763a6ea0a h1:TbXiwp5vd0XKd2ltBykuGFU+P/HltF3q/ix+Cbh053k=
Expand Down Expand Up @@ -181,8 +184,10 @@ github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-sqlite3 v1.12.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/mattn/go-sqlite3 v1.14.6 h1:dNPt6NO46WmLVt2DLNpwczCmdV5boIZ6g/tlDrlRUbg=
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/mattn/goveralls v0.0.3-0.20180319021929-1c14a4061c1c/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpevwGNQEw=
github.com/mattn/goveralls v0.0.5 h1:spfq8AyZ0cCk57Za6/juJ5btQxeE1FaEGMdfcI+XO48=
github.com/mattn/goveralls v0.0.5/go.mod h1:Xg2LHi51faXLyKXwsndxiW6uxEEQT9+3sjGzzwU4xy0=
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
Expand Down Expand Up @@ -351,6 +356,7 @@ golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgw
golang.org/x/tools v0.0.0-20190823170909-c4a336ef6a2f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191114222411-4191b8cbba09/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200113040837-eac381796e91/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
Expand Down
4 changes: 2 additions & 2 deletions provider/hana/hana.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ func (c connectionPoolCollector) QueryContextWithBBox(ctx context.Context, query
return nil, err
}

strLL, _ := wkt.Encode(ll)
strLL, _ := wkt.EncodeString(ll)
lobLL := new(driver.Lob)
lobLL.SetReader(strings.NewReader(strLL))

strUR, _ := wkt.Encode(ur)
strUR, _ := wkt.EncodeString(ur)
lobUR := new(driver.Lob)
lobUR.SetReader(strings.NewReader(strUR))

Expand Down
Loading
Loading