table_vacuate_delete.py
2.9 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
91
92
93
94
95
# author: 4N
# createtime: 2021/1/27
# email: nheweijun@sina.com
import datetime
import traceback
from app.models import Table, Database, DES,Task,db,TableVacuate
from sqlalchemy.engine import ResultProxy
from app.util.component.ApiTemplate import ApiTemplate
from app.util.component.PGUtil import PGUtil
from app.util.component.EntryDataVacuate import Process
from app.util.component.GeometryAdapter import GeometryAdapter
from app.util.component.StructuredPrint import StructurePrint
import multiprocessing
import uuid
import configure
from osgeo.ogr import DataSource,Layer,Geometry
from osgeo import ogr
from flask import current_app
class Api(ApiTemplate):
api_name = "删除抽稀表"
def process(self):
res = {}
res["data"] = {}
pg_ds = None
sys_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))
sys_ds :DataSource= PGUtil.open_pg_data_source(0,configure.SQLALCHEMY_DATABASE_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:
sys_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 sys_ds:
sys_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": {
}
}
}
}
}