gushoubang před 9 měsíci
rodič
revize
fcea9101ee
2 změnil soubory, kde provedl 95 přidání a 90 odebrání
  1. 1 1
      111.py
  2. 94 89
      app.py

+ 1 - 1
111.py

@@ -10,7 +10,7 @@ start_time = time.time()
 # msg = "对少数地区确需使用土地利用总体规划确定的城市建设用地范围外的土地,使用未列入耕地后备资源且尚未确定土地使用权人(或承包经营权人)的国有沙地、裸土地、裸岩石砾地的工业项目用地,在天涯区选取一个面积为100-120亩作为工业用地,要求与永久基本农田不重叠,且位于城镇开发边界内,与生态保护红线、文化保护区、自然保护地、风景名胜区、国有使用权等不重叠,距离小学大于5km,距离高压线超过10km,距离古树10km以外,距离变电站小于20km,工业项目必须依法申请使用土地利用总体规划确定的城市建设用地范围内的国有建设用地。"
 # msg = "我计划在抱坡区选取适宜地块作为工业用地,要求其在城市开发边界内,离小学大于1000m,坡度小于25度,用地面积在80-100亩之间。"
 
-msg = "我要进行选址"
+msg = "p"
 # msg = "我要进行选址,选一块居住用地,离幼儿园200米,离医院300米,离火葬场5000米"
 
 # 生成提示信息

+ 94 - 89
app.py

@@ -190,7 +190,7 @@ def inputMsg():
         print(f"生成过程中出现错误: {e}")
 
     json_res = res["response"]
-    json_res = json.loads(json_res)
+    
 
     # 组织成选址需要的数据格式
     json_res = jsonResToDict(json_res)
@@ -201,95 +201,100 @@ def inputMsg():
 # 将大模型解析的结果转换为选址需要的数据格式
 
 def jsonResToDict(json_res):
-    # 1.查询选址范围信息
-    districtName = json_res["districtName"]
-    ewkt = getAiDistrict(districtName)
-    # 2.保存选址范围信息
-    geomId = saveGeom(ewkt)
-    # 3.获取用地类型信息
-    landType = json_res["landType"]
-    landType = getLandType(landType, "YDYHFLDM")
-    # 4.获取模板信息
-    factorTemplates = getTemplateByCode(landType)
-
-    # TODO 以哪个因子列表为准,模版和因子个数怎么匹配
-
-    now = datetime.datetime.now()
-    formatted_time = now.strftime("%Y%m%d%H%M%S")
-    res = {
-        "xzmj": 1500,
-        "xmmc": "规划选址项目_"+formatted_time,
-        "jsdw": "建设单位",
-        "ydxz_bsm": landType,
-        "ydmjbegin": json_res["area"]["min"],
-        "ydmjend":  json_res["area"]["max"],
-        "geomId": geomId,
-        "yxyz": [],
-        # TODO: 循环遍历
-        # "yxyz": [
-        #     {
-        #         "id": "259e5bbaab434dbfb9c679bd44d4bfa4",
-        #         "name": "幼儿园服务半径",
-        #         "bsm": "TB_YEY",
-        #         "conditionInfo": {
-        #             "spatial_type": "distance",
-        #             "default": "lt",
-        #             "hasValue": true,
-        #             "defaultValue": "300",
-        #             "unit": "米",
-        #             "clip": false
-        #         }
-        #     }
-        # ],
-        # "useMultiple": json_res["useMultiple"],
-        # "useLandType": json_res["useLandType"],
-        # "multipleDistance": json_res["multipleDistance"]
-    }
-    # 循环遍历输入因子
-    factors = json_res["factors"]
-    input_factors = {}
-    for factor in factors:
-        factorInfo = getFactorByName(factor["type"])
-        if factorInfo == None:
-            continue
-        factorId = factorInfo["id"]
-        factorBsm = factorInfo["bsm"]
-        conditionInfo = factorInfo["condition_info"]
-        conditionObj = json.loads(conditionInfo)
-
-        defaultValue ='0'
-        if "value" in factor:
-            defaultValue=str(factor["value"])
-        # if defaultValue == '':
-        #     defaultValue = '0'
-
-        factor_info = {
-            "id": factorId,
-            "name": factor["type"],
-            "bsm": factorBsm,
-            "conditionInfo": {
-                "spatial_type": conditionObj["spatial_type"],
-                "default": factor["condition"],
-                "hasValue": conditionObj["hasValue"],
-                "defaultValue": defaultValue,
-                "unit": conditionObj["unit"],
-                "clip": conditionObj["clip"]
-            }
+    if json_res != str("未找到相关数据"):
+        json_res = json.loads(json_res)
+        # 1.查询选址范围信息
+        districtName = json_res["districtName"]
+        ewkt = getAiDistrict(districtName)
+        # 2.保存选址范围信息
+        geomId = saveGeom(ewkt)
+        # 3.获取用地类型信息
+        landType = json_res["landType"]
+        landType = getLandType(landType, "YDYHFLDM")
+        # 4.获取模板信息
+        factorTemplates = getTemplateByCode(landType)
+
+        # TODO 以哪个因子列表为准,模版和因子个数怎么匹配
+
+        now = datetime.datetime.now()
+        formatted_time = now.strftime("%Y%m%d%H%M%S")
+        res = {
+            "xzmj": 1500,
+            "xmmc": "规划选址项目_"+formatted_time,
+            "jsdw": "建设单位",
+            "ydxz_bsm": landType,
+            "ydmjbegin": json_res["area"]["min"],
+            "ydmjend":  json_res["area"]["max"],
+            "geomId": geomId,
+            "yxyz": [],
+            # TODO: 循环遍历
+            # "yxyz": [
+            #     {
+            #         "id": "259e5bbaab434dbfb9c679bd44d4bfa4",
+            #         "name": "幼儿园服务半径",
+            #         "bsm": "TB_YEY",
+            #         "conditionInfo": {
+            #             "spatial_type": "distance",
+            #             "default": "lt",
+            #             "hasValue": true,
+            #             "defaultValue": "300",
+            #             "unit": "米",
+            #             "clip": false
+            #         }
+            #     }
+            # ],
+            # "useMultiple": json_res["useMultiple"],
+            # "useLandType": json_res["useLandType"],
+            # "multipleDistance": json_res["multipleDistance"]
         }
-        input_factors[factor_info["id"]] = factor_info
-    # 循环遍历模板
-    for factorTemplate in factorTemplates:
-        factorId = factorTemplate["id"]
-        if factorId in input_factors:
-            res["yxyz"].append(input_factors[factorId])
-        else:
-            factorTemplate["conditionInfo"] = json.loads(
-                factorTemplate["conditionInfo"])
-            res["yxyz"].append(factorTemplate)
-    resObj = {}
-    resObj["data"] = res
-    resObj["code"] = 200
-    resObj["type"] = "selectLand"
+        # 循环遍历输入因子
+        factors = json_res["factors"]
+        input_factors = {}
+        for factor in factors:
+            factorInfo = getFactorByName(factor["type"])
+            if factorInfo == None:
+                continue
+            factorId = factorInfo["id"]
+            factorBsm = factorInfo["bsm"]
+            conditionInfo = factorInfo["condition_info"]
+            conditionObj = json.loads(conditionInfo)
+
+            defaultValue ='0'
+            if "value" in factor:
+                defaultValue=str(factor["value"])
+            # if defaultValue == '':
+            #     defaultValue = '0'
+
+            factor_info = {
+                "id": factorId,
+                "name": factor["type"],
+                "bsm": factorBsm,
+                "conditionInfo": {
+                    "spatial_type": conditionObj["spatial_type"],
+                    "default": factor["condition"],
+                    "hasValue": conditionObj["hasValue"],
+                    "defaultValue": defaultValue,
+                    "unit": conditionObj["unit"],
+                    "clip": conditionObj["clip"]
+                }
+            }
+            input_factors[factor_info["id"]] = factor_info
+        # 循环遍历模板
+        for factorTemplate in factorTemplates:
+            factorId = factorTemplate["id"]
+            if factorId in input_factors:
+                res["yxyz"].append(input_factors[factorId])
+            else:
+                factorTemplate["conditionInfo"] = json.loads(
+                    factorTemplate["conditionInfo"])
+                res["yxyz"].append(factorTemplate)
+        resObj = {}
+        resObj["data"] = res
+        resObj["code"] = 200
+        resObj["type"] = "selectLand"
+    else:
+        resObj = {"未找到相关数据"}
+        
     return resObj
 
 # 获取因子信息