Skip to content

Commit

Permalink
Calculate tile id ranges from x, y ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
wipfli committed Dec 4, 2022
1 parent d02a36c commit 16bea22
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"runtime/pprof"
"strconv"
"time"
"sort"
)

func main() {
Expand All @@ -40,6 +41,39 @@ pmtiles serve "s3://BUCKET_NAME"`
}

switch os.Args[1] {
case "extract":
var z uint8 = 14
var x_min uint32 = 0
var x_max uint32 = 10000 // included
var y_min uint32 = 0
var y_max uint32 = 10000 // included

var tile_ids []uint64

for x := x_min; x <= x_max; x++ {
for y := y_min; y <= y_max; y++ {
// fmt.Println(z, x, y, pmtiles.ZxyToId(z, x, y))
tile_ids = append(tile_ids, pmtiles.ZxyToId(z, x, y))
}
}

sort.Slice(tile_ids, func(i, j int) bool { return tile_ids[i] < tile_ids[j]})

var tile_id_ranges [][2]uint64

tile_id_ranges = append(tile_id_ranges, [2]uint64{tile_ids[0], tile_ids[0]})

for i := 1; i < len(tile_ids); i++ {
if tile_id_ranges[len(tile_id_ranges)-1][1] + 1 == tile_ids[i] {
tile_id_ranges[len(tile_id_ranges)-1][1] = tile_ids[i]
} else {
tile_id_ranges = append(tile_id_ranges, [2]uint64{tile_ids[i], tile_ids[i]})
}
}

fmt.Println(len(tile_ids))
fmt.Println(len(tile_id_ranges))

case "show":
err := pmtiles.Show(logger, os.Args[2:])

Expand Down

0 comments on commit 16bea22

Please sign in to comment.