Browse Source

250831-1代码。

baoyubo 1 day ago
parent
commit
a5ad802867
1 changed files with 41 additions and 3 deletions
  1. 41 3
      routers/api/spatialAnalysis/point.py

+ 41 - 3
routers/api/spatialAnalysis/point.py

@@ -331,6 +331,44 @@ ST_GeomFromText(
         traceback.print_exc()
         raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e))
 
+@router.post("/get_geojson_new")
+async def get_geojson(
+        body = Depends(remove_xss_json),
+        db:  Session = Depends(get_db)
+):
+    try:
+        # 根据缩放级别动态调整分组粒度
+        pac = body['area_code']
+        if pac[-3:]=='000':
+            pac=pac.replace('000','')
+        table_name = 'tp_geojson_data_zj'
+        option = body['option']
+        if 'cj' == option:
+            # print(1111)
+            table_name = 'tp_geojson_data_cj_sq'
+        sql = f"""SELECT  name,
+       pac,
+       ST_AsGeoJSON(geometry) AS geometry,
+       properties
+FROM {table_name}
+WHERE pac like '{pac}%';"""
+        result = db.execute(sql)
+        features = [
+            {**dict(r), "geometry": json.loads(r.geometry)}
+            for r in result.fetchall()
+        ]
+        # features = result.fetchall()
+        # for info in features:
+        #     info['geometry']= {**dict(info), "geometry": json.loads(info.geometry)}
+        #     pass
+        return {"code": 200,
+                "msg": "操作成功","type":"FeatureCollection",
+                "features": features}
+    except Exception as e:
+        # 处理异常
+        traceback.print_exc()
+        raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e))
+
 # @router.post("/get_map_img")
 # async def get_map_img(
 #     body: Dict[str, Any] = Depends(remove_xss_json),
@@ -458,9 +496,9 @@ async def get_tile(
                 ST_GeomFromText(
                     'POLYGON((
 {ymin} {xmin},
-{ymin} {xmax}, 
-{ymax} {xmax}, 
-{ymax} {xmin}, 
+{ymin} {xmax},
+{ymax} {xmax},
+{ymax} {xmin},
 {ymin} {xmin}))',
                     4326
                 )