Browse Source

优化土地数据重新计算逻辑,新增输出文件存在性验证,确保关键输出文件的完整性和错误处理更加完善。

drggboy 1 week ago
parent
commit
00b54c7ec6

+ 0 - 1
Water/Raster/lechang.cpg

@@ -1 +0,0 @@
-UTF-8

BIN
Water/Raster/lechang.dbf


+ 0 - 1
Water/Raster/lechang.prj

@@ -1 +0,0 @@
-GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]

BIN
Water/Raster/lechang.shp


BIN
Water/Raster/lechang.shx


BIN
Water/Raster/lechang.zip


+ 14 - 4
app/api/water.py

@@ -175,14 +175,24 @@ async def recalculate_land_data(
 
         cleaned_csv, shapefile, tif_file, map_output, hist_output, used_coeff = results
         
-        # 检查关键文件是否存在(shapefile可以为None,因为使用的是内存处理
-        if not tif_file or not map_output or not hist_output:
-            logger.error(f"重新计算土地数据失败,关键文件缺失: {land_type}")
-            logger.error(f"GeoTIFF: {tif_file}, 地图: {map_output}, 直方图: {hist_output}")
+        # 检查关键输出文件是否存在(只检查最终输出的地图和直方图
+        if not map_output or not hist_output:
+            logger.error(f"重新计算土地数据失败,关键输出文件缺失: {land_type}")
+            logger.error(f"地图: {map_output}, 直方图: {hist_output}")
             raise HTTPException(
                 status_code=500,
                 detail=f"重新计算土地数据失败: {land_type}"
             )
+        
+        # 验证输出文件实际存在
+        if not os.path.exists(map_output) or not os.path.exists(hist_output):
+            logger.error(f"生成的输出文件不存在: {land_type}")
+            logger.error(f"地图文件存在: {os.path.exists(map_output) if map_output else False}")
+            logger.error(f"直方图文件存在: {os.path.exists(hist_output) if hist_output else False}")
+            raise HTTPException(
+                status_code=500,
+                detail=f"生成的输出文件不存在: {land_type}"
+            )
 
         # 定义默认路径
         default_map_path = os.path.join(raster_dir, f"{land_type}_Cd含量地图.jpg")