diff --git a/src/postprocessing/point_map.py b/src/postprocessing/point_map.py index a77c6bc..2f0dcad 100644 --- a/src/postprocessing/point_map.py +++ b/src/postprocessing/point_map.py @@ -107,16 +107,20 @@ class SamplingPointMap: else: rgb_bands = [0, 0, 0] - if downsample and (width > 2000 or height > 2000): - print(f" ⚠ 下采样暂被禁用,使用原始分辨率: {width}x{height}") - sample_factor = 1 + # ★ 底图仅供预览:整幅高光谱 RGB 在 34914x19177 全分辨率下 np.stack(float32) + # 会一次分配 ~7.5GiB 导致 OOM。统一用 GDAL buf 抽样,预览最长边 ≤ MAX_DIM。 + _MAX_DIM = 2048 + if max(width, height) <= _MAX_DIM: + buf_w, buf_h = width, height else: - sample_factor = 1 + _scale = _MAX_DIM / max(width, height) + buf_w, buf_h = max(1, int(width * _scale)), max(1, int(height * _scale)) rgb_data = [] for band_idx in rgb_bands: band = dataset.GetRasterBand(band_idx + 1) - band_data = band.ReadAsArray().astype(np.float32) + # buf_xsize/buf_ysize:由 GDAL 在读取时抽样,Python 只驻留 buf 大小的数组 + band_data = band.ReadAsArray(buf_xsize=buf_w, buf_ysize=buf_h).astype(np.float32) rgb_data.append(band_data) if len(rgb_data) == 3: @@ -128,7 +132,15 @@ class SamplingPointMap: projection = dataset.GetProjection() dataset = None - return image_array, geotransform, projection, width, height, sample_factor + # 返回“显示坐标系”:原点不变,像元尺寸按抽样比例放大; + # 下游 _geo_to_pixel 据此直接得到显示像素坐标,无需再按 sample_factor 除一次。 + disp_gt = list(geotransform) + if buf_w != width: + disp_gt[1] = geotransform[1] * (width / float(buf_w)) + if buf_h != height: + disp_gt[5] = geotransform[5] * (height / float(buf_h)) + sample_factor = 1 # 缩放已并入 disp_gt + return image_array, tuple(disp_gt), projection, buf_w, buf_h, sample_factor def _read_sampling_points(self, csv_path: str) -> pd.DataFrame: """智能读取采样点,自动识别模糊列名,允许UTM坐标,自动修复颠倒坐标"""