修复Step7采样点布设路径读取问题:GDAL环境变量保护+路径归一化+FileNotFoundError检查+水域掩膜备选路径扫描

This commit is contained in:
DXC
2026-05-08 18:05:11 +08:00
parent 3c0bd29275
commit d7b5c45dd4
3 changed files with 45 additions and 3 deletions

View File

@ -1,10 +1,21 @@
from src.utils.util import *
import math
# -*- coding: utf-8 -*-
"""
采样点生成模块 - 提供分块采样和光谱数据提取功能
"""
import os
import math
# GDAL 环境变量保护(放在最前面,防止路径/编码问题)
os.environ['GDAL_FILENAME_IS_UTF8'] = 'YES'
os.environ['SHAPE_ENCODING'] = 'UTF-8'
import numpy as np
from osgeo import gdal, ogr
import spectral
from scipy import ndimage
from src.utils.util import write_bands
try:
from skimage import morphology
from skimage.morphology import skeletonize, medial_axis
@ -87,6 +98,12 @@ def get_spectral_sampling_points_chunked(bil_file, water_mask_shp, severe_glint=
ogr.UseExceptions()
try:
# ---------- 路径归一化 + 存在性检查 ----------
bil_file = os.path.abspath(bil_file).replace('\\', '/')
print(f"[路径检查] 去耀斑影像: {bil_file}")
if not os.path.exists(bil_file):
raise FileNotFoundError(f"【后端错误】无法在磁盘上找到指定的去耀斑影像: {bil_file}")
# 打开bil文件
dataset_bil = gdal.Open(bil_file)
if dataset_bil is None: