Update pyThtoQgis.py

This commit is contained in:
Alex38Lyon
2026-08-28 15:32:44 +02:00
parent 2c11b0e344
commit d1056d689c
+77 -73
View File
@@ -422,112 +422,116 @@ def extractVertices(input_gpkg_path, output_gpkg_path):
################################################################################################# #################################################################################################
def diagnostic(file_path): def diagnostic(file_path):
try:
start_time = time.time() start_time = time.time()
if not os.path.exists(file_path): if not os.path.exists(file_path):
log.error(f"diagnostic, fichier non trouvé : {Colors.ENDC}{file_path}") log.error(f"diagnostic, fichier non trouvé : {Colors.ENDC}{file_path}")
globalDat.errorCount += 1 globalDat.errorCount += 1
return return
ds = ogr.Open(file_path) ds = ogr.Open(file_path)
if ds is None: if ds is None:
log.error(f"Impossible d'ouvrir le fichier : {Colors.ENDC}{file_path}") log.error(f"Impossible d'ouvrir le fichier : {Colors.ENDC}{file_path}")
globalDat.errorCount += 1 globalDat.errorCount += 1
return return
layer = ds.GetLayer() layer = ds.GetLayer()
total = 0 total = 0
invalid = 0 invalid = 0
empty = 0 empty = 0
multi_geom_count = 0 multi_geom_count = 0
geom_types = defaultdict(int) geom_types = defaultdict(int)
has_z = False has_z = False
has_m = False has_m = False
field_stats = defaultdict(list) field_stats = defaultdict(list)
extent = layer.GetExtent() extent = layer.GetExtent()
srs = layer.GetSpatialRef() srs = layer.GetSpatialRef()
crs = srs.ExportToWkt() if srs else "CRS inconnu" crs = srs.ExportToWkt() if srs else "CRS inconnu"
for feature in layer: for feature in layer:
total += 1 total += 1
geom = feature.GetGeometryRef() geom = feature.GetGeometryRef()
if geom is None or geom.IsEmpty(): if geom is None or geom.IsEmpty():
empty += 1 empty += 1
continue continue
geom_types[geom.GetGeometryName()] += 1 geom_types[geom.GetGeometryName()] += 1
if not geom.IsValid(): if not geom.IsValid():
invalid += 1 invalid += 1
gtype = geom.GetGeometryType() gtype = geom.GetGeometryType()
if ogr.GT_HasZ(gtype): if ogr.GT_HasZ(gtype):
has_z = True has_z = True
if ogr.GT_HasM(gtype): if ogr.GT_HasM(gtype):
has_m = True has_m = True
# champs attributaires # champs attributaires
layer_defn = layer.GetLayerDefn() layer_defn = layer.GetLayerDefn()
for i in range(layer_defn.GetFieldCount()): for i in range(layer_defn.GetFieldCount()):
field_name = layer_defn.GetFieldDefn(i).GetNameRef() field_name = layer_defn.GetFieldDefn(i).GetNameRef()
val = feature.GetField(i) val = feature.GetField(i)
if val is not None: if val is not None:
field_stats[field_name].append(val) field_stats[field_name].append(val)
elapsed = time.time() - start_time elapsed = time.time() - start_time
file_size = os.path.getsize(file_path) / (1024*1024) # Mo file_size = os.path.getsize(file_path) / (1024*1024) # Mo
log.info(f"==================== BILAN FILE : {Colors.ENDC}{safe_relpath(file_path)}{Colors.INFO} ====================") log.info(f"==================== BILAN FILE : {Colors.ENDC}{safe_relpath(file_path)}{Colors.INFO} ====================")
log.debug(f"Temps d'analyse : {Colors.ENDC}{elapsed:.2f}{Colors.INFO} s") log.debug(f"Temps d'analyse : {Colors.ENDC}{elapsed:.2f}{Colors.INFO} s")
log.debug(f"Taille : {Colors.ENDC}{file_size:.2f}{Colors.INFO} Mo") log.debug(f"Taille : {Colors.ENDC}{file_size:.2f}{Colors.INFO} Mo")
log.debug(f"Nombre d'objets : {Colors.ENDC}{total}") log.debug(f"Nombre d'objets : {Colors.ENDC}{total}")
if empty == 0 : log.debug(f"Géométries vides : {Colors.ENDC}{empty}") if empty == 0 : log.debug(f"Géométries vides : {Colors.ENDC}{empty}")
else : log.warning(f"Géométries vides : {Colors.ENDC}{empty}") else : log.warning(f"Géométries vides : {Colors.ENDC}{empty}")
if invalid == 0 : log.debug(f"Géométries invalides : {Colors.ENDC}{invalid}") if invalid == 0 : log.debug(f"Géométries invalides : {Colors.ENDC}{invalid}")
else : log.warning(f"Géométries invalides : {Colors.ENDC}{invalid}") else : log.warning(f"Géométries invalides : {Colors.ENDC}{invalid}")
log.debug(f"MultiGeometries / Collections : {Colors.ENDC}{multi_geom_count}") log.debug(f"MultiGeometries / Collections : {Colors.ENDC}{multi_geom_count}")
log.debug("Types géométriques :") log.debug("Types géométriques :")
for gtype, count in geom_types.items(): for gtype, count in geom_types.items():
log.debug(f"\t{gtype} : {Colors.ENDC}{count}") log.debug(f"\t{gtype} : {Colors.ENDC}{count}")
log.debug("Bounding box :") log.debug("Bounding box :")
log.debug(f"\txmin = {Colors.ENDC}{extent[0]}") log.debug(f"\txmin = {Colors.ENDC}{extent[0]}")
log.debug(f"\txmax = {Colors.ENDC}{extent[1]}") log.debug(f"\txmax = {Colors.ENDC}{extent[1]}")
log.debug(f"\tymin = {Colors.ENDC}{extent[2]}") log.debug(f"\tymin = {Colors.ENDC}{extent[2]}")
log.debug(f"\tymax = {Colors.ENDC}{extent[3]}") log.debug(f"\tymax = {Colors.ENDC}{extent[3]}")
log.debug(f"CRS : {Colors.ENDC}{crs}") log.debug(f"CRS : {Colors.ENDC}{crs}")
log.debug("Dimensions :") log.debug("Dimensions :")
log.debug(f"\tZ présent : {Colors.ENDC}{has_z}") log.debug(f"\tZ présent : {Colors.ENDC}{has_z}")
log.debug(f"\tM présent : {Colors.ENDC}{has_m}") log.debug(f"\tM présent : {Colors.ENDC}{has_m}")
log.debug("Champs attributaires :") log.debug("Champs attributaires :")
for field, values in field_stats.items(): for field, values in field_stats.items():
unique_count = len(set(values)) unique_count = len(set(values))
log.debug(f"\tchamp : {Colors.ENDC}{field}{Colors.DEBUG} : {Colors.ENDC}{len(values)}{Colors.DEBUG} valeurs, {Colors.ENDC}{unique_count}{Colors.DEBUG} uniques") log.debug(f"\tchamp : {Colors.ENDC}{field}{Colors.DEBUG} : {Colors.ENDC}{len(values)}{Colors.DEBUG} valeurs, {Colors.ENDC}{unique_count}{Colors.DEBUG} uniques")
log.info(f"=========================================================================================================") log.info(f"=========================================================================================================")
ds = None ds = None
return invalid return invalid
except RuntimeError as e:
log.warning(f"Unable to validate geometry: {e}, Continuing anyway.")
################################################################################################# #################################################################################################
def fix_geometry(geom, GetFID): def fix_geometry(geom, GetFID):