Add LAZ integrity check to skip corrupted files early

Validate file readability before PDAL classification. Corrupted/truncated
files are detected instantly via laspy header read and skipped with a clear
error message pointing to re-download, instead of wasting time on PDAL
and repair attempts that will fail anyway.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jacquin Antoine
2026-05-14 17:59:32 +02:00
parent f988ddb76d
commit 7ac08f75dc
2 changed files with 28 additions and 0 deletions

View File

@ -124,6 +124,29 @@ def create_csf_pipeline(input_laz, output_las):
return _create_ground_pipeline(input_laz, output_las, 'csf')
def validate_laz(laz_file):
"""Quick integrity check for a LAZ/LAS file.
Reads the header with laspy to detect truncated or corrupted files
before launching expensive PDAL processing.
Returns:
True if file is readable, False otherwise.
"""
import laspy
try:
with laspy.open(str(laz_file)) as f:
# Just read the header — fast and catches truncated files
header = f.header
_ = header.point_count
return True
except Exception as e:
logger.error(f" ✗ Fichier corrompu ou incomplet: {laz_file.name}")
logger.error(f" {e}")
logger.error(f" → Re-télécharger depuis https://ign.fr/lidar-hd")
return False
def detect_ground_method(laz_file):
"""Detect the best ground classification method based on point cloud statistics.