Przeglądaj źródła

优化空间分析接口

baoyubo 10 miesięcy temu
rodzic
commit
2579ffca31

+ 7 - 5
routers/api/spatialAnalysis/__init__.py

@@ -43,7 +43,9 @@ async def mine(request: Request,body = Depends(remove_xss_json),db: Session = De
         town_village_data,town_count = get_town_list(body)
         # emergency_expert_count = count_emergency_expert(from_data.location,db)
         # emergency_management_count = count_emergency_management(from_data.location,db)
-
+        hospital_list = get_hospital_list(body,db)
+        emergency_shelter_list = get_emergency_shelter_list(body,db)
+        waterlogged_roads_list = get_waterlogged_roads_list(body,db)
         return {
             "code": 200,
             "msg": "成功",
@@ -55,13 +57,13 @@ async def mine(request: Request,body = Depends(remove_xss_json),db: Session = De
                 "areaSize":0,
                 "GDP":0,
                 "list":[{
-                    "name":"应急避难场所","num":0
+                    "name":"应急避难场所","num":len(emergency_shelter_list),"list":[{"name":shelter.name,"longitude":shelter.longitude,"latitude":shelter.latitude} for shelter in emergency_shelter_list]
                 },{
-                    "name":"易涝点","num":0
+                    "name":"易涝点","num":len(waterlogged_roads_list),"list":[{"name":waterlogged.name,"longitude":waterlogged.longitude,"latitude":waterlogged.latitude} for waterlogged in waterlogged_roads_list]
                 },{
-                    "name":"医院","num":1,"list":[{"name":"测试","longitude":111.275362017,"latitude":21.9912508420001}]
+                    "name":"医院","num":len(hospital_list),"list":[{"name":hospital.name,"longitude":hospital.longitude,"latitude":hospital.latitude} for hospital in hospital_list]
                 }
-                ],
+                ]
                 # "emergencyExpertCount":emergency_expert_count,
                 # "emergencyManagementCount":emergency_management_count
             }

+ 34 - 1
utils/spatial/__init__.py

@@ -153,4 +153,37 @@ def count_emergency_management(location_list: list, db):
 
     sql = text(f"""SELECT DISTINCT management_unit FROM `rescue_materia`  WHERE ST_Contains(ST_PolygonFromText( '{location}', 4326 ),ST_PointFromText(CONCAT('POINT(', latitude, ' ', longitude, ')'), 4326))""")
 
-    return len(db.execute(sql).all())
+    return len(db.execute(sql).all())
+
+
+def get_hospital_list(location_list:list,db):
+    resutl = []
+    for location in location_list:
+        location = convert_to_polygon(location)
+        sql = text(f"""SELECT hospital_name as `name`,longitude,latitude,6 AS `dataType` FROM mid_hospital WHERE ST_Contains(ST_PolygonFromText( '{location}', 4326 ),ST_PointFromText(CONCAT('POINT(', latitude, ' ', longitude, ')'), 4326))""")
+
+        resutl+=db.execute(sql).all()
+    return resutl
+
+def get_emergency_shelter_list(location_list:list,db):
+
+    resutl = []
+    for location in location_list:
+        location = convert_to_polygon(location)
+
+        sql = text(f"""SELECT shelter_name as `name`,lng as longitude,lat as latitude,3 AS `dataType` FROM mid_emergency_shelter WHERE ST_Contains(ST_PolygonFromText( '{location}', 4326 ),ST_PointFromText(CONCAT('POINT(', lat, ' ', lng, ')'), 4326))""")
+
+        resutl+=db.execute(sql).all()
+    return resutl
+
+
+def get_waterlogged_roads_list(location_list:list,db):
+
+    resutl = []
+    for location in location_list:
+        location = convert_to_polygon(location)
+
+        sql = text(f"""SELECT flood_name as `name`,lng as longitude,lat as latitude,4 AS `dataType` FROM mid_waterlogged_roads WHERE ST_Contains(ST_PolygonFromText( '{location}', 4326 ),ST_PointFromText(CONCAT('POINT(', lat, ' ', lng, ')'), 4326))""")
+
+        resutl+=db.execute(sql).all()
+    return resutl