添加公式方法
This commit is contained in:
@ -348,7 +348,7 @@ class WaterIndexProcessor:
|
||||
hdr_path : str, optional
|
||||
ENVI HDR 文件路径(None → 自动构造)
|
||||
output_dir : str, optional
|
||||
输出目录(None → 与 bsq_path 同目录下的 8_WaterIndex_Images/)
|
||||
输出目录(None → 与 bsq_path 同目录下的 10_WaterIndex_Images/)
|
||||
formula_names : list, optional
|
||||
要处理的公式名列表(None → 处理全部)
|
||||
water_mask : np.ndarray, optional
|
||||
@ -374,7 +374,7 @@ class WaterIndexProcessor:
|
||||
|
||||
# ── 自动构造输出目录 ────────────────────────────────────────────
|
||||
if output_dir is None:
|
||||
output_dir = os.path.join(os.path.dirname(bsq_path), '8_WaterIndex_Images')
|
||||
output_dir = os.path.join(os.path.dirname(bsq_path), '10_WaterIndex_Images')
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
|
||||
def progress(msg: str, pct: float):
|
||||
@ -610,7 +610,7 @@ class WaterIndexProcessor:
|
||||
if os.path.isfile(hdr_path_alt):
|
||||
hdr_path = hdr_path_alt
|
||||
|
||||
output_dir = os.path.join(work_dir, "8_WaterIndex_Images")
|
||||
output_dir = os.path.join(work_dir, "10_WaterIndex_Images")
|
||||
|
||||
# ── 加载水域掩膜(可选)───────────────────────────────────────
|
||||
water_mask: Optional[np.ndarray] = None
|
||||
|
||||
@ -2,6 +2,7 @@ from osgeo import gdal, osr
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import os
|
||||
import re
|
||||
import spectral
|
||||
from math import sin, cos, tan, sqrt, radians
|
||||
|
||||
@ -473,9 +474,56 @@ def get_spectral_in_coor(imgpath, coorpath, outpath, radius=0, flare_path=None,
|
||||
for i in range(min(3, coor_data.shape[0])):
|
||||
print(f" 行{i + 1}: {coor_data[i, :min(5, coor_data.shape[1])]}") # 只显示前5列
|
||||
|
||||
# 提取原始坐标
|
||||
lat_array = coor_data[:, 1] # 第2列是纬度(跳过测量点ID列)
|
||||
lon_array = coor_data[:, 2] # 第3列是经度
|
||||
# 提取原始坐标(使用智能坐标列检测)
|
||||
lon_patterns = [
|
||||
r'^lon', r'^lng', r'^longitude', r'经度', r'^x$', r'^utm_x$', r'^pixel_x$'
|
||||
]
|
||||
lat_patterns = [
|
||||
r'^lat', r'^latitude', r'纬度', r'^y$', r'^utm_y$', r'^pixel_y$'
|
||||
]
|
||||
|
||||
x_col_name, y_col_name = None, None
|
||||
|
||||
if coor_df is not None and hasattr(coor_df, 'columns'):
|
||||
for col in coor_df.columns:
|
||||
col_str = str(col).lower().strip()
|
||||
if x_col_name is None and any(re.search(p, col_str) for p in lon_patterns):
|
||||
x_col_name = col
|
||||
if y_col_name is None and any(re.search(p, col_str) for p in lat_patterns):
|
||||
y_col_name = col
|
||||
|
||||
if x_col_name and y_col_name and x_col_name in coor_df.columns and y_col_name in coor_df.columns:
|
||||
lon_array = coor_df[x_col_name].values
|
||||
lat_array = coor_df[y_col_name].values
|
||||
print(f"💡 坐标列名检测: X/经度=[{x_col_name}], Y/纬度=[{y_col_name}]")
|
||||
else:
|
||||
numeric_cols = coor_df.select_dtypes(include=[np.number]).columns.tolist() if coor_df is not None else []
|
||||
if len(numeric_cols) >= 2:
|
||||
col1, col2 = numeric_cols[0], numeric_cols[1]
|
||||
mean1 = coor_df[col1].head(10).mean()
|
||||
mean2 = coor_df[col2].head(10).mean()
|
||||
if abs(mean1) <= 90 and abs(mean2) > 90:
|
||||
y_col_name, x_col_name = col1, col2
|
||||
lon_array = coor_df[x_col_name].values
|
||||
lat_array = coor_df[y_col_name].values
|
||||
elif abs(mean2) <= 90 and abs(mean1) > 90:
|
||||
x_col_name, y_col_name = col1, col2
|
||||
lon_array = coor_df[x_col_name].values
|
||||
lat_array = coor_df[y_col_name].values
|
||||
else:
|
||||
if mean1 > mean2:
|
||||
x_col_name, y_col_name = col1, col2
|
||||
else:
|
||||
x_col_name, y_col_name = col2, col1
|
||||
lon_array = coor_df[x_col_name].values
|
||||
lat_array = coor_df[y_col_name].values
|
||||
print(f"💡 触发智能数值推断坐标列: X/经度=[{x_col_name}], Y/纬度=[{y_col_name}]")
|
||||
else:
|
||||
if coor_data is not None and coor_data.shape[1] >= 3:
|
||||
lat_array = coor_data[:, 1]
|
||||
lon_array = coor_data[:, 2]
|
||||
else:
|
||||
raise Exception("坐标文件格式错误:需要至少2列数据,且最好包含坐标列名(如lon/lat/经度/纬度)")
|
||||
|
||||
print(f"\n=== 原始坐标信息 ===")
|
||||
print(f"原始坐标范围: 经度 {np.min(lon_array):.6f} ~ {np.max(lon_array):.6f}, 纬度 {np.min(lat_array):.6f} ~ {np.max(lat_array):.6f}")
|
||||
|
||||
Reference in New Issue
Block a user