feature_schema.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
# coding=utf-8
# author: 4N
# createtime: 2021/8/4
# email: nheweijun@sina.com
from app.modules.data.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,FieldDefn
from app.models import DES
import json
class Api(ApiTemplate):
api_name = "要素info"
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(0,DES.decode(database.sqlalchemy_uri))
layer:Layer = pg_ds.GetLayerByName(table.name)
res["data"] = []
schema = layer.schema
for s in schema:
field :FieldDefn = s
d1 = field.GetName()
d2 = field.GetTypeName()
res["data"].append({"name":field.GetName(),"type":field.GetTypeName(),"pricision":field.GetWidth()})
res["result"] = True
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"}
],
"responses":{
200:{
"schema":{
"properties":{
}
}
}
}
}