ContentMapper 边界读取支持栅格水掩膜(.dat/.bsq/.tif/.tiff/.img)
This commit is contained in:
@ -18,6 +18,7 @@ ROOT = Path(__file__).resolve().parents[1]
|
||||
PIPELINE_FILE = ROOT / "src" / "core" / "water_quality_inversion_pipeline_GUI.py"
|
||||
PANEL_FILE = ROOT / "src" / "gui" / "panels" / "step11_map_panel.py"
|
||||
RESOLVER_FILE = ROOT / "src" / "gui" / "panels" / "_step_path_resolver.py"
|
||||
MAP_FILE = ROOT / "src" / "postprocessing" / "map.py"
|
||||
|
||||
|
||||
def test_step10_map_forced_override():
|
||||
@ -101,6 +102,46 @@ def test_panel_guard_does_not_overwrite_existing():
|
||||
print("✅ step11 panel 4.5 段遵守 '非空值不覆盖' 原则")
|
||||
|
||||
|
||||
def test_map_supports_raster_mask_formats():
|
||||
"""验证 ContentMapper.read_boundary_shapefile 内部已支持栅格格式分发(.dat/.bsq/.tif/.tiff/.img)。
|
||||
|
||||
之前 bug:4.5 段成功把 .dat 填入 boundary_file,但 ContentMapper 内部
|
||||
gpd.read_file(.dat) 直接报错。修复后 ContentMapper 内部按后缀分发:
|
||||
- .shp → 矢量(保持原行为)
|
||||
- .dat/.bsq/.tif/.tiff/.img → rasterio.features.shapes 矢量化成 GeoDataFrame
|
||||
"""
|
||||
text = MAP_FILE.read_text(encoding="utf-8")
|
||||
# 找 def read_boundary_shapefile
|
||||
m = re.search(
|
||||
r"def read_boundary_shapefile\(self,[^\)]*\)[^\n]*:\n(.*?)(?=\n def |\nclass |\Z)",
|
||||
text, re.DOTALL,
|
||||
)
|
||||
assert m, "找不到 read_boundary_shapefile 方法"
|
||||
body = m.group(1)
|
||||
|
||||
# 关键标记:format dispatch
|
||||
assert ".dat" in body, "read_boundary_shapefile 应支持 .dat 栅格"
|
||||
assert ".bsq" in body, "read_boundary_shapefile 应支持 .bsq 栅格"
|
||||
assert ".tif" in body, "read_boundary_shapefile 应支持 .tif 栅格"
|
||||
assert "gpd.read_file(shp_file)" in body, ".shp 分支应保留 gpd.read_file 矢量读取"
|
||||
assert "rasterio.features.shapes" in body or "from rasterio.features import" in text, \
|
||||
"栅格分支应使用 rasterio.features.shapes 矢量化"
|
||||
# 验证 helper 方法存在
|
||||
assert "def _raster_to_boundary_gdf" in text, \
|
||||
"应新增 _raster_to_boundary_gdf helper 方法"
|
||||
# 验证 helper 内有栅格读取 + 矢量化 + GeoDataFrame 返回
|
||||
helper_m = re.search(
|
||||
r"def _raster_to_boundary_gdf\(self,[^\)]*\)[^\n]*:\n(.*?)(?=\n def |\nclass |\Z)",
|
||||
text, re.DOTALL,
|
||||
)
|
||||
assert helper_m, "找不到 _raster_to_boundary_gdf 方法"
|
||||
helper = helper_m.group(1)
|
||||
assert "rasterio.open" in helper, "helper 应调用 rasterio.open 读栅格"
|
||||
assert "shapes(" in helper, "helper 应调用 rasterio.features.shapes 矢量化"
|
||||
assert "gpd.GeoDataFrame" in helper, "helper 应返回 gpd.GeoDataFrame"
|
||||
print("✅ ContentMapper.read_boundary_shapefile 支持 .shp/.dat/.bsq/.tif 多格式分发")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("=" * 60)
|
||||
print("Smoke test: 彻底修复底层写入路径与掩膜联动")
|
||||
@ -110,6 +151,7 @@ if __name__ == "__main__":
|
||||
test_step11_panel_calls_pipeline_get_step_output_dir()
|
||||
test_fallback_dir_table_water_mask()
|
||||
test_panel_guard_does_not_overwrite_existing()
|
||||
test_map_supports_raster_mask_formats()
|
||||
print("=" * 60)
|
||||
print("全部通过 ✅")
|
||||
sys.exit(0)
|
||||
|
||||
Reference in New Issue
Block a user