Pārlūkot izejas kodu

空间分析优化调整。

baoyubo 8 mēneši atpakaļ
vecāks
revīzija
655da5b8a8
1 mainītis faili ar 14 papildinājumiem un 12 dzēšanām
  1. 14 12
      utils/spatial/__init__.py

+ 14 - 12
utils/spatial/__init__.py

@@ -24,8 +24,8 @@ def convert_to_polygon(points):
 def get_town_list2(location_list:list,db):
     resutl = []
     for location in location_list:
-        location = convert_to_polygon(location)
-        sql = text(f"""SELECT DISTINCT `name`,geometry,properties,pac FROM tp_geojson_data_zj WHERE ST_Intersects(geometry,ST_PolygonFromText( '{location}', 4326 ))""")
+        location = convert_to_polygon(location) #,geometry
+        sql = text(f"""SELECT DISTINCT `name`,properties,pac FROM tp_geojson_data_zj WHERE ST_Intersects(geometry,ST_PolygonFromText( '{location}', 4326 ))""")
         # print(sql)
         resutl+=db.execute(sql).all()
     return resutl
@@ -33,8 +33,8 @@ def get_town_list2(location_list:list,db):
 def get_village_list(location_list:list,db,pac=''):
     resutl = []
     for location in location_list:
-        location = convert_to_polygon(location)
-        sql = text(f"""SELECT DISTINCT `name`,geometry,properties,pac FROM (select * from tp_geojson_data_cj_sq  {pac})A WHERE ST_Intersects(geometry,ST_PolygonFromText( '{location}', 4326 )) """)
+        location = convert_to_polygon(location) #geometry,
+        sql = text(f"""SELECT DISTINCT `name`,properties,pac FROM (select * from tp_geojson_data_cj_sq  {pac})A WHERE ST_Intersects(geometry,ST_PolygonFromText( '{location}', 4326 )) """)
         # print(sql)
         resutl+=db.execute(sql).all()
     return resutl
@@ -104,11 +104,11 @@ def get_town_village_list(locations,db):
 
     # 初始化一个空列表来存储结果
     intersected_names_and_pacs = []
-    town_count = 0
+    town_count = len(intersected_towns)
     village_count = 0
     for town in intersected_towns:
-        town_count+=1
-        town_pac = town.pac[:-3]
+        # town_count+=1
+        town_pac = town.pac
         properties = json.loads(town.properties)
         town_data = {
             "townName": town.name,
@@ -124,19 +124,21 @@ def get_town_village_list(locations,db):
         intersected_villages = get_village_list(locations,db,pac=f""" where pac like '{town_pac}%'""")
         intersected_villages_names_and_pacs = []
         for village in intersected_villages:
-            village_count += 1
-            properties = json.loads(village.properties)
+
+            # properties = json.loads(village.properties)
             village_data = {
                 "villageName": village.name,
                 "code": village.pac,
                 "populationSize": 0,  # 假设值,需要从数据中获取
-                "areaSize": properties['GEO_AREA'],  # 交集区域的面积
+                "areaSize": 0,#properties['GEO_AREA'],  # 交集区域的面积
                 "GDP": 0  # 假设值,需要从数据中获取
             }
             intersected_villages_names_and_pacs.append(village_data)
-        if len(intersected_villages_names_and_pacs)>0:
+        villageCount= len(intersected_villages_names_and_pacs)
+        if villageCount>0:
             town_data['children']=intersected_villages_names_and_pacs
-            town_data['villageCount'] = len(intersected_villages_names_and_pacs)
+            town_data['villageCount'] =villageCount
+            village_count += villageCount
         intersected_names_and_pacs.append(town_data)
 
     return intersected_names_and_pacs, town_count,village_count