Toujours supprimer le LAS temporaire du repli PDAL, même en échec
This commit is contained in:
@ -312,6 +312,7 @@ def _read_with_pdal(laz_file):
|
|||||||
import tempfile
|
import tempfile
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
tmp_path = None
|
||||||
try:
|
try:
|
||||||
# Convert COPC to LAS via PDAL, then read with laspy
|
# Convert COPC to LAS via PDAL, then read with laspy
|
||||||
with tempfile.NamedTemporaryFile(suffix='.las', delete=False) as tmp:
|
with tempfile.NamedTemporaryFile(suffix='.las', delete=False) as tmp:
|
||||||
@ -331,18 +332,10 @@ def _read_with_pdal(laz_file):
|
|||||||
|
|
||||||
if result.returncode != 0:
|
if result.returncode != 0:
|
||||||
logger.warning(f" PDAL conversion échouée: {result.stderr[:200]}")
|
logger.warning(f" PDAL conversion échouée: {result.stderr[:200]}")
|
||||||
try:
|
|
||||||
os.unlink(tmp_path)
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
import laspy
|
import laspy
|
||||||
las = laspy.read(tmp_path)
|
las = laspy.read(tmp_path)
|
||||||
try:
|
|
||||||
os.unlink(tmp_path)
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
if len(las.points) == 0:
|
if len(las.points) == 0:
|
||||||
logger.warning(f" PDAL: conversion réussie mais 0 points")
|
logger.warning(f" PDAL: conversion réussie mais 0 points")
|
||||||
return None
|
return None
|
||||||
@ -351,6 +344,14 @@ def _read_with_pdal(laz_file):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f" PDAL fallback échoué: {e}")
|
logger.warning(f" PDAL fallback échoué: {e}")
|
||||||
return None
|
return None
|
||||||
|
finally:
|
||||||
|
# Toujours supprimer le LAS temporaire, même en cas d'exception
|
||||||
|
# (timeout subprocess, laspy.read échoué…) : sinon fuite de ~Go.
|
||||||
|
if tmp_path:
|
||||||
|
try:
|
||||||
|
os.unlink(tmp_path)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def detect_ground_method(laz_file):
|
def detect_ground_method(laz_file):
|
||||||
|
|||||||
Reference in New Issue
Block a user