@@ -56,6 +56,9 @@ def __init__(self, schema: str, table_tiles: str, wkt: str = None):
56
56
),
57
57
ins = {
58
58
"regular_grid_200m" : AssetIn (key_prefix = "ahn" ),
59
+ "laz_tiles_ahn3_200m" : AssetIn (key_prefix = "ahn" ),
60
+ "laz_tiles_ahn4_200m" : AssetIn (key_prefix = "ahn" ),
61
+ "laz_tiles_ahn5_200m" : AssetIn (key_prefix = "ahn" ),
59
62
"tiles" : AssetIn (key_prefix = "input" ),
60
63
"index" : AssetIn (key_prefix = "input" ),
61
64
"reconstruction_input" : AssetIn (key_prefix = "input" ),
@@ -80,25 +83,17 @@ def __init__(self, schema: str, table_tiles: str, wkt: str = None):
80
83
is_required = False ,
81
84
default_value = "info" ,
82
85
),
83
- "dir_tiles_200m_ahn3" : Field (
84
- str ,
85
- description = "Directory of the 200m tiles of AHN3. Used if the tiles are stored in a non-standard location." ,
86
- is_required = False ,
87
- ),
88
- "dir_tiles_200m_ahn4" : Field (
89
- str ,
90
- description = "Directory of the 200m tiles of AHN4. Used if the tiles are stored in a non-standard location." ,
91
- is_required = False ,
92
- ),
93
- "dir_tiles_200m_ahn5" : Field (
94
- str ,
95
- description = "Directory of the 200m tiles of AHN5. Used if the tiles are stored in a non-standard location." ,
96
- is_required = False ,
97
- ),
98
86
},
99
87
)
100
88
def reconstructed_building_models_nl (
101
- context , regular_grid_200m , tiles , index , reconstruction_input
89
+ context ,
90
+ regular_grid_200m ,
91
+ tiles ,
92
+ index ,
93
+ reconstruction_input ,
94
+ laz_tiles_ahn3_200m ,
95
+ laz_tiles_ahn4_200m ,
96
+ laz_tiles_ahn5_200m ,
102
97
):
103
98
"""Generate the 3D building models by running the reconstruction sequentially
104
99
within one partition.
@@ -110,15 +105,9 @@ def reconstructed_building_models_nl(
110
105
reconstruction_input ,
111
106
regular_grid_200m ,
112
107
tiles ,
113
- dir_tiles_200m_ahn3 = context .op_execution_context .op_config .get (
114
- "dir_tiles_200m_ahn3"
115
- ),
116
- dir_tiles_200m_ahn4 = context .op_execution_context .op_config .get (
117
- "dir_tiles_200m_ahn4"
118
- ),
119
- dir_tiles_200m_ahn5 = context .op_execution_context .op_config .get (
120
- "dir_tiles_200m_ahn5"
121
- ),
108
+ dir_tiles_200m_ahn3 = laz_tiles_ahn3_200m ,
109
+ dir_tiles_200m_ahn4 = laz_tiles_ahn4_200m ,
110
+ dir_tiles_200m_ahn5 = laz_tiles_ahn5_200m ,
122
111
)
123
112
124
113
context .log .info (f"{ roofer_toml = } " )
@@ -152,6 +141,19 @@ def create_roofer_config(
152
141
dir_tiles_200m_ahn4 = None ,
153
142
dir_tiles_200m_ahn5 = None ,
154
143
):
144
+ def laz_filepaths_generator (
145
+ file_store_dir : Path , resultset : list [tuple ], dir_200m_laz = None
146
+ ):
147
+ """Generator for the full 200m laz file paths that only emits existing paths."""
148
+ if dir_200m_laz is not None :
149
+ lazdir = Path (dir_200m_laz )
150
+ else :
151
+ lazdir = ahn_dir (file_store_dir , ahn_version = 5 ).joinpath ("tiles_200m" )
152
+ for tile_id_ahn in resultset :
153
+ p = lazdir / f"t_{ tile_id_ahn [0 ]} .laz"
154
+ if p .is_file ():
155
+ yield str (p )
156
+
155
157
toml_template = """
156
158
polygon-source = "{footprint_file}"
157
159
id-attribute = "identificatie"
@@ -237,26 +239,30 @@ def create_roofer_config(
237
239
"tile_id" : tile_id ,
238
240
},
239
241
)
240
- if dir_tiles_200m_ahn3 is not None :
241
- out_dir_ahn3 = Path (dir_tiles_200m_ahn3 )
242
- else :
243
- out_dir_ahn3 = ahn_dir (
244
- context .resources .file_store .file_store .data_dir , ahn_version = 3
245
- ).joinpath ("tiles_200m" )
246
- laz_files_ahn3 = [
247
- str (out_dir_ahn3 / f"t_{ tile_id_ahn [0 ]} .laz" ) for tile_id_ahn in res
248
- ]
249
- # TODO: probably should take the tiles_200m directory from the asset output
250
- if dir_tiles_200m_ahn4 is not None :
251
- out_dir_ahn4 = Path (dir_tiles_200m_ahn4 )
252
- else :
253
- out_dir_ahn4 = ahn_dir (
254
- context .resources .file_store .file_store .data_dir , ahn_version = 4
255
- ).joinpath ("tiles_200m" )
256
- # TODO: same with the laz filename pattern
257
- laz_files_ahn4 = [
258
- str (out_dir_ahn4 / f"t_{ tile_id_ahn [0 ]} .laz" ) for tile_id_ahn in res
259
- ]
242
+ laz_files_ahn3 = list (
243
+ laz_filepaths_generator (
244
+ file_store_dir = context .resources .file_store .file_store .data_dir ,
245
+ resultset = res ,
246
+ dir_200m_laz = dir_tiles_200m_ahn3 ,
247
+ )
248
+ )
249
+
250
+ laz_files_ahn4 = list (
251
+ laz_filepaths_generator (
252
+ file_store_dir = context .resources .file_store .file_store .data_dir ,
253
+ resultset = res ,
254
+ dir_200m_laz = dir_tiles_200m_ahn4 ,
255
+ )
256
+ )
257
+
258
+ laz_files_ahn5 = list (
259
+ laz_filepaths_generator (
260
+ file_store_dir = context .resources .file_store .file_store .data_dir ,
261
+ resultset = res ,
262
+ dir_200m_laz = dir_tiles_200m_ahn5 ,
263
+ )
264
+ )
265
+
260
266
# Would be neater if we could use -sql in the OGR connection to do this query,
261
267
# instead of creating a view.
262
268
tile_view = PostgresTableIdentifier (tiles .schema , f"t_{ tile_id } " )
@@ -284,13 +290,7 @@ def create_roofer_config(
284
290
footprint_file = f"PG:{ context .resources .db_connection .connect .dsn } tables={ tile_view } " ,
285
291
ahn3_files = laz_files_ahn3 ,
286
292
ahn4_files = laz_files_ahn4 ,
287
- ahn5_files = [
288
- str (
289
- ahn_dir (
290
- context .resources .file_store .file_store .data_dir , ahn_version = 5
291
- ).joinpath ("as_downloaded/LAZ" )
292
- )
293
- ],
293
+ ahn5_files = laz_files_ahn5 ,
294
294
output_path = output_dir ,
295
295
)
296
296
path_toml = output_dir / "roofer.toml"
0 commit comments