|
@@ -9,6 +9,7 @@ from typing import List
|
|
import uuid
|
|
import uuid
|
|
import tempfile
|
|
import tempfile
|
|
import struct
|
|
import struct
|
|
|
|
+from sqlalchemy.sql import text
|
|
|
|
|
|
|
|
|
|
class DecimalEncoder(json.JSONEncoder):
|
|
class DecimalEncoder(json.JSONEncoder):
|
|
@@ -154,18 +155,26 @@ def export_vector_data_batch(db: Session, vector_ids: List[int]):
|
|
return _export_vector_data_to_file(vector_data_list, f"export_batch_{'_'.join(map(str, vector_ids))}")
|
|
return _export_vector_data_to_file(vector_data_list, f"export_batch_{'_'.join(map(str, vector_ids))}")
|
|
|
|
|
|
|
|
|
|
-def export_all_vector_data(db: Session):
|
|
|
|
- """导出整个矢量数据表为GeoJSON格式并保存到文件"""
|
|
|
|
- # 查询所有矢量数据
|
|
|
|
- vector_data_list = db.query(VectorData).all()
|
|
|
|
|
|
+def export_all_vector_data(db: Session, table_name: str = "surveydata"):
|
|
|
|
+ """导出指定的矢量数据表为GeoJSON格式并保存到文件
|
|
|
|
+
|
|
|
|
+ Args:
|
|
|
|
+ db (Session): 数据库会话
|
|
|
|
+ table_name (str): 要导出的矢量数据表名,默认为'surveydata'
|
|
|
|
+
|
|
|
|
+ Returns:
|
|
|
|
+ dict: 包含导出文件路径和临时目录的字典
|
|
|
|
+ """
|
|
|
|
+ # 使用动态表名查询
|
|
|
|
+ query = text(f"SELECT * FROM {table_name}")
|
|
|
|
+ vector_data_list = db.execute(query).fetchall()
|
|
|
|
|
|
# 如果没有数据,抛出异常
|
|
# 如果没有数据,抛出异常
|
|
if not vector_data_list:
|
|
if not vector_data_list:
|
|
- raise HTTPException(status_code=404, detail="数据库中没有矢量数据")
|
|
|
|
|
|
+ raise HTTPException(status_code=404, detail=f"表 {table_name} 中没有矢量数据")
|
|
|
|
|
|
# 调用现有的导出函数
|
|
# 调用现有的导出函数
|
|
- return _export_vector_data_to_file(vector_data_list, "export_all")
|
|
|
|
-
|
|
|
|
|
|
+ return _export_vector_data_to_file(vector_data_list, f"export_{table_name}")
|
|
|
|
|
|
|
|
|
|
def parse_geom_field(geom_value) -> dict:
|
|
def parse_geom_field(geom_value) -> dict:
|
|
@@ -200,7 +209,6 @@ def parse_geom_field(geom_value) -> dict:
|
|
return None
|
|
return None
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
def _export_vector_data_to_file(vector_data_list: List[VectorData], base_filename: str):
|
|
def _export_vector_data_to_file(vector_data_list: List[VectorData], base_filename: str):
|
|
"""将矢量数据列表导出为 GeoJSON 文件"""
|
|
"""将矢量数据列表导出为 GeoJSON 文件"""
|
|
features = []
|
|
features = []
|