Skip to content

Commit

Permalink
Log a warning if MBTiles is missing format metadata [#167]
Browse files Browse the repository at this point in the history
  • Loading branch information
bdon committed May 28, 2024
1 parent 6986931 commit ca451ea
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pmtiles/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ func convertMbtiles(logger *log.Logger, input string, output string, deduplicate
mbtilesMetadata = append(mbtilesMetadata, stmt.ColumnText(1))
}
}

if !mbtilesMetadataHasFormat(mbtilesMetadata) {
logger.Println("WARNING: MBTiles metadata is missing format information. Update this with: INSERT INTO metadata (name, value) VALUES ('format', 'png')")
}

header, jsonMetadata, err := mbtilesToHeaderJSON(mbtilesMetadata)

if err != nil {
Expand Down Expand Up @@ -558,6 +563,15 @@ func parseCenter(center string) (int32, int32, uint8, error) {
return int32(centerLon * E7), int32(centerLat * E7), uint8(centerZoom), nil
}

func mbtilesMetadataHasFormat(mbtilesMetadata []string) bool {
for i := 0; i < len(mbtilesMetadata); i += 2 {
if mbtilesMetadata[i] == "format" {
return true
}
}
return false
}

func mbtilesToHeaderJSON(mbtilesMetadata []string) (HeaderV3, map[string]interface{}, error) {
header := HeaderV3{}
jsonResult := make(map[string]interface{})
Expand Down
5 changes: 5 additions & 0 deletions pmtiles/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ func TestMbtiles(t *testing.T) {
assert.True(t, ok)
}

func TestMbtilesMissingFormat(t *testing.T) {
assert.False(t, mbtilesMetadataHasFormat([]string{"version", "1.0"}))
assert.True(t, mbtilesMetadataHasFormat([]string{"format", "png"}))
}

func TestMbtilesMissingBoundsCenter(t *testing.T) {
header, _, err := mbtilesToHeaderJSON([]string{
"name", "test_name",
Expand Down

0 comments on commit ca451ea

Please sign in to comment.