Skip to content

Commit

Permalink
Fix #478 with correct y-flip logic where the default is y=0 at top; a…
Browse files Browse the repository at this point in the history
…dd 'tms' scheme for zxy with flipped y (#479)
  • Loading branch information
larsmaxfield authored Oct 12, 2024
1 parent 6630348 commit 28960a9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion python/bin/pmtiles-convert
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ parser.add_argument(
"--overwrite", help="Overwrite the existing output.", action="store_true"
)
parser.add_argument(
"--scheme", help="Tiling scheme of the input directory ('ags', 'gwc', 'zyx', 'zxy' (default))."
"--scheme", help="Tiling scheme of the input directory ('ags', 'gwc', 'tms', 'zyx', 'zxy' (default))."
)
parser.add_argument(
"--format", help="Raster image format of tiles in the input directory ('png', 'jpeg', 'webp', 'avif') if not provided in the metadata.", dest="tile_format"
Expand Down
15 changes: 7 additions & 8 deletions python/pmtiles/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def disk_to_pmtiles(directory_path, output, maxzoom, **kwargs):
maxzoom (int, "auto"): Max zoom level to use. If "auto", uses highest zoom in directory.
Keyword args:
scheme (str): Tiling scheme of the directory ('ags', 'gwc', 'zyx', 'zxy' (default)).
scheme (str): Tiling scheme of the directory ('ags', 'gwc', 'tms', 'zyx', 'zxy' (default)).
tile_format (str): Image format of the tiles ('png', 'jpeg', 'webp', 'avif') if not given in the metadata.
verbose (bool): Set True to print progress.
Expand Down Expand Up @@ -247,33 +247,32 @@ def disk_to_pmtiles(directory_path, output, maxzoom, **kwargs):
count = 0
for row_dir in get_dirs(os.path.join(directory_path, zoom_dir)):
if scheme == 'ags':
y = flip_y(z, int(row_dir.replace("R", ""), 16))
y = int(row_dir.replace("R", ""), 16)
elif scheme == 'gwc':
pass
elif scheme == 'zyx':
y = flip_y(int(z), int(row_dir))
y = int(row_dir)
else:
x = int(row_dir)
for current_file in os.listdir(os.path.join(directory_path, zoom_dir, row_dir)):
if current_file == ".DS_Store":
pass
else:
file_name, _ = current_file.split('.',1)
if scheme == 'xyz':
y = flip_y(int(z), int(file_name))
if scheme == 'tms':
y = flip_y(z, int(file_name))
elif scheme == 'ags':
x = int(file_name.replace("C", ""), 16)
elif scheme == 'gwc':
x, y = file_name.split('_')
x = int(x)
y = int(y)
y = flip_y(z, int(y))
elif scheme == 'zyx':
x = int(file_name)
else:
y = int(file_name)

flipped = (1 << z) - 1 - y
tileid = zxy_to_tileid(z, x, flipped)
tileid = zxy_to_tileid(z, x, y)
filepath = os.path.join(directory_path, zoom_dir, row_dir, current_file)
tileid_path_set.append((tileid, filepath))
count = count + 1
Expand Down

0 comments on commit 28960a9

Please sign in to comment.