xuanzhi_query.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import json
  2. from fastapi import APIRouter, Query
  3. from typing import List, Any
  4. from gistools.geo_analysis import intersect_kfq, intersect_gyyd
  5. from database import Database
  6. router = APIRouter()
  7. database = Database()
  8. @router.get("/kg-query")
  9. async def kg_query(id: str = Query(..., description="ID列表, 逗号分隔")) -> List[Any]:
  10. """
  11. 查询控制性详细规划信息,按照dkcsd,ghfhd,dkgzd,jtblx,cyppd总和倒序排序
  12. """
  13. sql = (
  14. "select id, xzqmc, xzqdm, dymc, yddm, ydxz, ydmj, rjlsx, rjlxx, jzmdsx, jzmdxx, "
  15. "jzgdsx, jzgdxx, ldlsx, ldlxx, pfwh, pfsj, dkcsd, ghfhd, dkgzd, jtblx, cyppd, "
  16. "st_area(shape::geography) as pfmarea, st_astext(shape) as geom, "
  17. "st_astext(st_centroid(shape)) as center_wkt, "
  18. "(COALESCE(dkcsd, 0) + COALESCE(ghfhd, 0) + COALESCE(dkgzd, 0) + "
  19. "COALESCE(jtblx, 0) + COALESCE(cyppd, 0)) as total_score "
  20. "from sde.kzxxxgh where id in ({id}) "
  21. "order by total_score desc"
  22. )
  23. result = await database.execute_query(sql.format(id=id))
  24. return result
  25. @router.get("/klyzy-query")
  26. async def klyzy_query(id: str = Query(..., description="ID列表, 逗号分隔")) -> List[Any]:
  27. """
  28. 查询可利用资源信息,按照dkcsd,ghfhd,dkgzd,jtblx,cyppd总和倒序排序
  29. """
  30. sql = (
  31. "select *, st_astext(shape) as geom, st_astext(st_centroid(shape)) as center_wkt, "
  32. "(COALESCE(dkcsd, 0) + COALESCE(ghfhd, 0) + COALESCE(dkgzd, 0) + "
  33. "COALESCE(jtblx, 0) + COALESCE(cyppd, 0)) as total_score "
  34. "from sde.ecgap_klyzy where id in ({id}) "
  35. "order by total_score desc"
  36. )
  37. result = await database.execute_query(sql.format(id=id))
  38. return result
  39. @router.get("/population")
  40. async def population_query(name: str = Query(..., description="地名")) -> List[Any]:
  41. """
  42. 查询人口信息
  43. """
  44. sql = (
  45. "select pop_age_o as 老年人口, pop_age_m as 中青年人口, pop_sex_m as 男性人口, "
  46. "pop_sex_f as 女性人口, pop as 人口总量 "
  47. "from sde.layer_poi_population where name = '{name}'"
  48. )
  49. result = await database.execute_query(sql.format(name=name))
  50. return result
  51. @router.get("/kfq-intersect")
  52. async def kfq_intersect(wkt: str = Query(..., description="WKT字符串")) -> List[Any]:
  53. """
  54. 查询缓冲区内的开发区信息
  55. """
  56. result = await intersect_kfq(wkt)
  57. return result
  58. @router.get("/gyyd-intersect")
  59. async def gyyd_intersect(wkt: str = Query(..., description="WKT字符串")) -> List[Any]:
  60. """
  61. 查询缓冲区内的工业用地信息
  62. """
  63. result = await intersect_gyyd(wkt)
  64. return result