Skip to content

Commit 861ceaa

Browse files
committed
Sketch out writing a tile.json file
Doesn't work because it doesn't include the tiles key
1 parent 92a670a commit 861ceaa

File tree

5 files changed

+39
-13
lines changed

5 files changed

+39
-13
lines changed

tasks/make_boundaries/src/entities/Tileset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ def __init__(
1515
self.make_fn = make_fn
1616
self.make_args = make_args
1717

18-
def make(self) -> str | None:
18+
def make(self) -> list[str] | None:
1919
return self.make_fn(**self.make_args)

tasks/make_boundaries/src/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def run():
8888
print(f"Making {k}...")
8989
f = tilesets[k].make()
9090
if f:
91-
new_files.append(f)
91+
new_files.extend(f)
9292
else:
9393
failed_files.append(k)
9494

tasks/make_boundaries/src/usecases/make_admin.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from datetime import date
23

34
import geopandas as gp
@@ -15,8 +16,10 @@ def make_admin(cache_dir: str, output_dir: str, date: date):
1516

1617
# 1. Fetch the BKG data we need
1718
ds = date.strftime("%Y-%m-%d")
18-
json_path = f"{cache_dir}/admin_boundaries_{ds}.geojson"
19-
versatiles_path = f"{output_dir}/admin_boundaries_{ds}.versatiles"
19+
json_path = os.path.join(cache_dir, f"admin_boundaries_{ds}.geojson")
20+
versatiles_path = os.path.join(output_dir, f"admin_boundaries_{ds}.versatiles")
21+
tilejson_path = versatiles_path.replace(".versatiles", ".json")
22+
2023
fp = "vg250_01-01.utm32s.shape.ebenen/vg250_ebenen_0101"
2124

2225
zip_name = "vg250_01-01.utm32s.shape.ebenen.zip"
@@ -88,9 +91,9 @@ def make_admin(cache_dir: str, output_dir: str, date: date):
8891
print(f"Wrote to {json_path}")
8992

9093
try:
91-
make_versatiles(json_path, versatiles_path, date)
94+
make_versatiles(json_path, versatiles_path, tilejson_path, date)
9295
except Exception:
9396
print(f"Failed to build {versatiles_path}")
9497
return
9598

96-
return versatiles_path
99+
return [versatiles_path]

tasks/make_boundaries/src/usecases/make_admin_labels.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import datetime
2+
import os
23
from typing import Dict
34

45
import geopandas as gp
@@ -33,8 +34,11 @@ def make_admin_labels(cache_dir: str, output_dir: str, date: datetime.date):
3334

3435
# 1. Fetch the BKG data we need
3536
ds = date.strftime("%Y-%m-%d")
36-
json_path = f"{cache_dir}/admin_labels_{ds}.geojson"
37-
versatiles_path = f"{output_dir}/admin_labels_{ds}.versatiles"
37+
38+
json_path = os.path.join(cache_dir, f"admin_labels_{ds}.geojson")
39+
versatiles_path = os.path.join(output_dir, f"admin_labels_{ds}.versatiles")
40+
tilejson_path = versatiles_path.replace(".versatiles", ".json")
41+
3842
fp = "vg250_01-01.utm32s.shape.ebenen/vg250_ebenen_0101"
3943

4044
zip_name = "vg250_01-01.utm32s.shape.ebenen.zip"
@@ -123,9 +127,11 @@ def make_admin_labels(cache_dir: str, output_dir: str, date: datetime.date):
123127

124128
# 4. Convert to versatiles
125129
try:
126-
make_versatiles(json_path, versatiles_path, date, ["--base-zoom=5"])
130+
make_versatiles(
131+
json_path, versatiles_path, tilejson_path, date, ["--base-zoom=5"]
132+
)
127133
except Exception:
128134
print(f"Failed to build {versatiles_path}")
129135
return
130136

131-
return versatiles_path
137+
return [versatiles_path]

tasks/make_boundaries/src/usecases/make_versatiles.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33

44

55
def make_versatiles(
6-
input_path: str, output_path: str, date: dt.date, tc_args: list[str] = []
6+
input_path: str,
7+
output_path: str,
8+
tilejson_path: str,
9+
date: dt.date,
10+
tc_args: list[str] = [],
711
):
812
mbtiles_path = output_path.replace(".versatiles", ".mbtiles")
913
mbtiles_path_tmp = mbtiles_path.replace(".mbtiles", "_tmp.mbtiles")
@@ -36,10 +40,9 @@ def make_versatiles(
3640

3741
# Unclear to me why this fixes overzoom but it does
3842
subprocess.run(["tile-join", "-f", "-o", mbtiles_path_tmp, mbtiles_path])
39-
4043
print("done")
41-
print("Converting to versatiles... ", end="")
4244

45+
print("Converting to versatiles... ", end="")
4346
subprocess.run(
4447
[
4548
"versatiles",
@@ -51,6 +54,20 @@ def make_versatiles(
5154
).check_returncode()
5255
print("done")
5356

57+
print("Writing tiles.json... ", end="")
58+
with open(tilejson_path, "w") as f:
59+
subprocess.run(
60+
[
61+
"versatiles",
62+
"dev",
63+
"print-tilejson",
64+
"-p",
65+
output_path,
66+
],
67+
stdout=f,
68+
).check_returncode()
69+
print("done")
70+
5471
print("Cleaning up temporary files... ", end="")
5572
subprocess.run(["rm", mbtiles_path]).check_returncode()
5673
subprocess.run(["rm", mbtiles_path_tmp]).check_returncode()

0 commit comments

Comments
 (0)