perf(step11): IDW auto-switch for large grids + GDAL fast rasterize

- 网格 >500K 点自动跳过 Kriging 切 IDW(千万级点从数小时降至数秒)
- n_closest_points 50→20,Block 每块打印进度
- GDAL ReprojectImage 直接重采样栅格掩膜,避免 58K 多边形 rasterize 卡死
- 自动扫描工作目录 .dat 栅格,不依赖 handler 传参
- 特殊 Unicode 字符替换为 ASCII 兼容
This commit is contained in:
duxin
2026-07-24 14:36:51 +08:00
parent d0344b8fa0
commit beed27b1f0
2 changed files with 202 additions and 55 deletions

View File

@ -193,11 +193,42 @@ class Step11MapHandler(BaseStepHandler):
input_crs=base_kwargs['input_crs'],
output_crs=base_kwargs['output_crs'],
)
# 原始路径若是栅格(.dat/.tif),传给 prepare_shared_context
# 走 GDAL 快速重采样通道,避免 58K 多边形 rasterize 卡死
_orig_path = boundary_shp_path
_raster_src = None
_RASTER_EXTS = ('.dat', '.tif', '.tiff', '.bsq', '.bil', '.bip', '.img')
if _orig_path and os.path.isfile(_orig_path):
_ext = os.path.splitext(_orig_path)[1].lower()
if _ext in _RASTER_EXTS:
_raster_src = _orig_path
# fallback: 扫描 work_dir 下的原始栅格掩膜
if _raster_src is None:
_wd = Path(str(context.work_dir))
for _sub in ('1_water_mask', '1_Water_Mask', 'water_mask'):
_scan_dir = _wd / _sub
if _scan_dir.is_dir():
for _ext in _RASTER_EXTS:
_hits = sorted(_scan_dir.glob(f'*{_ext}'),
key=lambda p: p.stat().st_mtime, reverse=True)
for _h in _hits:
if _h.is_file():
_raster_src = str(_h)
break
if _raster_src:
break
if _raster_src:
break
if _raster_src:
context.notify('step11_map', 'info',
f'找到原始栅格掩膜,将使用 GDAL 快速重采样: {Path(_raster_src).name}')
shared_ctx = pre_mapper.prepare_shared_context(
sample_csv=csv_paths[0],
shp_file=resolved_boundary,
resolution=float(base_kwargs['resolution']),
expand_ratio=0.05,
boundary_raster=_raster_src,
)
base_kwargs['shared_context'] = shared_ctx
context.notify('step11_map', 'info',