活动介绍
file-type

泰森斜率计算器:栅格数据分析工具

ZIP文件

3星 · 超过75%的资源 | 2KB | 更新于2025-04-12 | 41 浏览量 | 6 下载量 举报 收藏
download 立即下载
### 标题知识点解释: 标题中提到的“slope_栅格数据slope_”暗示了文档或文件内容与栅格数据的斜率计算有关。斜率(slope)在地理信息系统(GIS)中是一个关键的空间分析工具,用于确定地理表面的倾斜程度。当应用于栅格数据(即由规则格网组成的地理数据模型)时,斜率分析可以帮助我们了解地表形态,如山脉、河床的倾斜度,这对于土木工程、水文学、生态学以及土地利用规划等多个领域至关重要。 ### 描述知识点解释: 描述部分指出该文件是一个用于计算栅格数据斜率的程序或脚本,并特别指明了计算的是泰森斜率(Thiessen slope)。泰森多边形(Thiessen polygons)或称为沃罗诺伊图(Voronoi diagram)是在特定点集基础上形成的,其中每个点都有一个与之相关的多边形区域,区域内任何位置到该点的距离都小于到其他点的距离。虽然泰森多边形通常用于空间分析中的区域划分,但泰森斜率并不是一个常见的术语,可能是指在计算泰森多边形过程中同时计算的某个地形斜率数据。这表明该脚本或程序在处理栅格数据时,可能采用了特定的空间分析算法,以得到泰森多边形相关的栅格数据斜率。 描述还指出该程序非常灵活,用户可以通过替换数据路径来对不同的栅格数据集进行斜率分析。这意味着用户界面友好,易于操作,不需要用户具备深入的编程知识就可以使用。它也可能暗示该脚本是用一种通用的编程语言编写的,例如Python,这在GIS领域的脚本和自动化任务中非常常见。 ### 标签知识点解释: 标签“栅格数据slope”表明这个程序或文件聚焦于栅格数据处理中的斜率计算功能。在GIS领域,标签用于帮助用户快速识别内容和功能,因此这进一步确认了该文件的用途。 ### 压缩包子文件的文件名称列表知识点解释: 文件列表中仅包含了“slope.py”,这暗示了该程序可能是用Python语言编写的。Python是GIS领域常用的脚本语言,因为它简单易学,功能强大,且有着丰富的库支持空间数据处理和分析。例如,GDAL(Geospatial Data Abstraction Library)和Rasterio是两个常用于栅格数据分析的Python库。文件名“slope.py”表明这个文件可能是此类库的一个应用实例,它将包含执行栅格数据斜率计算的核心代码。 ### 综合知识点解释: 综合以上信息,我们可以推断出该文件是一个GIS领域中用于计算栅格数据斜率的Python脚本。它可能使用了如GDAL或Rasterio等库来处理栅格数据,并计算出每个栅格单元的斜率值。泰森斜率的概念虽然不常见,但在计算泰森多边形过程中,可能涉及到计算多边形中心点或边缘点周围栅格单元的斜率值。 斜率分析在GIS中非常有用,它可以帮助分析地形特征、评估水土流失风险、进行洪水模拟和规划土地开发等。用户只需将特定的栅格数据路径指向该脚本,就能得到斜率分析结果,这大大降低了斜率计算的技术门槛,使得非专业人士也能进行复杂的空间分析任务。 总结来说,这个“slope.py”文件是一个在GIS环境中计算栅格数据斜率的工具,使用Python语言编写,具有用户友好的操作特性,并且可能使用了先进的空间分析库。对于需要进行地形分析的专业人士而言,这是一个有价值的资源。

相关推荐

filetype

请给以下代码做好排版: import numpy as np import rasterio import matplotlib.pyplot as plt import pandas as pd from math import sqrt, atan2, degrees, radians, sin, cos , arccos import warnings warnings.filterwarnings("ignore", category=rasterio.errors.NotGeoreferencedWarning) # 1. 读取地形数据 def read_terrain_data(file_path): with rasterio.open(file_path) as src: elevation_data = src.read(1) return elevation_data # 2. 获取栅格高程 def get_elevation(x, y, elevation_map): rows, cols = elevation_map.shape col_idx = x row_idx = rows - 1 - y [r,c]=(np.array([row_idx,col_idx])).astype(np.int16) if 0 <= col_idx < cols and 0 <= row_idx < rows: return elevation_map[r,c] else: return None # 3. 计算坡度(中心差分法) def calculate_slope(x, y, elevation_map,flag): h = get_elevation(x, y, elevation_map) if h is None: return None h_d = get_elevation(x - 1, y, elevation_map) h_f = get_elevation(x + 1, y, elevation_map) h_b = get_elevation(x, y + 1, elevation_map) h_h = get_elevation(x, y - 1, elevation_map) h_a = get_elevation(x - 1, y+1, elevation_map) h_c = get_elevation(x + 1, y+1, elevation_map) h_g = get_elevation(x - 1, y-1, elevation_map) h_i = get_elevation(x + 1, y-1, elevation_map) if None in [h_a,h_b,h_c,h_d,h_f,h_g,h_h,h_i]: return None dz_dx = (h_c+2*h_f+h_i-h_a-2*h_d-h_g)/8 dz_dy = (h_a+2*h_b+h_c-h_g-2*h_h-h_i)/8 slope_rad = atan2(sqrt(dz_dx**2 + dz_dy**2), 1) #S slope_deg = degrees(slope_rad) slope_way = 270 + degrees(dz_dx/dz_dy) - 90*(dz_dy/abs(dz_dy)) way_rad = radians(slope_way) #A [n1,n2,n3] = [sin(slope_rad)*sin(way_rad),sin(slope_rad)*cos(way_rad),cos(slope_rad)] if flag== 0: return slope_deg else: return [n1,n2,n3] # 4. 读取路径数据 def read_path_data(excel_path): df = pd.read_excel(excel_path, header=None) da1 = pd.read_excel("D:\model\area1.xlsx",sheet_name=0,header=1) path1 =[] da2 = pd.read_excel("D:\model\area1.xlsx",sheet_name=1,header=1) path2 =[] for _, row in da1.iterrows(): x, y = int(row[2]), int(row[3]) path1.append((x, y)) for _, row in da2.iterrows(): x, y = int(row[2]), int(row[3]) path2.append((x, y)) path_data = [] for _, row in df.iterrows(): x, y, heading = int(row[1]), int(row[2]), int(row[3]) if 8300<=x<=9800 or 3501<=x<=4500: if (x,y)in path1 or (x,y)in path2: path_data.append((x, y, heading,1)) else: path_data.append((x, y, heading,0)) else: path_data.append((x, y, heading,0)) return path_data # 5. 计算路径指标 def calculate_path_metrics(path_data, elevation_map): total_distance = 0 all_time = 0 dangerous_time =0 esplion =0 angle_changes = [] speeding = [] #速度 length = [] #里程 timing = [0] #时间 heigh = [] #高程 sloping = [] #坡度 for i in range(1, len(path_data)): x1, y1, h1 = path_data[i - 1] x2, y2, h2, flag = path_data[i] heigh.append(h2) dx = abs(x2 - x1) dy = abs(y2 - y1) dl = dx +dy dheading = abs(h1 -h2) if dl==1: if dheading == 0: w = 1 if dheading == 45: w = 1.5 if dheading == 90: w = 2 else: if dheading == 0: w = sqrt(2) if dheading == 45: w = sqrt(2) + 0.5 if dheading == 90: w = sqrt(2) + 1 distance = 5*w length.append(distance) #里程表 total_distance += distance slope1 = calculate_slope(x1, y1, elevation_map) slope2 = calculate_slope(x2, y2, elevation_map) sloping.append(slope2) #坡度表 delta_heading = (h2 - h1 + 180) % 360 - 180 angle_changes.append(abs(delta_heading)) if slope2 is None or slope2 > 30: speed = 0 else: speed = 30 if slope2 < 10 else (20 if slope2 < 20 else 10) speeding.append(speed) #速度表 time = distance / (speed / 3.6) if speed > 0 else 0 timing.append(time) #时间表 all_time += time #时效性 if flag==1: dangerous_time+=time #安全性 dslope = (slope1 + slope2)/2 n1,n2,n3=calculate_slope(x1, y1, elevation_map,1) n4,n5,n6=calculate_slope(x2, y2, elevation_map,1) delta = arccos((n1*n4+n2*n5+n3*n6)/(sqrt(n1**2+n2**2+n3**2)*sqrt(n4**2+n5**2+n6**2))) esplion += delta * dslope #平稳性 return { "里程(m)": total_distance, "时效性(秒)": all_time, "平稳性": esplion, "安全性": dangerous_time } # 6. 绘制曲线 def plot_curves(a, elevation_map): # 计算各项指标(保持不变) distances = [0] elevations = [get_elevation(path_data[0][0], path_data[0][1], elevation_map)] slopes = [] speeds = [] angle_changes = [0] for i in range(1, len(path_data)): x1, y1, h1 = path_data[i - 1] x2, y2, h2 = path_data[i] dx = (x2 - x1) * 5 dy = (y2 - y1) * 5 distance = distances[-1] + sqrt(dx**2 + dy**2) distances.append(distance) elevation = get_elevation(x2, y2, elevation_map) elevations.append(elevation) slope = calculate_slope(x2, y2, elevation_map) slopes.append(slope if slope is not None else 0) delta_heading = (h2 - h1 + 180) % 360 - 180 angle_changes.append(abs(delta_heading)) if slope is None : speed = 0 else: base_speed = 30 if slope < 10 else (20 if slope < 20 else 10) speed = max(5, base_speed - abs(delta_heading) / 10) speeds.append(speed) # 转换为numpy数组 distances = np.array(distances) speeds = np.array(speeds) angle_changes = np.array(angle_changes) # 优化3:避免降采样,改用抗锯齿绘制(关键改进) fig, axes = plt.subplots(4, 1, figsize=(12, 16), dpi=120) # 提高DPI使线条更细 # 1. 高程-里程曲线(保持不变) axes[0].plot(distances, elevations, 'b-', linewidth=1, alpha=0.8) axes[0].set_title("Elevation-mileage curve") axes[0].set_ylabel("Elevation(m)") # 2. 坡度-里程曲线(保持不变) axes[1].plot(distances[1:], slopes, 'r-', linewidth=1, alpha=0.8) axes[1].set_title("Slope-mileage curve") axes[1].set_ylabel("Slope(°)") # 3. 速度-距离曲线(优化为细曲线) axes[2].plot(distances[1:], speeds, 'g-', linewidth=1.2, alpha=0.9, rasterized=True) # 启用抗锯齿 axes[2].set_title("Speed-distance curve") axes[2].set_ylabel("Speed(km/h)") axes[2].set_ylim(0, 40) axes[2].grid(True, linestyle='--', alpha=0.5) # 4. 转向角-里程曲线(优化为细曲线) axes[3].plot(distances, angle_changes, 'm-', linewidth=1.2, alpha=0.9, rasterized=True) # 启用抗锯齿 axes[3].set_title("Steering angle-mileage curve") axes[3].set_ylabel("Steering angle(°)") axes[3].set_xlabel("Distance (m)") axes[3].set_ylim(0, 40) axes[3].grid(True, linestyle='--', alpha=0.5) plt.tight_layout() plt.show() # 主程序 if __name__ == "__main__": elevation_map = read_terrain_data("D:/model/map.tif") path_data = read_path_data("D:/model/pathy.xlsx") metrics = calculate_path_metrics(path_data, elevation_map) print("路径指标:") for key, value in metrics.items(): print(f"{key}: {value:.2f}") plot_curves(path_data, elevation_map)

慕酒
  • 粉丝: 70
上传资源 快速赚钱