baoyubo преди 1 седмица
родител
ревизия
5b8a6bcb82
променени са 2 файла, в които са добавени 14 реда и са изтрити 5 реда
  1. 2 1
      routers/api/spatialAnalysis/__init__.py
  2. 12 4
      utils/spatial/__init__.py

+ 2 - 1
routers/api/spatialAnalysis/__init__.py

@@ -44,7 +44,7 @@ async def mine(request: Request,body = Depends(remove_xss_json),db: Session = De
         # town_village_data,town_count,village_count = count_town_village(from_data.location,db)
         # town_village_data,town_count = get_town_list(body)
         print(time.time())
-        town_village_data,town_count,village_count,populationSize,areaSize,GDP = get_town_village_list(body,db) #[],0,0#
+        town_village_data,town_count,village_count,populationSize,areaSize,GDP,event_cn = get_town_village_list(body,db) #[],0,0#
         print(time.time(),town_village_data,town_count,village_count,populationSize,areaSize,GDP)
         # emergency_expert_count = count_emergency_expert(from_data.location,db)
         # emergency_management_count = count_emergency_management(from_data.location,db)
@@ -139,6 +139,7 @@ async def mine(request: Request,body = Depends(remove_xss_json),db: Session = De
                 "populationSize":f'{populationSize/10000:.2f}万人',
                 "areaSize":f'{areaSize:.2f}平方公里',
                 "GDP":f'{GDP:.2f}亿元',
+                "event_cn":event_cn,
                 "list":list_1
 
             }

+ 12 - 4
utils/spatial/__init__.py

@@ -53,7 +53,7 @@ def get_village_list(location_list:list,db,pac=''):
         location = convert_to_polygon(location) #geometry,
         query.append(f"ST_Intersects(geometry,ST_PolygonFromText( '{location}', 4326 ))")
     query=' or '.join(query)
-    sql = text(f"""SELECT DISTINCT `name`,properties,pac,populationSize,GDP FROM (select * from tp_geojson_data_cj_sq  {pac})A WHERE {query} """)
+    sql = text(f"""SELECT DISTINCT `name`,properties,pac,populationSize,GDP,ifnull(event_cn,0)as event_cn FROM (select * from tp_geojson_data_cj_sq cj LEFT JOIN (SELECT cjpac,COUNT(1)as event_cn FROM `event_base` where del_flag<>'2' GROUP BY cjpac) `event_count` on cj.pac=event_count.cjpac and event_count.cjpac is not null  {pac})A WHERE {query} """)
     # print(sql)
     resutl=db.execute(sql).all()
     return resutl
@@ -131,6 +131,7 @@ def get_town_village_list(locations,db):
     populationSize = 0
     areaSize = 0
     GDP = 0
+    event_cn = 0
     for town in intersected_towns:
         # town_count+=1
         town_pac = town.pac
@@ -141,7 +142,8 @@ def get_town_village_list(locations,db):
             "code": town.pac,
             "populationSize": f"{quyu_data['populationSize']}{quyu_data['populationSize_unit']}",
             "areaSize": f"{quyu_data['areaSize']}{quyu_data['areaSize_unit']}",
-            "GDP": f"{quyu_data['GDP']}{quyu_data['GDP_unit']}"  # 假设值,需要从数据中获取
+            "GDP": f"{quyu_data['GDP']}{quyu_data['GDP_unit']}",  # 假设值,需要从数据中获取
+            "event_cn":0
         }
         populationSize += quyu_data['populationSize']
         areaSize += quyu_data['areaSize']
@@ -161,8 +163,14 @@ def get_town_village_list(locations,db):
                 "code": village.pac,
                 "populationSize": f"{quyu_data['populationSize']}{quyu_data['populationSize_unit']}",#village.populationSize,  # 假设值,需要从数据中获取
                 "areaSize": f"{quyu_data['areaSize']}{quyu_data['areaSize_unit']}",#properties['GEO_AREA'],  # 交集区域的面积  0,#
-                "GDP": f"{quyu_data['GDP']}{quyu_data['GDP_unit']}"#village.GDP  # 假设值,需要从数据中获取
+                "GDP": f"{quyu_data['GDP']}{quyu_data['GDP_unit']}" ,#village.GDP  # 假设值,需要从数据中获取
+                "event_cn":village.event_cn,
             }
+            village_event_cn = 0
+            if village.event_cn:
+                village_event_cn=village.event_cn
+            event_cn+=village_event_cn
+            town_data['event_cn']+=village_event_cn
             intersected_villages_names_and_pacs.append(village_data)
         villageCount= len(intersected_villages_names_and_pacs)
         if villageCount>0:
@@ -171,7 +179,7 @@ def get_town_village_list(locations,db):
             village_count += villageCount
         intersected_names_and_pacs.append(town_data)
 
-    return intersected_names_and_pacs, town_count,village_count,populationSize,areaSize,GDP
+    return intersected_names_and_pacs, town_count,village_count,populationSize,areaSize,GDP,event_cn
 # import geopandas as gpd
 # from shapely.geometry import Polygon
 #