diff --git a/main.go b/main.go index c003812..c2fa848 100644 --- a/main.go +++ b/main.go @@ -32,8 +32,9 @@ var cli struct { } `cmd:"" help:"Convert an MBTiles or older spec version to PMTiles."` Show struct { - Path string `arg:""` - Bucket string `help:"Remote bucket"` + Path string `arg:""` + Bucket string `help:"Remote bucket"` + Metadata bool `help:"Print only the JSON metadata."` } `cmd:"" help:"Inspect a local or remote archive."` Tile struct { @@ -91,12 +92,12 @@ func main() { switch ctx.Command() { case "show ": - err := pmtiles.Show(logger, cli.Show.Bucket, cli.Show.Path, false, 0, 0, 0) + err := pmtiles.Show(logger, cli.Show.Bucket, cli.Show.Path, cli.Show.Metadata, false, 0, 0, 0) if err != nil { logger.Fatalf("Failed to show archive, %v", err) } case "tile ": - err := pmtiles.Show(logger, cli.Tile.Bucket, cli.Tile.Path, true, cli.Tile.Z, cli.Tile.X, cli.Tile.Y) + err := pmtiles.Show(logger, cli.Tile.Bucket, cli.Tile.Path, false, true, cli.Tile.Z, cli.Tile.X, cli.Tile.Y) if err != nil { logger.Fatalf("Failed to show tile, %v", err) } diff --git a/pmtiles/show.go b/pmtiles/show.go index 4a2fbc2..2617ca8 100644 --- a/pmtiles/show.go +++ b/pmtiles/show.go @@ -12,7 +12,7 @@ import ( "os" ) -func Show(logger *log.Logger, bucketURL string, key string, show_tile bool, z int, x int, y int) error { +func Show(logger *log.Logger, bucketURL string, key string, show_metadata_only bool, show_tile bool, z int, x int, y int) error { ctx := context.Background() bucketURL, key, err := NormalizeBucketKey(bucketURL, "", key) @@ -66,20 +66,6 @@ func Show(logger *log.Logger, bucketURL string, key string, show_tile bool, z in default: tile_type = "Unknown" } - fmt.Printf("pmtiles spec version: %d\n", header.SpecVersion) - // fmt.Printf("total size: %s\n", humanize.Bytes(uint64(r.Size()))) - fmt.Printf("tile type: %s\n", tile_type) - fmt.Printf("bounds: %f,%f %f,%f\n", float64(header.MinLonE7)/10000000, float64(header.MinLatE7)/10000000, float64(header.MaxLonE7)/10000000, float64(header.MaxLatE7)/10000000) - fmt.Printf("min zoom: %d\n", header.MinZoom) - fmt.Printf("max zoom: %d\n", header.MaxZoom) - fmt.Printf("center: %f,%f\n", float64(header.CenterLonE7)/10000000, float64(header.CenterLatE7)/10000000) - fmt.Printf("center zoom: %d\n", header.CenterZoom) - fmt.Printf("addressed tiles count: %d\n", header.AddressedTilesCount) - fmt.Printf("tile entries count: %d\n", header.TileEntriesCount) - fmt.Printf("tile contents count: %d\n", header.TileContentsCount) - fmt.Printf("clustered: %t\n", header.Clustered) - fmt.Printf("internal compression: %d\n", header.InternalCompression) - fmt.Printf("tile compression: %d\n", header.TileCompression) metadata_reader, err := bucket.NewRangeReader(ctx, key, int64(header.MetadataOffset), int64(header.MetadataLength)) if err != nil { @@ -101,17 +87,35 @@ func Show(logger *log.Logger, bucketURL string, key string, show_tile bool, z in } metadata_reader.Close() - var metadata_map map[string]interface{} - json.Unmarshal(metadata_bytes, &metadata_map) - for k, v := range metadata_map { - switch v := v.(type) { - case string: - fmt.Println(k, v) - default: - fmt.Println(k, "") + if show_metadata_only { + fmt.Print(string(metadata_bytes)) + } else { + fmt.Printf("pmtiles spec version: %d\n", header.SpecVersion) + // fmt.Printf("total size: %s\n", humanize.Bytes(uint64(r.Size()))) + fmt.Printf("tile type: %s\n", tile_type) + fmt.Printf("bounds: %f,%f %f,%f\n", float64(header.MinLonE7)/10000000, float64(header.MinLatE7)/10000000, float64(header.MaxLonE7)/10000000, float64(header.MaxLatE7)/10000000) + fmt.Printf("min zoom: %d\n", header.MinZoom) + fmt.Printf("max zoom: %d\n", header.MaxZoom) + fmt.Printf("center: %f,%f\n", float64(header.CenterLonE7)/10000000, float64(header.CenterLatE7)/10000000) + fmt.Printf("center zoom: %d\n", header.CenterZoom) + fmt.Printf("addressed tiles count: %d\n", header.AddressedTilesCount) + fmt.Printf("tile entries count: %d\n", header.TileEntriesCount) + fmt.Printf("tile contents count: %d\n", header.TileContentsCount) + fmt.Printf("clustered: %t\n", header.Clustered) + fmt.Printf("internal compression: %d\n", header.InternalCompression) + fmt.Printf("tile compression: %d\n", header.TileCompression) + + var metadata_map map[string]interface{} + json.Unmarshal(metadata_bytes, &metadata_map) + for k, v := range metadata_map { + switch v := v.(type) { + case string: + fmt.Println(k, v) + default: + fmt.Println(k, "") + } } } - } else { // write the tile to stdout