Skip to content

add ability to convert a directory of tile files with XYZ structure#233

Open
jamesscottbrown wants to merge 1 commit intoprotomaps:mainfrom
jamesscottbrown:convert-directory
Open

add ability to convert a directory of tile files with XYZ structure#233
jamesscottbrown wants to merge 1 commit intoprotomaps:mainfrom
jamesscottbrown:convert-directory

Conversation

@jamesscottbrown
Copy link
Copy Markdown
Contributor

This provides the ability to generate a PMTiles archive from a directory of tiles directly, wihtout having to first create a PMTiles archive.

See protomaps/PMTiles#519

@mcbain
Copy link
Copy Markdown

mcbain commented Jul 1, 2025

Fix for hard coded png

path := filepath.Join(input, fmt.Sprintf("%d", z), fmt.Sprintf("%d", x), fmt.Sprintf("%d.%s", y, tileFormat))

extension := strings.ToLower(filepath.Ext(info.Name()))[1:]

// skip files with unsupported extensions
if _, ok := fileTypes[extension]; !ok {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe we should support .jpeg extensions too?

if tileFormat == "" {
tileFormat = extension
} else if tileFormat != extension {
return fmt.Errorf("mixed tile formats in directory: %s - enoountered both %s and %s", path, tileFormat, extension)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

encountered

return fmt.Errorf("invalid tile row: %s", y)
}

_minLat, _minLon, _maxLat, _maxLon := TileToLatLonBounds(int(zInt), int(xInt), int(yInt))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The tile coordinates are not enough to determine the intended geographic bounds for a tileset - tile pyramids that contain the z=0 tile will have a bounds of the entire web mercator extent. We need to read user-supplied bounds from a metadata.json or allow passing it on the command line.

header.MinLonE7 = minLon
header.MaxLonE7 = maxLon

header.CenterLatE7 = (minLat + maxLat) / 2
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This can be read from the center of a metadata.json and use this midpoint as a fallback

@bdon
Copy link
Copy Markdown
Member

bdon commented Jul 3, 2025

Thanks for tackling this feature. Overall I think we need to depend on necessary metadata existing in a metadata.json or equivalent, see this comment on how this was implemented in the python pmtiles package:

protomaps/PMTiles#338 (comment)

I know Tippecanoe outputs a metadata.json to directory outputs, maybe we ought to demand that the user author a metadata.json for this directory conversion to work simply (otherwise we would need to support N number of arbitrary formats, since AFAIK there is no standardization)?

A integration test for creating an archive from a directory would be nice too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants