feature_delete.py
2.0 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
# coding=utf-8
# author: 4N
# createtime: 2021/8/4
# email: nheweijun@sina.com
from app.models import Table,Database
from app.util.component.ApiTemplate import ApiTemplate
from app.util.component.GeometryAdapter import GeometryAdapter
from app.util.component.LayerUtil import LayerUtil
from app.util.component.PGUtil import PGUtil
from osgeo.ogr import Geometry,Layer,DataSource,Feature
from app.models import DES
import json
class Api(ApiTemplate):
api_name = "要素删除"
def para_check(self):
pass
def process(self):
res = {}
pg_ds:DataSource = None
try:
table:Table = Table.query.filter_by(guid=self.para.get("guid")).one_or_none()
if not table:
raise Exception("数据不存在!")
if table.table_type == 0:
raise Exception("非空间数据!")
database:Database = table.relate_database
pg_ds:DataSource = PGUtil.open_pg_data_source(1,DES.decode(database.sqlalchemy_uri))
layer:Layer = pg_ds.GetLayerByName(table.name)
fid = int(self.para.get("fid"))
is_success = layer.DeleteFeature(fid)
if is_success == 0:
res["msg"] = "删除成功!"
res["result"] = True
else :
res["msg"] = "要素不存在,删除失败!"
res["result"] = False
except Exception as e:
raise e
finally:
if pg_ds:
pg_ds.Destroy()
return res
api_doc={
"tags":["要素接口"],
"parameters":[
{"name": "guid",
"in": "formData",
"type": "string",
"description": "guid"},
{"name": "fid",
"in": "formData",
"type": "string",
"description": "fid"}
],
"responses":{
200:{
"schema":{
"properties":{
}
}
}
}
}