@@ -231,11 +231,14 @@ def process_with_tiles(ept_file, tile_size, output_path, metric, voxel_size,
231231
232232 chm = core
233233
234+ # Derive core extent from CHM grid extent and actual pixel crop to avoid stretching
235+ dx , dy = voxel_size [0 ], voxel_size [1 ]
236+ grid_extent = extent # [x_min, x_max, y_min, y_max] as returned by calculate_chm
234237 core_extent = (
235- tile_min_x + buffer_x ,
236- tile_max_x - buffer_x ,
237- tile_min_y + buffer_y ,
238- tile_max_y - buffer_y ,
238+ grid_extent [ 0 ] + buffer_pixels_x * dx ,
239+ grid_extent [ 1 ] - buffer_pixels_x * dx ,
240+ grid_extent [ 2 ] + buffer_pixels_y * dy ,
241+ grid_extent [ 3 ] - buffer_pixels_y * dy ,
239242 )
240243
241244 create_geotiff (chm , result_file , srs , core_extent )
@@ -295,11 +298,13 @@ def process_with_tiles(ept_file, tile_size, output_path, metric, voxel_size,
295298 if end_x > start_x and end_y > start_y :
296299 result = result [start_y :end_y , start_x :end_x ]
297300
301+ # Derive core extent from voxel grid extent and applied pixel crop to avoid stretching
302+ dx , dy = voxel_size [0 ], voxel_size [1 ]
298303 core_extent = (
299- tile_min_x + buffer_x ,
300- tile_max_x - buffer_x ,
301- tile_min_y + buffer_y ,
302- tile_max_y - buffer_y ,
304+ spatial_extent [ 0 ] + buffer_pixels_x * dx ,
305+ spatial_extent [ 1 ] - buffer_pixels_x * dx ,
306+ spatial_extent [ 2 ] + buffer_pixels_y * dy ,
307+ spatial_extent [ 3 ] - buffer_pixels_y * dy ,
303308 )
304309
305310 if core_extent [1 ] <= core_extent [0 ] or core_extent [3 ] <= core_extent [2 ]:
0 commit comments