123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- from fastapi import APIRouter, Request, Depends, Query, HTTPException, status
- from common.security import valid_access_token
- from sqlalchemy.orm import Session
- from sqlalchemy.sql import func
- from common.auth_user import *
- from sqlalchemy import text
- from pydantic import BaseModel
- from common.BigDataCenterAPI import *
- from database import get_db
- from typing import List
- from models import *
- from utils import *
- from utils.spatial import *
- import json
- import traceback
- router = APIRouter()
- class location_c(BaseModel):
- x:float
- y:float
- class mine(BaseModel):
- location : List=[]
- @router.post('/get_info')
- async def mine(request: Request,body = Depends(remove_xss_json),db: Session = Depends(get_db)):
- try:
- # 验证必需的字段
- # required_fields = ['location','location_c']
- # missing_fields = [field for field in required_fields if field not in body]
- # if missing_fields:
- # raise HTTPException(status_code=401, detail=f"Missing required fields: {', '.join(missing_fields)}")
- # 行政镇、行政村数据
- # town_village_data,town_count,village_count = count_town_village(from_data.location,db)
- # town_village_data,town_count = get_town_list(body)
- town_village_data,town_count,village_count = get_town_village_list(body,db) #[],0,0#
- # 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": "成功",
- "data": {
- "townData":town_village_data,
- "townCount":town_count,
- "villageCount":village_count,
- # "villageCount":village_count,
- "populationSize":0,
- "areaSize":0,
- "GDP":0,
- "list":[{
- "name":"应急避难场所","num":len(emergency_shelter_list),"list":[{"name":shelter.name,"longitude":shelter.longitude,"latitude":shelter.latitude} for shelter in emergency_shelter_list]
- },{
- "name":"易涝点","num":len(waterlogged_roads_list),"list":[{"name":waterlogged.name,"longitude":waterlogged.longitude,"latitude":waterlogged.latitude} for waterlogged in waterlogged_roads_list]
- },{
- "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
- }
- }
- except Exception as e:
- db.rollback()
- traceback.print_exc()
- raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
- @router.get('/get_mms_area_info')
- async def mine(request: Request,body = Depends(remove_xss_json),db: Session = Depends(get_db)):
- try:
- with open('/home/python3/xh_twapi01/routers/api/spatialAnalysis/茂名市.json','r', encoding='utf-8') as f:
- data = json.load(f)
- features = data['features']
- result = [{'name': '高','color': '#ff2f3c',"points":[]},
- {'name': '较高', 'color': '#ffaf00',"points":[]},
- {'name': '较低', 'color': '#ffd800',"points":[]},
- {'name': '低', 'color': '#40c75f',"points":[]},]
- adcode_dit = {'高':['440902','440983'],"较高":['440904'],"较低":['440981'],"低":['440982']}
- # "440902":{'name': '高','color': '#ff2f3c'},
- # "440904": {'name': '较高', 'color': '#ffaf00'},
- # "440981": {'name': '较低', 'color': '#ffd800'},
- # "440982": {'name': '低', 'color': '#40c75f'},
- # "440983": {'name': '高', 'color': '#ff2f3c'},
- # }
- area_data = {}
- for feature in features:
- properties = feature['properties']
- area_code = properties['adcode']
- geometry = feature['geometry']
- coordinates = geometry['coordinates']
- area_data[str(area_code)]=[]
- for i in coordinates:
- area_data[str(area_code)] += i
- # result.append({"name":adcode_dit[str(area_code)]['name'],
- # "color":adcode_dit[str(area_code)]['color'],
- # "area_name":area_name,
- # "area_code":area_code,
- # "points":i})
- for i in result:
- for x in adcode_dit[i['name']]:
- i['points']+=area_data[x]
- return {
- "code": 200,
- "msg": "成功",
- "data": result}
- except Exception as e:
- traceback.print_exc()
- raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
|