Skip to content

Commit eccc90e

Browse files
committed
bugfixes galore
1 parent dde0a9f commit eccc90e

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

topo_map_processor/tools/collect_bounds.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ def cli():
3535
with open(args.output_file, 'w') as f:
3636
f.write('{ "type": "FeatureCollection", "features": [\n')
3737

38-
for i,feat in enumerate(feat_map.values()):
38+
feats = list(feat_map.values())
39+
for i,feat in enumerate(feats):
3940
line = json.dumps(feat)
4041

41-
if i != len(paths) - 1:
42+
if i != len(feats) - 1:
4243
line += ','
4344
line += '\n'
4445
f.write(line)

topo_map_processor/tools/retile.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# dependencies = [
44
# "mercantile",
55
# "pmtiles",
6+
# "shapely",
67
# ]
78
# ///
89

@@ -18,18 +19,15 @@
1819

1920

2021
import mercantile
21-
from shapely.geometry import mapping
22+
from shapely.geometry import shape
2223

2324
from osgeo_utils.gdal2tiles import main as gdal2tiles_main
2425
from osgeo_utils.gdal2tiles import create_overview_tile, TileJobInfo, GDAL2Tiles
2526

26-
2727
from tile_sources import PartitionedPMTilesSource, MissingTileError
2828

2929
WEBP_QUALITY = 75
3030

31-
32-
3331
class AttrDict(dict):
3432
def __init__(self, *args, **kwargs):
3533
super(AttrDict, self).__init__(*args, **kwargs)
@@ -110,7 +108,7 @@ def get_tile_file(tile, tiles_dir):
110108

111109
def check_sheets(sheets_to_pull, tiffs_dir):
112110
for sheet_no in sheets_to_pull:
113-
to = tiffs_dir.joinpath(f'{sheet_no}.tif')
111+
to = tiffs_dir.joinpath(f'{sheet_no}')
114112
if not to.exists():
115113
raise Exception(f'missing file {to}')
116114

@@ -122,7 +120,7 @@ def copy_tiles_over(tiles_to_pull, tiles_dir, from_pmtiles_prefix):
122120
pull_from_pmtiles(to, from_pmtiles_prefix)
123121

124122

125-
def create_upper_tiles(tiles_to_create, tiles_dir):
123+
def create_upper_tiles(z, tiles_to_create, tiles_dir):
126124
options = AttrDict({
127125
'resume': True,
128126
'verbose': False,
@@ -162,7 +160,7 @@ def get_sheet_data(bounds_fname):
162160
sheets_to_box = {}
163161
for f in index_data['features']:
164162
sheet_no = f['properties']['id']
165-
geom = mapping(f['geometry'])
163+
geom = shape(f['geometry'])
166164
xmin, ymin, xmax, ymax = geom.bounds
167165
box = mercantile.LngLatBbox(xmin, ymin, xmax, ymax)
168166
sheets_to_box[sheet_no] = box
@@ -203,7 +201,7 @@ def create_vrt_file(sheets, tiffs_dir):
203201
vrt_file = Path(f'{tiffs_dir}/combined.vrt')
204202
if vrt_file.exists():
205203
return vrt_file
206-
tiff_list = [ tiffs_dir.joinpath(f'{p_sheet}.tif').resolve() for p_sheet in sheets ]
204+
tiff_list = [ tiffs_dir.joinpath(f'{p_sheet}').resolve() for p_sheet in sheets ]
207205
tiff_list = [ str(f) for f in tiff_list if f.exists() ]
208206

209207
tiff_list_str = ' '.join(tiff_list)
@@ -239,7 +237,7 @@ def cli():
239237
parser.error(f"The following arguments are required when --sheets-to-pull-list-outfile is not provided: {', '.join(missing)}")
240238

241239
retile_sheets = Path(args.retile_list_file).read_text().split('\n')
242-
retile_sheets = set([ r.strip() for r in retile_sheets if r.strip() != '' ])
240+
retile_sheets = set([ r.strip().replace('.tif', '') for r in retile_sheets if r.strip() != '' ])
243241

244242
if args.from_pmtiles_prefix is None:
245243
if not args.max_zoom:
@@ -271,7 +269,7 @@ def cli():
271269
for tile in affected_base_tiles:
272270
to_add = base_tiles_to_sheets[tile]
273271
for sheet in to_add:
274-
sheets_to_pull.add(sheet)
272+
sheets_to_pull.add(sheet + '.tif')
275273

276274
print(f'{sheets_to_pull=}')
277275

@@ -282,20 +280,22 @@ def cli():
282280
exit(0)
283281

284282

283+
tiles_dir = Path(args.tiles_dir)
284+
tiffs_dir = Path(args.tiffs_dir)
285285

286286
print('check the sheets availability')
287-
check_sheets(sheets_to_pull, args.tiffs_dir)
287+
check_sheets(sheets_to_pull, tiffs_dir)
288288

289289
print('creating vrt file from sheets involved')
290-
vrt_file = create_vrt_file(sheets_to_pull, args.tiffs_dir)
290+
vrt_file = create_vrt_file(sheets_to_pull, tiffs_dir)
291291

292292
Path(args.tiles_dir).mkdir(exist_ok=True, parents=True)
293293

294294
print('creating tiles for base zoom with a vrt')
295-
create_base_tiles(f'{vrt_file}', str(args.tiles_dir), f'{max_zoom}')
295+
create_base_tiles(str(vrt_file), tiles_dir, f'{max_zoom}')
296296

297297
print('deleting unwanted base tiles')
298-
delete_unwanted_tiles(affected_base_tiles, max_zoom, args.tiles_dir)
298+
delete_unwanted_tiles(affected_base_tiles, max_zoom, tiles_dir)
299299

300300
prev_affected_tiles = affected_base_tiles
301301
for z in range(max_zoom-1, min_zoom-1, -1):
@@ -313,13 +313,13 @@ def cli():
313313
child_tiles_to_pull.add(ctile)
314314

315315
print('copying additional child tiles required for curr level')
316-
copy_tiles_over(child_tiles_to_pull, args.tiles_dir, args.from_pmtiles_prefix)
316+
copy_tiles_over(child_tiles_to_pull, tiles_dir, args.from_pmtiles_prefix)
317317

318318
print('creating tiles for current level')
319-
create_upper_tiles(curr_affected_tiles, args.tiles_dir)
319+
create_upper_tiles(z, curr_affected_tiles, tiles_dir)
320320

321321
print('removing unwanted child tiles')
322-
delete_unwanted_tiles(prev_affected_tiles, z+1, args.tiles_dir)
322+
delete_unwanted_tiles(prev_affected_tiles, z+1, tiles_dir)
323323

324324
prev_affected_tiles = curr_affected_tiles
325325

topo_map_processor/tools/tile_sources.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def __init__(self, pmtiles_prefix):
108108

109109
self.fnames = list(pmtiles_files)
110110
fname_to_index = { fname:i for i,fname in enumerate(self.fnames) }
111-
self.tiles_to_suffix = {}
111+
self.tiles_to_findex = {}
112112
self.tiles_to_size = {}
113113
for fname in self.fnames:
114114
print(f'collecting tile sizes from {fname}')
@@ -119,7 +119,7 @@ def __init__(self, pmtiles_prefix):
119119
self.tiles_to_size[tile] = len(t_data)
120120

121121
def get_reader_from_tile(self, tile):
122-
if tile not in self.tiles_to_suffix:
122+
if tile not in self.tiles_to_findex:
123123
raise MissingTileError()
124124
s = self.tiles_to_findex[tile]
125125
fname = self.fnames[s]
@@ -161,7 +161,7 @@ def min_zoom(self):
161161

162162
@property
163163
def max_zoom(self):
164-
return max(int([reader.header()['max_zoom']) for reader in self.readers.values()])
164+
return max([int(reader.header()['max_zoom']) for reader in self.readers.values()])
165165

166166
def get_meta_prop(self, prop_name):
167167
for reader in self.readers.values():

0 commit comments

Comments
 (0)