|
@@ -22,21 +22,31 @@ def convert_to_polygon(points):
|
|
|
|
|
|
|
|
|
def get_town_list2(location_list:list,db):
|
|
|
- resutl = []
|
|
|
+ # resutl = []
|
|
|
+ if len(location_list) ==0:
|
|
|
+ return []
|
|
|
+ query = []
|
|
|
for location in location_list:
|
|
|
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()
|
|
|
+ query.append(f"ST_Intersects(geometry,ST_PolygonFromText( '{location}', 4326 ))")
|
|
|
+ query=' or '.join(query)
|
|
|
+ sql = text(f"""SELECT DISTINCT `name`,properties,pac FROM tp_geojson_data_zj WHERE {query}""")
|
|
|
+ # print(sql)
|
|
|
+ resutl=db.execute(sql).all()
|
|
|
return resutl
|
|
|
|
|
|
def get_village_list(location_list:list,db,pac=''):
|
|
|
+ if len(location_list) ==0:
|
|
|
+ return []
|
|
|
resutl = []
|
|
|
+ query = []
|
|
|
for location in location_list:
|
|
|
location = convert_to_polygon(location) #geometry,
|
|
|
- sql = text(f"""SELECT DISTINCT `name`,properties,pac,populationSize,GDP 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()
|
|
|
+ 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} """)
|
|
|
+ # print(sql)
|
|
|
+ resutl=db.execute(sql).all()
|
|
|
return resutl
|
|
|
|
|
|
def get_town_list(locations,):
|
|
@@ -109,6 +119,9 @@ def get_town_village_list(locations,db):
|
|
|
intersected_names_and_pacs = []
|
|
|
town_count = len(intersected_towns)
|
|
|
village_count = 0
|
|
|
+ populationSize = 0
|
|
|
+ areaSize = 0
|
|
|
+ GDP = 0
|
|
|
for town in intersected_towns:
|
|
|
# town_count+=1
|
|
|
town_pac = town.pac
|
|
@@ -121,7 +134,9 @@ def get_town_village_list(locations,db):
|
|
|
"areaSize": f"{quyu_data['areaSize']}{quyu_data['areaSize_unit']}",
|
|
|
"GDP": f"{quyu_data['GDP']}{quyu_data['GDP_unit']}" # 假设值,需要从数据中获取
|
|
|
}
|
|
|
-
|
|
|
+ populationSize += quyu_data['populationSize']
|
|
|
+ areaSize += quyu_data['areaSize']
|
|
|
+ GDP += quyu_data['GDP']
|
|
|
# intersected_villages = db.query(TpCjSqGeoJSONData).filter(
|
|
|
# func.ST_Intersects(TpCjSqGeoJSONData.geometry, multi_polygon) == True
|
|
|
# ).filter(TpCjSqGeoJSONData.pac.like(f'{town_pac}%')).all()
|
|
@@ -147,7 +162,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
|
|
|
+ return intersected_names_and_pacs, town_count,village_count,populationSize,areaSize,GDP
|
|
|
# import geopandas as gpd
|
|
|
# from shapely.geometry import Polygon
|
|
|
#
|