image_register.py
3.1 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
96
97
98
99
100
101
102
103
104
105
106
107
108
# coding=utf-8
#author: 4N
#createtime: 2021/7/19
#email: nheweijun@sina.com
from osgeo.ogr import *
from osgeo import gdal,ogr,osr
from osgeo.gdal import Dataset,Band
from app.util.component.ApiTemplate import ApiTemplate
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
import numpy
import cv2
import json
from .models import Image
from app.modules.image.ImageDataService import ImageDataService
from app.models import db
import uuid
import os
class Api(ApiTemplate):
api_name = "注册影像数据"
def process(self):
# 返回结果
res = {}
try:
data_server = self.para.get("data_server")
path = self.para.get("path")
host = data_server.split(":")[0]
port = int(data_server.split(":")[1])
if host.__eq__("localhost"):
pass
else:
transport = TSocket.TSocket(host, port)
transport = TTransport.TBufferedTransport(transport)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = ImageDataService.Client(protocol)
transport.open()
info= json.loads(client.getInfo(path))
# 影像空间范围
if not info["origin_extent"]:
if not self.para.get("extent"):
res["result"] = False
res["msg"] = "数据解析范围失败,请手动输入范围"
return res
else :
origin_extent=json.loads(self.para.get("extent"))
else:
origin_extent = info["origin_extent"]
transport.close()
guid = uuid.uuid1().__str__()
image = Image(guid= guid,
overview=info["overview_count"],
raster_x_size=info["xy_size"][0],
raster_y_size=info["xy_size"][1],
name=os.path.basename(path),
alias=self.para.get("alias"),
extent=origin_extent,
null_value=info["null_value"]
)
db.session.add(image)
db.session.commit()
res["data"] = guid
res["result"] = True
except Exception as e:
raise e
return res
api_doc = {
"tags": ["影像接口"],
"parameters": [
{"name": "data_server",
"in": "formData",
"type": "string",
"description": "data_server"},
{"name": "path",
"in": "formData",
"type": "string",
"description": "path"}
],
"responses": {
200: {
"schema": {
"properties": {
}
}
}
}
}