table_vacuate_delete.py
2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# author: 4N
# createtime: 2021/1/27
# email: nheweijun@sina.com
from ..models import Table,DES,db,TableVacuate
from app.util.component.ApiTemplate import ApiTemplate
from app.util.component.PGUtil import PGUtil
import configure
from osgeo.ogr import DataSource
from flask import current_app
class Api(ApiTemplate):
api_name = "删除抽稀表"
def process(self):
res = {}
res["data"] = {}
pg_ds = None
va_ds = None
try:
table_guid = self.para.get("guid")
table: Table = Table.query.filter_by(guid=table_guid).one_or_none()
grid = None
if not self.para.get("grid"):
raise Exception("请输入grids参数!")
else:
grid = float(self.para.get("grid"))
if not table:
raise Exception("数据不存在!")
# 判断图层是否存在
pg_ds :DataSource= PGUtil.open_pg_data_source(0,DES.decode(table.relate_database.sqlalchemy_uri))
if configure.VACUATE_DB_URI:
va_ds: DataSource = PGUtil.open_pg_data_source(1, configure.VACUATE_DB_URI)
else:
va_ds: DataSource = PGUtil.open_pg_data_source(1,DES.decode(table.relate_database.sqlalchemy_uri))
layer = pg_ds.GetLayerByName(table.name)
if not layer:
raise Exception("图层不存在!")
#删除数据
tvs = db.session.query(TableVacuate).filter_by(pixel_distance=grid, table_guid=table.guid).all()
if not tvs:
raise Exception("数据不存在!")
for tv in tvs :
db.session.delete(tv)
try:
va_ds.DeleteLayer(tv.name)
except Exception as e :
current_app.logger.warning("抽稀图层不存在!")
db.session.commit()
res["result"] = True
except Exception as e:
raise e
finally:
if pg_ds:
pg_ds.Destroy()
if va_ds:
va_ds.Destroy()
return res
api_doc = {
"tags": ["管理接口"],
"parameters": [
{"name": "guid",
"in": "formData",
"type": "string",
"description": "表guid", "required": "true"},
{"name": "grid",
"in": "formData",
"type": "string",
"description": "网格大小", "required": "true"}
],
"responses": {
200: {
"schema": {
"properties": {
}
}
}
}
}