-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from sfomuseum/metadata
Add methods and tools to ensure spatial metadata properties for MBTiles databases
- Loading branch information
Showing
505 changed files
with
81,072 additions
and
32,672 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"log" | ||
|
||
"github.com/paulmach/orb" | ||
"github.com/paulmach/orb/maptile" | ||
"github.com/tilezen/go-tilepacks/tilepack" | ||
) | ||
|
||
func main() { | ||
|
||
var verify bool | ||
|
||
flag.BoolVar(&verify, "verify", false, "Verify that spatial metadata was written to each database") | ||
|
||
flag.Parse() | ||
|
||
for _, path := range flag.Args() { | ||
|
||
mbtilesReader, err := tilepack.NewMbtilesReader(path) | ||
|
||
if err != nil { | ||
log.Fatalf("Couldn't read input mbtiles %s: %+v", path, err) | ||
} | ||
|
||
var bounds *orb.Bound | ||
minZoom := uint(20) | ||
maxZoom := uint(0) | ||
|
||
err = mbtilesReader.VisitAllTiles(func(t maptile.Tile, data []byte) { | ||
|
||
tb := t.Bound() | ||
|
||
if bounds == nil { | ||
bounds = &tb | ||
} else { | ||
tb = bounds.Union(tb) | ||
bounds = &tb | ||
} | ||
|
||
minZoom = min(minZoom, uint(t.Z)) | ||
maxZoom = max(maxZoom, uint(t.Z)) | ||
}) | ||
|
||
if err != nil { | ||
log.Fatalf("Couldn't read tiles from %s: %+v", path, err) | ||
} | ||
|
||
mbtilesReader.Close() | ||
|
||
mbtilesWriter, err := tilepack.NewMbtilesOutputter(path, 0) | ||
|
||
if err != nil { | ||
log.Fatalf("Couldn't read input mbtiles %s: %+v", path, err) | ||
} | ||
|
||
err = mbtilesWriter.AssignSpatialMetadata(*bounds, maptile.Zoom(minZoom), maptile.Zoom(maxZoom)) | ||
|
||
if err != nil { | ||
log.Fatalf("Failed to assign spatial metadata to %s: %+v", path, err) | ||
} | ||
|
||
mbtilesWriter.Close() | ||
|
||
if verify { | ||
|
||
mbtilesReader, err := tilepack.NewMbtilesReader(path) | ||
|
||
if err != nil { | ||
log.Fatalf("Couldn't read input mbtiles %s: %+v", path, err) | ||
} | ||
|
||
metadata, err := mbtilesReader.Metadata() | ||
|
||
if err != nil { | ||
log.Fatalf("Unable to read metadata for %s, %v", path, err) | ||
} | ||
|
||
bounds, err := metadata.Bounds() | ||
|
||
if err != nil { | ||
log.Fatalf("Failed to derive bounds metadata after update") | ||
} | ||
|
||
center, err := metadata.Center() | ||
|
||
if err != nil { | ||
log.Fatalf("Failed to derive bounds metadata after update") | ||
} | ||
|
||
minZoom, err := metadata.MinZoom() | ||
|
||
if err != nil { | ||
log.Fatalf("Failed to derive min zoom metadata after update") | ||
} | ||
|
||
maxZoom, err := metadata.MaxZoom() | ||
|
||
if err != nil { | ||
log.Fatalf("Failed to derive max zoom metadata after update") | ||
} | ||
|
||
log.Printf("[%s] bounds: %v center: %v zoom: %d-%d\n", path, bounds, center, minZoom, maxZoom) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
module github.com/tilezen/go-tilepacks | ||
|
||
go 1.12 | ||
go 1.23 | ||
|
||
require ( | ||
github.com/aaronland/go-string v1.0.0 | ||
github.com/aws/aws-sdk-go v1.44.65 | ||
github.com/mattn/go-sqlite3 v1.14.14 | ||
github.com/paulmach/orb v0.9.0 | ||
github.com/schollz/progressbar/v3 v3.13.0 | ||
github.com/aws/aws-sdk-go v1.55.5 | ||
github.com/mattn/go-sqlite3 v1.14.23 | ||
github.com/paulmach/orb v0.11.1 | ||
github.com/schollz/progressbar/v3 v3.14.6 | ||
) | ||
|
||
require ( | ||
github.com/jmespath/go-jmespath v0.4.0 // indirect | ||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect | ||
github.com/rivo/uniseg v0.4.7 // indirect | ||
go.mongodb.org/mongo-driver v1.11.4 // indirect | ||
golang.org/x/sys v0.22.0 // indirect | ||
golang.org/x/term v0.22.0 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.