|
@@ -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
|
|
|
#
|