两期对比接口,土方量计算接口返回信息调整

This commit is contained in:
liyubo 2026-02-26 11:00:33 +08:00
parent 146872a4dd
commit dd931f6231
2 changed files with 1048 additions and 118 deletions

View File

@ -136,7 +136,132 @@ async def calc_earthwork(request: Request):
)
# 7. 返回成功响应
return _success_response(result)
res_dict = result.to_dict()
res_dict["calculation_details"] = None
res_dict["elevation_statistics"] = None
res_dict["volume_distribution"] = None
return _success_response(res_dict)
except ValueError as e:
logger.warning(f"参数验证失败: {str(e)}")
return _error_response(f"参数错误: {str(e)}", 400)
except Exception as e:
logger.error(f"计算失败: {str(e)}")
return _error_response(f"服务器内部错误: {str(e)}", 500)
# 两期对比接口-3dTiles
@earthwork_bp.post("/api/v1/calc/twoPhaseComparison")
async def two_phase_comparison(request: Request):
"""
两期对比接口
请求参数示例:
{
"polygonCoords": [
[
115.70440468338526,
30.77363140345639
],
[
115.70443054007985,
30.773510462589584
],
[
115.70459702429197,
30.77360789911405
]
],
"designElevation": 100,
"algorithm": "grid",
"resolution": 1,
"crs": "EPSG:4326",
"interpolationMethod": "linear",
"urlA": "http://222.212.85.86:9000/300bdf2b-a150-406e-be63-d28bd29b409f/model/hbgldk/yzk/20260113/3D/terra_b3dms/tileset.json",
"urlB": "http://222.212.85.86:9000/300bdf2b-a150-406e-be63-d28bd29b409f/model/hbgldk/yzk/20260113/3D/terra_b3dms/tileset.json"
}
"""
try:
# 1. 接收前端传参
data = request.json
if not data:
return _error_response("请求参数不能为空", 400)
# 2. 提取参数
polygon_coords = data.get("polygonCoords")
design_elevation = data.get("designElevation", 1000)
urlA = data.get("urlA")
urlB = data.get("urlB")
if not polygon_coords:
return _error_response("多边形坐标不能为空", 400)
if design_elevation is None:
return _error_response("设计高程不能为空", 400)
if urlA is None or urlB is None :
return _error_response("对比地图不能为空", 400)
# 3. 可选参数
algorithm = data.get("algorithm", "tin")
resolution = data.get("resolution", 1.0)
crs = data.get("crs", "EPSG:4326")
interpolation_method = data.get("interpolationMethod", "linear")
# 4. 参数验证
if len(polygon_coords) < 3:
return _error_response("多边形至少需要3个点", 400)
# 检查多边形是否闭合,如不闭合则自动闭合
if polygon_coords[0] != polygon_coords[-1]:
polygon_coords.append(polygon_coords[0])
# 算法验证
if algorithm not in ["grid", "tin", "prism"]:
return _error_response("算法必须是 grid, tin 或 prism", 400)
# 分辨率验证
if resolution <= 0 or resolution > 100:
return _error_response("分辨率必须在0-100米之间", 400)
# 5. 确保计算器已初始化
app_info_a = init_app(urlA)
if not app_info_a.get('data_source').tileset_path :
return _error_response(f"下载地图失败:{urlA}", 400)
calculator_3d_tiles_a = app_info_a.get("calculator_3d_tiles")
app_info_b = init_app(urlB)
if not app_info_b.get('data_source').tileset_path :
return _error_response(f"下载地图失败:{urlB}", 400)
calculator_3d_tiles_b = app_info_b.get("calculator_3d_tiles")
# 6. 执行计算
algorithm_type = AlgorithmType.GRID
result_a = await calculator_3d_tiles_a.calculate(
polygon_coords=polygon_coords,
design_elevation=design_elevation,
algorithm=algorithm_type,
resolution=resolution,
target_crs=crs,
interpolation_method=interpolation_method
)
result_b = await calculator_3d_tiles_b.calculate(
polygon_coords=polygon_coords,
design_elevation=design_elevation,
algorithm=algorithm_type,
resolution=resolution,
target_crs=crs,
interpolation_method=interpolation_method
)
# 获取网格数据
grids_a = result_a.calculation_details
grids_b = result_b.calculation_details
# 比较网格数据
comparison_result = calculator_3d_tiles_a.compare_grid_cells(grids_a, grids_b)
# 转换为字典
result_dict = comparison_result.to_dict()
# 7. 返回成功响应
return _success_response(result_dict)
except ValueError as e:
logger.warning(f"参数验证失败: {str(e)}")

File diff suppressed because it is too large Load Diff