提交 6bb1b3725ae3f91bf5f192c8de23150563269cd8

作者 nheweijun
1 个父辈 9d1053c1

服务整合初步版本

正在显示 69 个修改的文件 包含 3199 行增加305 行删除
@@ -44,6 +44,9 @@ def create_app(): @@ -44,6 +44,9 @@ def create_app():
44 :return:app,flask实例 44 :return:app,flask实例
45 """ 45 """
46 46
  47 + # 上下文全局变量字典
  48 + global GLOBAL_DIC
  49 +
47 # app基本设置 50 # app基本设置
48 app = Flask(__name__) 51 app = Flask(__name__)
49 app.config['SQLALCHEMY_DATABASE_URI'] = configure.SQLALCHEMY_DATABASE_URI 52 app.config['SQLALCHEMY_DATABASE_URI'] = configure.SQLALCHEMY_DATABASE_URI
@@ -96,15 +99,14 @@ def create_app(): @@ -96,15 +99,14 @@ def create_app():
96 # 入库监测线程 99 # 入库监测线程
97 @app.before_first_request 100 @app.before_first_request
98 def data_entry_process(): 101 def data_entry_process():
99 - StructurePrint.print("start listen") 102 + StructurePrint().print("start listen")
100 process = threading.Thread(target=data_entry_center) 103 process = threading.Thread(target=data_entry_center)
101 process.start() 104 process.start()
102 105
103 # 不检测https 106 # 不检测https
104 os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1' 107 os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'
105 108
106 - # 上下文全局变量字典  
107 - global GLOBAL_DIC 109 +
108 110
109 return app 111 return app
110 112
@@ -11,7 +11,7 @@ import datetime @@ -11,7 +11,7 @@ import datetime
11 11
12 from app.util.component.PGUtil import PGUtil 12 from app.util.component.PGUtil import PGUtil
13 import glob 13 import glob
14 - 14 +import traceback
15 class DES(): 15 class DES():
16 ''' 16 '''
17 DES密码加解密 17 DES密码加解密
@@ -33,21 +33,6 @@ class DES(): @@ -33,21 +33,6 @@ class DES():
33 33
34 db = SQLAlchemy() 34 db = SQLAlchemy()
35 35
36 -# 动态加载Model  
37 -current_dir = os.path.abspath(os.path.dirname(__file__))  
38 -pkgs = list(glob.glob('%s/modules/*/models' % (current_dir)))  
39 -pkgs.extend(list(glob.glob('%s/modules/*/*/models' % (current_dir))))  
40 -  
41 -for pkg in pkgs :  
42 - pkg = os.path.normpath(pkg)  
43 - node_list = pkg.split(os.path.sep)  
44 - pkg_name = ".".join(node_list[node_list.index("app"):])  
45 - try:  
46 - __import__(pkg_name)  
47 - except:  
48 - pass  
49 -  
50 -  
51 36
52 class Table(db.Model): 37 class Table(db.Model):
53 ''' 38 '''
@@ -268,4 +253,21 @@ class TileScheme(db.Model): @@ -268,4 +253,21 @@ class TileScheme(db.Model):
268 dpi = Column(Integer) 253 dpi = Column(Integer)
269 rows = Column(Integer) 254 rows = Column(Integer)
270 cols = Column(Integer) 255 cols = Column(Integer)
271 - update_time = Column(DateTime)  
  256 + update_time = Column(DateTime)
  257 +
  258 + parameter = Column(Text)
  259 +
  260 +# 动态加载Model
  261 +current_dir = os.path.abspath(os.path.dirname(__file__))
  262 +pkgs = list(glob.glob('%s/modules/*/models' % (current_dir)))
  263 +pkgs.extend(list(glob.glob('%s/modules/*/*/models' % (current_dir))))
  264 +
  265 +for pkg in pkgs :
  266 + pkg = os.path.normpath(pkg)
  267 + node_list = pkg.split(os.path.sep)
  268 + pkg_name = ".".join(node_list[node_list.index("app"):])
  269 + try:
  270 + __import__(pkg_name)
  271 + except Exception as e:
  272 + print(traceback.format_exc())
  273 + pass
@@ -121,7 +121,7 @@ class Api(ApiTemplate): @@ -121,7 +121,7 @@ class Api(ApiTemplate):
121 121
122 # 没有权限的表跳过 122 # 没有权限的表跳过
123 if not PGUtil.check_table_privilege(l_name,"SELECT",db_tuple[0],pg_ds): 123 if not PGUtil.check_table_privilege(l_name,"SELECT",db_tuple[0],pg_ds):
124 - StructurePrint.print("用户{}对表{}没有select权限!".format(db_tuple[0],l_name),"warn") 124 + StructurePrint().print("用户{}对表{}没有select权限!".format(db_tuple[0],l_name),"warn")
125 continue 125 continue
126 126
127 # 范围统计和数量统计以100w为界限 127 # 范围统计和数量统计以100w为界限
@@ -174,7 +174,7 @@ class Api(ApiTemplate): @@ -174,7 +174,7 @@ class Api(ApiTemplate):
174 174
175 spatial_table_name.append(layer.GetName()) 175 spatial_table_name.append(layer.GetName())
176 except: 176 except:
177 - StructurePrint.print("表{}注册失败!".format(l_name), "warn") 177 + StructurePrint().print("表{}注册失败!".format(l_name), "warn")
178 continue 178 continue
179 return spatial_table_name,tables 179 return spatial_table_name,tables
180 180
@@ -193,7 +193,7 @@ class Api(ApiTemplate): @@ -193,7 +193,7 @@ class Api(ApiTemplate):
193 193
194 # 没有权限的表跳过 194 # 没有权限的表跳过
195 if not SQLUtil.check_table_privilege(table_name, "SELECT", db_tuple[0], db_session): 195 if not SQLUtil.check_table_privilege(table_name, "SELECT", db_tuple[0], db_session):
196 - StructurePrint.print("用户{}对表{}没有select权限!".format(db_tuple[0],table_name), "warn") 196 + StructurePrint().print("用户{}对表{}没有select权限!".format(db_tuple[0],table_name), "warn")
197 continue 197 continue
198 198
199 table_guid = uuid.uuid1().__str__() 199 table_guid = uuid.uuid1().__str__()
@@ -248,7 +248,7 @@ class Api(ApiTemplate): @@ -248,7 +248,7 @@ class Api(ApiTemplate):
248 248
249 # 没有权限的表跳过 249 # 没有权限的表跳过
250 # if not PGUtil.check_table_privilege(l_name, "SELECT", db_tuple[0], pg_ds): 250 # if not PGUtil.check_table_privilege(l_name, "SELECT", db_tuple[0], pg_ds):
251 - # StructurePrint.print("用户{}对表{}没有select权限!".format(db_tuple[0], l_name), "warn") 251 + # StructurePrint().print("用户{}对表{}没有select权限!".format(db_tuple[0], l_name), "warn")
252 # continue 252 # continue
253 253
254 base_layer_name=l_name.split("_vacuate_")[1] 254 base_layer_name=l_name.split("_vacuate_")[1]
@@ -43,7 +43,7 @@ def data_entry_center(): @@ -43,7 +43,7 @@ def data_entry_center():
43 for process in remove_process: 43 for process in remove_process:
44 running_dict.pop(process) 44 running_dict.pop(process)
45 45
46 - # StructurePrint.print("listening...") 46 + # StructurePrint().print("listening...")
47 47
48 # 入库进程少于阈值,开启入库进程 48 # 入库进程少于阈值,开启入库进程
49 49
@@ -58,7 +58,7 @@ def data_entry_center(): @@ -58,7 +58,7 @@ def data_entry_center():
58 58
59 try: 59 try:
60 parameter = json.loads(ready_task.parameter) 60 parameter = json.loads(ready_task.parameter)
61 - StructurePrint.print("检测到入库任务") 61 + StructurePrint().print("检测到入库任务")
62 ready_task.state = 2 62 ready_task.state = 2
63 ready_task.process = "入库中" 63 ready_task.process = "入库中"
64 sys_session.commit() 64 sys_session.commit()
@@ -104,10 +104,10 @@ def data_entry_center(): @@ -104,10 +104,10 @@ def data_entry_center():
104 sys_session.query(Task).filter_by(guid=ready_task.guid).update( 104 sys_session.query(Task).filter_by(guid=ready_task.guid).update(
105 {"state": -1, "process": "入库失败"}) 105 {"state": -1, "process": "入库失败"})
106 sys_session.commit() 106 sys_session.commit()
107 - StructurePrint.print(e.__str__(), "error") 107 + StructurePrint().print(e.__str__(), "error")
108 else: 108 else:
109 # 解表啊 109 # 解表啊
110 sys_session.commit() 110 sys_session.commit()
111 except Exception as e: 111 except Exception as e:
112 sys_session.commit() 112 sys_session.commit()
113 - StructurePrint.print(e.__str__(), "error")  
  113 + StructurePrint().print(e.__str__(), "error")
@@ -199,7 +199,7 @@ class Api(ApiTemplate): @@ -199,7 +199,7 @@ class Api(ApiTemplate):
199 199
200 # 没有权限的表跳过 200 # 没有权限的表跳过
201 if not PGUtil.check_table_privilege(l_name, "SELECT", db_tuple[0], pg_ds): 201 if not PGUtil.check_table_privilege(l_name, "SELECT", db_tuple[0], pg_ds):
202 - StructurePrint.print("用户{}对表{}没有select权限!".format(db_tuple[0], l_name), "warn") 202 + StructurePrint().print("用户{}对表{}没有select权限!".format(db_tuple[0], l_name), "warn")
203 continue 203 continue
204 204
205 205
@@ -224,11 +224,11 @@ class Api(ApiTemplate): @@ -224,11 +224,11 @@ class Api(ApiTemplate):
224 ext = [round(e, 2) for e in ext] 224 ext = [round(e, 2) for e in ext]
225 extent = "{},{},{},{}".format(ext[0], ext[1], ext[2], ext[3]) 225 extent = "{},{},{},{}".format(ext[0], ext[1], ext[2], ext[3])
226 226
227 - StructurePrint.print("空间表增加!") 227 + StructurePrint().print("空间表增加!")
228 228
229 geom_type = GeometryAdapter.get_geometry_type(layer) 229 geom_type = GeometryAdapter.get_geometry_type(layer)
230 except: 230 except:
231 - StructurePrint.print("表{}注册失败!".format(l_name), "warn") 231 + StructurePrint().print("表{}注册失败!".format(l_name), "warn")
232 continue 232 continue
233 233
234 table_guid = uuid.uuid1().__str__() 234 table_guid = uuid.uuid1().__str__()
@@ -304,7 +304,7 @@ class Api(ApiTemplate): @@ -304,7 +304,7 @@ class Api(ApiTemplate):
304 304
305 # 删除表 305 # 删除表
306 if table.name not in db_tables_names: 306 if table.name not in db_tables_names:
307 - StructurePrint.print("空间表减少!") 307 + StructurePrint().print("空间表减少!")
308 sys_session.delete(table) 308 sys_session.delete(table)
309 # 修改表 309 # 修改表
310 else: 310 else:
@@ -320,7 +320,7 @@ class Api(ApiTemplate): @@ -320,7 +320,7 @@ class Api(ApiTemplate):
320 320
321 # 没有权限的表跳过 321 # 没有权限的表跳过
322 if not PGUtil.check_table_privilege(l_name, "SELECT", db_tuple[0], pg_ds): 322 if not PGUtil.check_table_privilege(l_name, "SELECT", db_tuple[0], pg_ds):
323 - StructurePrint.print("用户{}对表{}没有select权限!".format(db_tuple[0], l_name), "warn") 323 + StructurePrint().print("用户{}对表{}没有select权限!".format(db_tuple[0], l_name), "warn")
324 sys_session.delete(table) 324 sys_session.delete(table)
325 continue 325 continue
326 326
@@ -336,7 +336,7 @@ class Api(ApiTemplate): @@ -336,7 +336,7 @@ class Api(ApiTemplate):
336 db_columns_names.append(field_name) 336 db_columns_names.append(field_name)
337 337
338 if field_name not in columns_names: 338 if field_name not in columns_names:
339 - StructurePrint.print("{}空间表属性增加!".format(table.name)) 339 + StructurePrint().print("{}空间表属性增加!".format(table.name))
340 field_alias = field_name if field_defn.GetAlternativeName() is None or field_defn.GetAlternativeName().__eq__( 340 field_alias = field_name if field_defn.GetAlternativeName() is None or field_defn.GetAlternativeName().__eq__(
341 "") else field_defn.GetAlternativeName() 341 "") else field_defn.GetAlternativeName()
342 column = Columns(guid=uuid.uuid1().__str__(), table_guid=table.guid, 342 column = Columns(guid=uuid.uuid1().__str__(), table_guid=table.guid,
@@ -347,7 +347,7 @@ class Api(ApiTemplate): @@ -347,7 +347,7 @@ class Api(ApiTemplate):
347 # 删除列 347 # 删除列
348 for column in columns: 348 for column in columns:
349 if column.name not in db_columns_names: 349 if column.name not in db_columns_names:
350 - StructurePrint.print("{}空间表属性减少!".format(table.name)) 350 + StructurePrint().print("{}空间表属性减少!".format(table.name))
351 sys_session.delete(column) 351 sys_session.delete(column)
352 352
353 # 范围统计和数量统计以100w为界限 353 # 范围统计和数量统计以100w为界限
@@ -373,7 +373,7 @@ class Api(ApiTemplate): @@ -373,7 +373,7 @@ class Api(ApiTemplate):
373 373
374 # 修改要素量 374 # 修改要素量
375 if not table.feature_count.__eq__(feature_count): 375 if not table.feature_count.__eq__(feature_count):
376 - StructurePrint.print("{}空间表要素!".format(table.name)) 376 + StructurePrint().print("{}空间表要素!".format(table.name))
377 sys_session.query(Table).filter_by(guid=table.guid).update({"feature_count": feature_count, 377 sys_session.query(Table).filter_by(guid=table.guid).update({"feature_count": feature_count,
378 "extent": extent}) 378 "extent": extent})
379 379
@@ -381,13 +381,13 @@ class Api(ApiTemplate): @@ -381,13 +381,13 @@ class Api(ApiTemplate):
381 def add_common_table(self,data_session,sys_session,database_guid,real_common_tables_name,origin_common_tables_name,this_time,db_tuple): 381 def add_common_table(self,data_session,sys_session,database_guid,real_common_tables_name,origin_common_tables_name,this_time,db_tuple):
382 for table_name in real_common_tables_name: 382 for table_name in real_common_tables_name:
383 if table_name not in origin_common_tables_name: 383 if table_name not in origin_common_tables_name:
384 - StructurePrint.print("{}非空间表增加!".format(table_name)) 384 + StructurePrint().print("{}非空间表增加!".format(table_name))
385 table_guid = uuid.uuid1().__str__() 385 table_guid = uuid.uuid1().__str__()
386 386
387 387
388 # 没有权限的表跳过 388 # 没有权限的表跳过
389 if not SQLUtil.check_table_privilege(table_name, "SELECT", db_tuple[0], data_session): 389 if not SQLUtil.check_table_privilege(table_name, "SELECT", db_tuple[0], data_session):
390 - StructurePrint.print("用户{}对表{}没有select权限!".format(db_tuple[0], table_name), "warn") 390 + StructurePrint().print("用户{}对表{}没有select权限!".format(db_tuple[0], table_name), "warn")
391 continue 391 continue
392 392
393 count = data_session.execute('select count(*) from "{}"'.format(table_name)).fetchone()[0] 393 count = data_session.execute('select count(*) from "{}"'.format(table_name)).fetchone()[0]
@@ -435,14 +435,14 @@ class Api(ApiTemplate): @@ -435,14 +435,14 @@ class Api(ApiTemplate):
435 tables = sys_session.query(Table).filter_by(name=table_name).filter_by(database_guid=database_guid).all() 435 tables = sys_session.query(Table).filter_by(name=table_name).filter_by(database_guid=database_guid).all()
436 for table in tables: 436 for table in tables:
437 if table_name not in real_common_tables_name: 437 if table_name not in real_common_tables_name:
438 - StructurePrint.print("{}非空间表减少!".format(table_name)) 438 + StructurePrint().print("{}非空间表减少!".format(table_name))
439 sys_session.delete(table) 439 sys_session.delete(table)
440 # 修改表 440 # 修改表
441 else: 441 else:
442 442
443 # 没有权限的表删除 443 # 没有权限的表删除
444 if not SQLUtil.check_table_privilege(table_name, "SELECT", db_tuple[0], data_session): 444 if not SQLUtil.check_table_privilege(table_name, "SELECT", db_tuple[0], data_session):
445 - StructurePrint.print("用户{}对表{}没有select权限!".format(db_tuple[0], table_name), "warn") 445 + StructurePrint().print("用户{}对表{}没有select权限!".format(db_tuple[0], table_name), "warn")
446 sys_session.delete(table) 446 sys_session.delete(table)
447 continue 447 continue
448 448
@@ -471,7 +471,7 @@ class Api(ApiTemplate): @@ -471,7 +471,7 @@ class Api(ApiTemplate):
471 # 属性增加 471 # 属性增加
472 for col in real_cols_name: 472 for col in real_cols_name:
473 if col not in columns_names: 473 if col not in columns_names:
474 - StructurePrint.print("{}表要素属性增加!".format(table_name)) 474 + StructurePrint().print("{}表要素属性增加!".format(table_name))
475 column = Columns(guid=uuid.uuid1().__str__(), table_guid=table.guid, 475 column = Columns(guid=uuid.uuid1().__str__(), table_guid=table.guid,
476 name=col, create_time=this_time, update_time=this_time) 476 name=col, create_time=this_time, update_time=this_time)
477 sys_session.add(column) 477 sys_session.add(column)
@@ -479,7 +479,7 @@ class Api(ApiTemplate): @@ -479,7 +479,7 @@ class Api(ApiTemplate):
479 # 属性减少 479 # 属性减少
480 for column in columns: 480 for column in columns:
481 if column.name not in real_cols_name: 481 if column.name not in real_cols_name:
482 - StructurePrint.print("{}表要素属性减少!".format(table_name)) 482 + StructurePrint().print("{}表要素属性减少!".format(table_name))
483 sys_session.delete(column) 483 sys_session.delete(column)
484 484
485 # 修改要素量 485 # 修改要素量
@@ -489,7 +489,7 @@ class Api(ApiTemplate): @@ -489,7 +489,7 @@ class Api(ApiTemplate):
489 count = SQLUtil.get_table_count(table_name,data_session) 489 count = SQLUtil.get_table_count(table_name,data_session)
490 490
491 if not table.feature_count.__eq__(count): 491 if not table.feature_count.__eq__(count):
492 - StructurePrint.print("{}表要素变化!".format(table_name)) 492 + StructurePrint().print("{}表要素变化!".format(table_name))
493 sys_session.query(Table).filter_by(guid=table.guid).update({"feature_count": count}) 493 sys_session.query(Table).filter_by(guid=table.guid).update({"feature_count": count})
494 494
495 495
@@ -126,7 +126,7 @@ class Api(ApiTemplate): @@ -126,7 +126,7 @@ class Api(ApiTemplate):
126 # try: 126 # try:
127 # pg_ds.DeleteLayer(tv.name) 127 # pg_ds.DeleteLayer(tv.name)
128 # except Exception as e : 128 # except Exception as e :
129 - # StructurePrint.print("抽稀图层不存在!","warn") 129 + # StructurePrint().print("抽稀图层不存在!","warn")
130 130
131 # 创建抽稀过程 131 # 创建抽稀过程
132 options = ["OVERWRITE=yes", "GEOMETRY_NAME={}".format(PGUtil.get_geo_column(table.name,pg_session)), 132 options = ["OVERWRITE=yes", "GEOMETRY_NAME={}".format(PGUtil.get_geo_column(table.name,pg_session)),
@@ -257,7 +257,7 @@ class VacuateProcess: @@ -257,7 +257,7 @@ class VacuateProcess:
257 p_x = (extent[1]-extent[0])/10.0 257 p_x = (extent[1]-extent[0])/10.0
258 p_y = (extent[3] - extent[2]) / 10.0 258 p_y = (extent[3] - extent[2]) / 10.0
259 fill_precent=0 259 fill_precent=0
260 - StructurePrint.print("判断疏密") 260 + StructurePrint().print("判断疏密")
261 for ix in range(10): 261 for ix in range(10):
262 for iy in range(10): 262 for iy in range(10):
263 grid_extent = [extent[0]+ix*p_x,extent[0]+ix*p_x+p_x,extent[2]+iy*p_y,extent[2]+iy*p_y+p_y] 263 grid_extent = [extent[0]+ix*p_x,extent[0]+ix*p_x+p_x,extent[2]+iy*p_y,extent[2]+iy*p_y+p_y]
@@ -270,7 +270,7 @@ class VacuateProcess: @@ -270,7 +270,7 @@ class VacuateProcess:
270 fill_precent += 1 270 fill_precent += 1
271 271
272 print(fill_precent) 272 print(fill_precent)
273 - StructurePrint.print("判断疏密结束") 273 + StructurePrint().print("判断疏密结束")
274 274
275 layer.SetSpatialFilter(None) 275 layer.SetSpatialFilter(None)
276 layer.ResetReading() 276 layer.ResetReading()
@@ -66,7 +66,7 @@ class Api(ApiTemplate): @@ -66,7 +66,7 @@ class Api(ApiTemplate):
66 p_x = (extent[1] - extent[0]) / 10.0 66 p_x = (extent[1] - extent[0]) / 10.0
67 p_y = (extent[3] - extent[2]) / 10.0 67 p_y = (extent[3] - extent[2]) / 10.0
68 fill_precent = 0 68 fill_precent = 0
69 - StructurePrint.print("判断疏密") 69 + StructurePrint().print("判断疏密")
70 for ix in range(10): 70 for ix in range(10):
71 for iy in range(10): 71 for iy in range(10):
72 grid_extent = [extent[0] + ix * p_x, extent[0] + ix * p_x + p_x, extent[2] + iy * p_y, 72 grid_extent = [extent[0] + ix * p_x, extent[0] + ix * p_x + p_x, extent[2] + iy * p_y,
@@ -80,7 +80,7 @@ class Api(ApiTemplate): @@ -80,7 +80,7 @@ class Api(ApiTemplate):
80 fill_precent += 1 80 fill_precent += 1
81 81
82 print(fill_precent) 82 print(fill_precent)
83 - StructurePrint.print("判断疏密结束") 83 + StructurePrint().print("判断疏密结束")
84 84
85 layer.SetSpatialFilter(None) 85 layer.SetSpatialFilter(None)
86 layer.ResetReading() 86 layer.ResetReading()
@@ -8,6 +8,7 @@ from flask import current_app as app @@ -8,6 +8,7 @@ from flask import current_app as app
8 import socket 8 import socket
9 import configure 9 import configure
10 10
  11 +
11 from app.util.component.ApiTemplate import ApiTemplate 12 from app.util.component.ApiTemplate import ApiTemplate
12 class Api(ApiTemplate): 13 class Api(ApiTemplate):
13 14
@@ -6,10 +6,13 @@ import hashlib @@ -6,10 +6,13 @@ import hashlib
6 from flask import current_app as app 6 from flask import current_app as app
7 import socket 7 import socket
8 8
  9 +
9 from app.util.component.ApiTemplate import ApiTemplate 10 from app.util.component.ApiTemplate import ApiTemplate
  11 +from app.util.component.StructuredPrint import StructurePrint
10 class Api(ApiTemplate): 12 class Api(ApiTemplate):
11 13
12 def process(self): 14 def process(self):
  15 + StructurePrint().print("test")
13 return {"Name":socket.gethostname(),"Type":"DMapDMS"} 16 return {"Name":socket.gethostname(),"Type":"DMapDMS"}
14 17
15 api_doc={ 18 api_doc={
@@ -10,12 +10,6 @@ from . import service_register @@ -10,12 +10,6 @@ from . import service_register
10 from . import service_type 10 from . import service_type
11 from . import service_list 11 from . import service_list
12 from . import service_delete 12 from . import service_delete
13 -from . import catalog_create  
14 -from . import catalog_delete  
15 -from . import catalog_edit  
16 -from . import catalog_tree  
17 -from . import catalog_next  
18 -from . import catalog_real_tree  
19 import os 13 import os
20 from flask import send_from_directory 14 from flask import send_from_directory
21 15
@@ -61,69 +55,6 @@ class DataManager(BlueprintApi): @@ -61,69 +55,6 @@ class DataManager(BlueprintApi):
61 """ 55 """
62 return service_delete.Api().result 56 return service_delete.Api().result
63 57
64 - @staticmethod  
65 - @bp.route('/CatalogCreate', methods=['POST'])  
66 - @swag_from(catalog_create.Api.api_doc)  
67 - def api_catalog_create():  
68 - """  
69 - 创建服务目录  
70 - """  
71 - return catalog_create.Api().result  
72 -  
73 - @staticmethod  
74 - @bp.route('/CatalogDelete', methods=['POST'])  
75 - @swag_from(catalog_delete.Api.api_doc)  
76 - def api_catalog_delete():  
77 - """  
78 - 删除服务目录  
79 - """  
80 - return catalog_delete.Api().result  
81 -  
82 - @staticmethod  
83 - @bp.route('/CatalogEdit', methods=['POST'])  
84 - @swag_from(catalog_edit.Api.api_doc)  
85 - def api_catalog_edit():  
86 - """  
87 - 修改服务目录  
88 - """  
89 - return catalog_edit.Api().result  
90 -  
91 - @staticmethod  
92 - @bp.route('/CatalogEdit', methods=['POST'])  
93 - @swag_from(catalog_edit.Api.api_doc)  
94 - def api_catalog_edit():  
95 - """  
96 - 修改服务目录  
97 - """  
98 - return catalog_edit.Api().result  
99 -  
100 - @staticmethod  
101 - @bp.route('/CatalogNext', methods=['POST'])  
102 - @swag_from(catalog_next.Api.api_doc)  
103 - def api_catalog_next():  
104 - """  
105 - 下一级服务目录  
106 - """  
107 - return catalog_next.Api().result  
108 -  
109 - @staticmethod  
110 - @bp.route('/CatalogTree', methods=['POST'])  
111 - @swag_from(catalog_tree.Api.api_doc)  
112 - def api_catalog_tree():  
113 - """  
114 - 服务目录树  
115 - """  
116 - return catalog_tree.Api().result  
117 -  
118 - @staticmethod  
119 - @bp.route('/CatalogRealTree', methods=['POST'])  
120 - @swag_from(catalog_real_tree.Api.api_doc)  
121 - def api_catalog_real_tree():  
122 - """  
123 - 服务目录树  
124 - """  
125 - return catalog_real_tree.Api().result  
126 -  
127 58
128 @staticmethod 59 @staticmethod
129 @bp.route('/Overview/<file>', methods=['GET']) 60 @bp.route('/Overview/<file>', methods=['GET'])
  1 +# coding=utf-8
  2 +#author: 4N
  3 +#createtime: 2021/9/22
  4 +#email: nheweijun@sina.com
  5 +
  6 +
  7 +
  8 +# coding=utf-8
  9 +#author: 4N
  10 +#createtime: 2021/9/14
  11 +#email: nheweijun@sina.com
  12 +
  13 +from flasgger import swag_from
  14 +from flask import Blueprint
  15 +from app.util import BlueprintApi
  16 +from . import catalog_edit, catalog_tree, catalog_delete, catalog_create, catalog_next,catalog_real_tree
  17 +
  18 +
  19 +class DataManager(BlueprintApi):
  20 +
  21 + bp = Blueprint("ServiceCatalog", __name__, url_prefix="/API/Service/Catalog")
  22 +
  23 +
  24 + @staticmethod
  25 + @bp.route('/Create', methods=['POST'])
  26 + @swag_from(catalog_create.Api.api_doc)
  27 + def api_catalog_create():
  28 + """
  29 + 创建服务目录
  30 + """
  31 + return catalog_create.Api().result
  32 +
  33 + @staticmethod
  34 + @bp.route('/Delete', methods=['POST'])
  35 + @swag_from(catalog_delete.Api.api_doc)
  36 + def api_catalog_delete():
  37 + """
  38 + 删除服务目录
  39 + """
  40 + return catalog_delete.Api().result
  41 +
  42 + @staticmethod
  43 + @bp.route('/Edit', methods=['POST'])
  44 + @swag_from(catalog_edit.Api.api_doc)
  45 + def api_catalog_edit():
  46 + """
  47 + 修改服务目录
  48 + """
  49 + return catalog_edit.Api().result
  50 +
  51 +
  52 + @staticmethod
  53 + @bp.route('/Next', methods=['POST'])
  54 + @swag_from(catalog_next.Api.api_doc)
  55 + def api_catalog_next():
  56 + """
  57 + 下一级服务目录
  58 + """
  59 + return catalog_next.Api().result
  60 +
  61 + @staticmethod
  62 + @bp.route('/Tree', methods=['POST'])
  63 + @swag_from(catalog_tree.Api.api_doc)
  64 + def api_catalog_tree():
  65 + """
  66 + 服务目录树
  67 + """
  68 + return catalog_tree.Api().result
  69 +
  70 + @staticmethod
  71 + @bp.route('/RealTree', methods=['POST'])
  72 + @swag_from(catalog_real_tree.Api.api_doc)
  73 + def api_catalog_real_tree():
  74 + """
  75 + 服务目录树
  76 + """
  77 + return catalog_real_tree.Api().result
  78 +
@@ -61,7 +61,7 @@ class Api(ApiTemplate): @@ -61,7 +61,7 @@ class Api(ApiTemplate):
61 61
62 api_doc={ 62 api_doc={
63 63
64 - "tags":["服务接口"], 64 + "tags":["服务目录接口"],
65 "parameters":[ 65 "parameters":[
66 {"name": "name", 66 {"name": "name",
67 "in": "formData", 67 "in": "formData",
@@ -48,7 +48,7 @@ class Api(ApiTemplate): @@ -48,7 +48,7 @@ class Api(ApiTemplate):
48 48
49 49
50 api_doc = { 50 api_doc = {
51 - "tags": ["服务接口"], 51 + "tags": ["服务目录接口"],
52 "parameters": [ 52 "parameters": [
53 {"name": "guid", 53 {"name": "guid",
54 "in": "formData", 54 "in": "formData",
@@ -34,7 +34,7 @@ class Api(ApiTemplate): @@ -34,7 +34,7 @@ class Api(ApiTemplate):
34 34
35 35
36 api_doc = { 36 api_doc = {
37 - "tags": ["服务接口"], 37 + "tags": ["服务目录接口"],
38 "parameters": [ 38 "parameters": [
39 {"name": "guid", 39 {"name": "guid",
40 "in": "formData", 40 "in": "formData",
@@ -32,7 +32,7 @@ class Api(ApiTemplate): @@ -32,7 +32,7 @@ class Api(ApiTemplate):
32 32
33 api_doc={ 33 api_doc={
34 34
35 - "tags":["服务接口"], 35 + "tags":["服务目录接口"],
36 "parameters":[ 36 "parameters":[
37 {"name": "catalog_guid", 37 {"name": "catalog_guid",
38 "in": "formData", 38 "in": "formData",
@@ -50,7 +50,7 @@ class Api(ApiTemplate): @@ -50,7 +50,7 @@ class Api(ApiTemplate):
50 50
51 api_doc={ 51 api_doc={
52 52
53 - "tags":["服务接口"], 53 + "tags":["服务目录接口"],
54 "parameters":[ 54 "parameters":[
55 {"name": "database_guid", 55 {"name": "database_guid",
56 "in": "formData", 56 "in": "formData",
@@ -39,7 +39,7 @@ class Api(ApiTemplate): @@ -39,7 +39,7 @@ class Api(ApiTemplate):
39 39
40 api_doc={ 40 api_doc={
41 41
42 - "tags":["服务接口"], 42 + "tags":["服务目录接口"],
43 "parameters":[ 43 "parameters":[
44 {"name": "database_guid", 44 {"name": "database_guid",
45 "in": "formData", 45 "in": "formData",
@@ -9,14 +9,14 @@ from flask import Blueprint @@ -9,14 +9,14 @@ from flask import Blueprint
9 from app.util import BlueprintApi 9 from app.util import BlueprintApi
10 from . import image_register 10 from . import image_register
11 from . import image_service_register 11 from . import image_service_register
12 -from . import image_service_list  
13 from . import image_server_list 12 from . import image_server_list
14 from . import data_list 13 from . import data_list
15 from . import capabilities 14 from . import capabilities
16 from . import image_list 15 from . import image_list
17 from . import image_tile 16 from . import image_tile
18 from . import image_wms 17 from . import image_wms
19 - 18 +from . import image_overview
  19 +from . import image_service_list
20 20
21 21
22 class DataManager(BlueprintApi): 22 class DataManager(BlueprintApi):
@@ -33,6 +33,16 @@ class DataManager(BlueprintApi): @@ -33,6 +33,16 @@ class DataManager(BlueprintApi):
33 """ 33 """
34 return image_register.Api().result 34 return image_register.Api().result
35 35
  36 +
  37 + @staticmethod
  38 + @bp.route('/Overview', methods=['POST'])
  39 + @swag_from(image_overview.Api.api_doc)
  40 + def api_image_overview():
  41 + """
  42 + 影像缩略图
  43 + """
  44 + return image_overview.Api().result
  45 +
36 @staticmethod 46 @staticmethod
37 @bp.route('/ServiceRegister', methods=['POST']) 47 @bp.route('/ServiceRegister', methods=['POST'])
38 @swag_from(image_service_register.Api.api_doc) 48 @swag_from(image_service_register.Api.api_doc)
@@ -43,6 +53,15 @@ class DataManager(BlueprintApi): @@ -43,6 +53,15 @@ class DataManager(BlueprintApi):
43 return image_service_register.Api().result 53 return image_service_register.Api().result
44 54
45 @staticmethod 55 @staticmethod
  56 + @bp.route('/ServiceList', methods=['GET'])
  57 + @swag_from(image_service_list.Api.api_doc)
  58 + def api_image_service_list():
  59 + """
  60 + 服务列表
  61 + """
  62 + return image_service_list.Api().result
  63 +
  64 + @staticmethod
46 @bp.route('/ServerList', methods=['GET']) 65 @bp.route('/ServerList', methods=['GET'])
47 @swag_from(image_server_list.Api.api_doc) 66 @swag_from(image_server_list.Api.api_doc)
48 def image_server_list(): 67 def image_server_list():
@@ -79,14 +98,6 @@ class DataManager(BlueprintApi): @@ -79,14 +98,6 @@ class DataManager(BlueprintApi):
79 """ 98 """
80 return image_list.Api().result 99 return image_list.Api().result
81 100
82 - @staticmethod  
83 - @bp.route('/ImageServiceList', methods=['POST'])  
84 - @swag_from(image_service_list.Api.api_doc)  
85 - def image_service_list():  
86 - """  
87 - 影像服务列表  
88 - """  
89 - return image_service_list.Api().result  
90 101
91 @staticmethod 102 @staticmethod
92 @bp.route('/Tile/<guid>/<l>/<y>/<z>', methods=['GET']) 103 @bp.route('/Tile/<guid>/<l>/<y>/<z>', methods=['GET'])
@@ -2,3 +2,52 @@ @@ -2,3 +2,52 @@
2 #author: 4N 2 #author: 4N
3 #createtime: 2021/9/8 3 #createtime: 2021/9/8
4 #email: nheweijun@sina.com 4 #email: nheweijun@sina.com
  5 +
  6 +
  7 +
  8 +from app.util.component.ApiTemplate import ApiTemplate
  9 +from app.util.component.ModelVisitor import ModelVisitor
  10 +
  11 +from app.modules.service.image.models import Image,db
  12 +from sqlalchemy import or_,and_
  13 +import datetime
  14 +class Api(ApiTemplate):
  15 +
  16 + api_name = "影像数据List"
  17 +
  18 + def process(self):
  19 +
  20 + # 返回结果
  21 + res = {}
  22 + try:
  23 + para = self.para
  24 + guid = self.para.get("guid")
  25 + image = Image.query.filter_by(guid=guid).one_or_none()
  26 + del para["guid"]
  27 + para["update_time"] = datetime.datetime.now()
  28 + image.update(para)
  29 + db.session.commit()
  30 +
  31 + res["result"] = True
  32 + except Exception as e:
  33 + raise e
  34 +
  35 + return res
  36 +
  37 +
  38 + api_doc = {
  39 + "tags": ["影像接口"],
  40 + "parameters": [
  41 + {"name": "alias",
  42 + "in": "formData",
  43 + "type": "string"},
  44 + ],
  45 + "responses": {
  46 + 200: {
  47 + "schema": {
  48 + "properties": {
  49 + }
  50 + }
  51 + }
  52 + }
  53 + }
@@ -5,30 +5,90 @@ @@ -5,30 +5,90 @@
5 5
6 6
7 from app.util.component.ApiTemplate import ApiTemplate 7 from app.util.component.ApiTemplate import ApiTemplate
8 -from app.util.component.ModelVisitor import ModelVisitor 8 +from app.util.component.StructuredPrint import StructurePrint
9 9
10 from app.modules.service.image.models import Image 10 from app.modules.service.image.models import Image
11 -from sqlalchemy import or_,and_ 11 +from sqlalchemy import or_
  12 +import random
  13 +from .image_wms import Api as WMSApi
  14 +import numpy
  15 +import json
  16 +from flask import Response
  17 +from kazoo.client import KazooClient
  18 +import configure
  19 +import traceback
  20 +
  21 +
12 class Api(ApiTemplate): 22 class Api(ApiTemplate):
13 23
14 api_name = "影像数据预览功能" 24 api_name = "影像数据预览功能"
15 25
16 def process(self): 26 def process(self):
  27 + from app import GLOBAL_DIC
17 28
18 # 返回结果 29 # 返回结果
19 res = {} 30 res = {}
  31 +
20 try: 32 try:
  33 +
  34 + #获取
  35 + zoo = GLOBAL_DIC.get("zookeeper")
  36 + if zoo is None:
  37 + zoo :KazooClient = KazooClient(hosts=configure.zookeeper, timeout=100)
  38 + zoo.start()
  39 + GLOBAL_DIC["zookeeper"] = zoo
  40 + StructurePrint().print("连接zoo")
  41 + else :
  42 + if not zoo.connected:
  43 + zoo.start()
21 44
22 - res["result"] = True  
23 - except Exception as e:  
24 - raise e  
25 45
26 - return res 46 + guid = self.para.get("guid")
  47 + image = Image.query.filter_by(guid=guid).one_or_none()
  48 + # 该影像的服务器,随机选取一个
  49 + image_servers = image.server.split(",")
  50 + indx = int(random.random() * len(image_servers))
  51 + image_server = image_servers[indx]
  52 + wms_api = WMSApi()
  53 +
  54 + bands = [1,2,3] if image.band_count>=3 else [1,1,1]
  55 +
  56 + #计算查询范围,保持正常比例
  57 + query_extent = json.loads(image.extent)
  58 + if query_extent[2]-query_extent[0] > query_extent[3]-query_extent[1]:
  59 + offset = ((query_extent[2]-query_extent[0]) - (query_extent[3]-query_extent[1])) / 2.0
  60 + query_extent = [query_extent[0],query_extent[1] - offset ,query_extent[2],query_extent[3] + offset]
  61 + else:
  62 + offset = ((query_extent[3] - query_extent[1]) - (query_extent[2] - query_extent[0])) / 2.0
  63 + query_extent = [query_extent[0] - offset, query_extent[1], query_extent[2] + offset, query_extent[3]]
  64 +
  65 +
  66 + pixel_array_t = wms_api.get_data(zoo, image_server, image, query_extent, bands, 256, 256)
  67 +
  68 +
  69 + pixel_array = numpy.zeros((256, 256, 3), dtype=int)
  70 + for ii in [0, 1, 2]:
  71 + # opencv 颜色排序为GBR
  72 + pixel_array[:, :, 2 - ii] = pixel_array_t[:, :, ii]
  73 +
  74 + # 将图片生成在内存中,然后直接返回response
  75 + im_data = wms_api.create_by_opencv("image/jpeg", pixel_array, 30)
  76 +
  77 + return Response(im_data, mimetype="image/jpeg")
  78 +
  79 + except Exception as e:
  80 + StructurePrint().print(traceback.format_exc())
  81 + res["state"] = -1
  82 + res["message"] = e.__str__()
  83 + return res
27 84
28 85
29 api_doc = { 86 api_doc = {
30 "tags": ["影像接口"], 87 "tags": ["影像接口"],
31 "parameters": [ 88 "parameters": [
  89 + {"name": "guid",
  90 + "in": "formData",
  91 + "type": "string"},
32 ], 92 ],
33 "responses": { 93 "responses": {
34 200: { 94 200: {
@@ -117,7 +117,7 @@ class Api(ApiTemplate): @@ -117,7 +117,7 @@ class Api(ApiTemplate):
117 cell_x_size = info.get("cell_x_size"), 117 cell_x_size = info.get("cell_x_size"),
118 cell_y_size = abs(info.get("cell_y_size")), 118 cell_y_size = abs(info.get("cell_y_size")),
119 name=os.path.basename(info.get("path")), 119 name=os.path.basename(info.get("path")),
120 - origin_extent=json.dumps(info["origin_extent"]), 120 + extent=json.dumps(info["origin_extent"]),
121 # geo_origin_extent = json.dumps(info["geo_origin_extent"]), 121 # geo_origin_extent = json.dumps(info["geo_origin_extent"]),
122 null_value=info.get("null_value"), 122 null_value=info.get("null_value"),
123 server=data_server, 123 server=data_server,
@@ -132,6 +132,9 @@ class Api(ApiTemplate): @@ -132,6 +132,9 @@ class Api(ApiTemplate):
132 db.session.add(image) 132 db.session.add(image)
133 db.session.commit() 133 db.session.commit()
134 # res["data"] = guid 134 # res["data"] = guid
  135 +
  136 +
  137 +
135 res["result"] = True 138 res["result"] = True
136 139
137 except Exception as e: 140 except Exception as e:
@@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
4 #email: nheweijun@sina.com 4 #email: nheweijun@sina.com
5 5
6 from app.util.component.ApiTemplate import ApiTemplate 6 from app.util.component.ApiTemplate import ApiTemplate
7 -from app import GLOBAL_DIC 7 +
8 from kazoo.client import KazooClient 8 from kazoo.client import KazooClient
9 import configure 9 import configure
10 class Api(ApiTemplate): 10 class Api(ApiTemplate):
@@ -12,6 +12,7 @@ class Api(ApiTemplate): @@ -12,6 +12,7 @@ class Api(ApiTemplate):
12 api_name = "获取数据服务器列表" 12 api_name = "获取数据服务器列表"
13 13
14 def process(self): 14 def process(self):
  15 + from app import GLOBAL_DIC
15 16
16 # 返回结果 17 # 返回结果
17 res = {} 18 res = {}
@@ -6,25 +6,39 @@ @@ -6,25 +6,39 @@
6 from app.modules.service.image.models import ImageService,Image 6 from app.modules.service.image.models import ImageService,Image
7 from app.models import db 7 from app.models import db
8 from app.util.component.ApiTemplate import ApiTemplate 8 from app.util.component.ApiTemplate import ApiTemplate
9 -import uuid  
10 -from app.util.component.SliceScheme import SliceScheme  
11 -from app.util.component.FileProcess import FileProcess  
12 -import os  
13 -import json 9 +from app.models import Service
14 import datetime 10 import datetime
15 class Api(ApiTemplate): 11 class Api(ApiTemplate):
16 12
17 - api_name = "注册影像服务" 13 + api_name = "修改影像服务"
18 14
19 def process(self): 15 def process(self):
20 16
21 -  
22 -  
23 # 返回结果 17 # 返回结果
24 res = {} 18 res = {}
25 19
26 try: 20 try:
27 21
  22 + guid = self.para.get("guid")
  23 + service = Service.query.filter_by(guid=guid).one_or_none()
  24 + this_time = datetime.datetime.now()
  25 +
  26 +
  27 + service_update = {"upate_time":this_time}
  28 + image_service = {"upate_time":this_time}
  29 + for key in self.para.keys():
  30 + if key in ["name","alias","state","description","catalog_guid"]:
  31 + service_update[key] = self.para.get(key)
  32 + if key in ["name","scheme_guid"]:
  33 + image_service[key] = self.para.get(key)
  34 +
  35 + image_service = ImageService.query.filter_by(guid=service.service_guid).one_or_none()
  36 +
  37 + service.update(service_update)
  38 + image_service.update(image_service)
  39 +
  40 + db.session.commit()
  41 +
28 res["result"] = True 42 res["result"] = True
29 except Exception as e: 43 except Exception as e:
30 raise e 44 raise e
@@ -34,14 +48,12 @@ class Api(ApiTemplate): @@ -34,14 +48,12 @@ class Api(ApiTemplate):
34 api_doc = { 48 api_doc = {
35 "tags": ["影像接口"], 49 "tags": ["影像接口"],
36 "parameters": [ 50 "parameters": [
37 - {"name": "guids", 51 + {"name": "guid",
38 "in": "formData", 52 "in": "formData",
39 - "type": "string",  
40 - "description": "影像guids,以英文逗号相隔"},  
41 - {"name": "file", 53 + "type": "string"},
  54 + {"name": "name",
42 "in": "formData", 55 "in": "formData",
43 - "type": "file",  
44 - "description": "切片方案"}, 56 + "type": "string"},
45 ], 57 ],
46 "responses": { 58 "responses": {
47 200: { 59 200: {
  1 +# coding=utf-8
  2 +#author: 4N
  3 +#createtime: 2021/7/19
  4 +#email: nheweijun@sina.com
  5 +
  6 +from app.modules.service.image.models import ImageService,Image
  7 +
  8 +from app.util.component.ApiTemplate import ApiTemplate
  9 +from app.util.component.ModelVisitor import ModelVisitor
  10 +from app.models import Service
  11 +from sqlalchemy import or_
  12 +class Api(ApiTemplate):
  13 +
  14 + api_name = "影像服务List"
  15 +
  16 + def process(self):
  17 +
  18 + # 返回结果
  19 + res = {}
  20 +
  21 + try:
  22 + page_index = int(self.para.get("page_index", "0"))
  23 + page_size = int(self.para.get("page_size", "10"))
  24 +
  25 + alias = self.para.get("alias")
  26 + name = self.para.get("name")
  27 + type = self.para.get("type")
  28 +
  29 + services = ImageService.query
  30 + if type:
  31 + services = services.filter_by(type=type)
  32 + # 并集
  33 + if alias and name:
  34 + services = services.filter(
  35 + or_(ImageService.alias.like("%" + alias + "%"), ImageService.name.like("%" + name + "%")))
  36 + else:
  37 + if alias:
  38 + services = services.filter(ImageService.alias.like("%" + alias + "%"))
  39 + if name:
  40 + services = services.filter(ImageService.name.like("%" + name + "%"))
  41 +
  42 + services = services.limit(page_size).offset(page_index).all()
  43 +
  44 + res["data"] = ModelVisitor.objects_to_jsonarray(services)
  45 + res["result"] = True
  46 + except Exception as e:
  47 + raise e
  48 +
  49 + return res
  50 +
  51 + api_doc = {
  52 + "tags": ["影像接口"],
  53 + "parameters": [
  54 + {"name": "page_index",
  55 + "in": "formData",
  56 + "type": "int",
  57 + "description": "页"},
  58 + {"name": "page_size",
  59 + "in": "formData",
  60 + "type": "int",
  61 + "description": "页大小"},
  62 + {"name": "alias",
  63 + "in": "formData",
  64 + "type": "string",
  65 + "description": "服务别名"},
  66 + {"name": "name",
  67 + "in": "formData",
  68 + "type": "string",
  69 + "description": "服务名"},
  70 + ],
  71 + "responses": {
  72 + 200: {
  73 + "schema": {
  74 + "properties": {
  75 + }
  76 + }
  77 + }
  78 + }
  79 + }
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 #createtime: 2021/7/19 3 #createtime: 2021/7/19
4 #email: nheweijun@sina.com 4 #email: nheweijun@sina.com
5 5
6 -from app.modules.service.image.models import ImageService,Image 6 +from .models import ImageService,Image
7 from app.models import db,Service 7 from app.models import db,Service
8 from app.util.component.ApiTemplate import ApiTemplate 8 from app.util.component.ApiTemplate import ApiTemplate
9 import uuid 9 import uuid
@@ -12,6 +12,10 @@ from app.util.component.FileProcess import FileProcess @@ -12,6 +12,10 @@ from app.util.component.FileProcess import FileProcess
12 import os 12 import os
13 import json 13 import json
14 import datetime 14 import datetime
  15 +from .image_wms import Api as Api2
  16 +import cv2
  17 +import configure
  18 +
15 class Api(ApiTemplate): 19 class Api(ApiTemplate):
16 20
17 api_name = "注册影像服务" 21 api_name = "注册影像服务"
@@ -26,55 +30,133 @@ class Api(ApiTemplate): @@ -26,55 +30,133 @@ class Api(ApiTemplate):
26 try: 30 try:
27 guids = self.para.get("guids").split(",") 31 guids = self.para.get("guids").split(",")
28 name = self.para.get("name") 32 name = self.para.get("name")
29 - catalog_guid = self.para.get("catalog_guid")  
30 -  
31 - service_guid = uuid.uuid1().__str__()  
32 33
  34 + image_service_guid = uuid.uuid1().__str__()
33 35
34 - parent = os.path.dirname(os.path.realpath(__file__))  
35 - dir_path, store_file = FileProcess.save(parent)  
36 - scheme = SliceScheme(store_file).parameter  
37 -  
38 - service = ImageService(guid=service_guid, name=name,  
39 - create_time=datetime.datetime.now())  
40 - service_exetent = [] 36 + this_time = datetime.datetime.now()
  37 + service_guid = uuid.uuid1().__str__()
  38 + image_service = ImageService(guid=image_service_guid,
  39 + name=name,
  40 + create_time=this_time,
  41 + scheme_guid=self.para.get("scheme_guid"),
  42 + crs = self.para.get("crs"),
  43 + service_guid=service_guid)
  44 + image_service_exetent = []
41 45
42 for g in guids: 46 for g in guids:
43 image = Image.query.filter_by(guid=g).one_or_none() 47 image = Image.query.filter_by(guid=g).one_or_none()
44 if image: 48 if image:
45 - image_extent = json.loads(image.origin_extent)  
46 - if not service_exetent:  
47 - service_exetent = image_extent 49 + image_extent = json.loads(image.extent)
  50 + if not image_service_exetent:
  51 + image_service_exetent = image_extent
48 else: 52 else:
49 - service_exetent[0] = min(image_extent[0],service_exetent[0])  
50 - service_exetent[1] = min(image_extent[1], service_exetent[1])  
51 - service_exetent[2] = max(image_extent[2], service_exetent[2])  
52 - service_exetent[3] = max(image_extent[3], service_exetent[3])  
53 - service.images.append(image)  
54 - service.extent = json.dumps(service_exetent) 53 + image_service_exetent[0] = min(image_extent[0],image_service_exetent[0])
  54 + image_service_exetent[1] = min(image_extent[1], image_service_exetent[1])
  55 + image_service_exetent[2] = max(image_extent[2], image_service_exetent[2])
  56 + image_service_exetent[3] = max(image_extent[3], image_service_exetent[3])
  57 + image_service.images.append(image)
  58 + image_service.extent = json.dumps(image_service_exetent)
  59 +
  60 +
  61 +
  62 + service = Service(
  63 + guid = service_guid,
  64 + name = self.para.get("name"),
  65 + alias = self.para.get("alias"),
  66 + state = 1,
  67 + create_time = this_time,
  68 + update_time = this_time,
  69 + description = self.para.get("description"),
  70 + #node = Column(Integer),
  71 + type = self.para.get("type"),
  72 + service_guid = image_service_guid,
  73 + catalog_guid = self.para.get("catalog_guid")
  74 + )
  75 +
55 db.session.add(service) 76 db.session.add(service)
56 - db.session.commit() 77 + db.session.add(image_service)
  78 +
57 79
58 #获得overview 80 #获得overview
  81 + overview_file = self.get_overview(service,image_service)
  82 + service.overview="http://{}/API/Service/Overview/{}".format(
  83 + configure.deploy_ip_host,overview_file)
  84 + db.session.commit()
59 85
60 - res["data"] = service_guid 86 + res["data"] = image_service_guid
61 res["result"] = True 87 res["result"] = True
62 except Exception as e: 88 except Exception as e:
  89 + db.session.rollback()
63 raise e 90 raise e
64 91
65 return res 92 return res
66 93
  94 + def get_overview(self,service,image_service):
  95 +
  96 + api = Api2()
  97 +
  98 +
  99 + query_extent = json.loads(image_service.extent)
  100 + if query_extent[2] - query_extent[0] > query_extent[3] - query_extent[1]:
  101 + offset = ((query_extent[2] - query_extent[0]) - (query_extent[3] - query_extent[1])) / 2.0
  102 + query_extent = [query_extent[0], query_extent[1] - offset, query_extent[2], query_extent[3] + offset]
  103 + else:
  104 + offset = ((query_extent[3] - query_extent[1]) - (query_extent[2] - query_extent[0])) / 2.0
  105 + query_extent = [query_extent[0] - offset, query_extent[1], query_extent[2] + offset, query_extent[3]]
  106 +
  107 + bbox = ",".join([str(x) for x in query_extent])
  108 +
  109 + api.para = {"guid":image_service.guid,"bbox":bbox,"overview":1}
  110 + res = api.process()
  111 + dir_path = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), "overview")
  112 + gid = uuid.uuid1().__str__()
  113 + store_file = os.path.join(dir_path, "{}.jpg".format(gid))
  114 + cv2.imwrite(store_file, res, [cv2.IMWRITE_JPEG_QUALITY, 30])
  115 +
  116 + return "{}.jpg".format(gid)
  117 +
  118 +
  119 +
  120 +
67 api_doc = { 121 api_doc = {
68 "tags": ["影像接口"], 122 "tags": ["影像接口"],
69 "parameters": [ 123 "parameters": [
  124 +
  125 + # 通用参数
  126 + {"name": "name",
  127 + "in": "formData",
  128 + "type": "string",
  129 + "required": "true",
  130 + "description": "[WMS,WMTS,影像WMS,影像WMTS]"},
  131 + {"name": "alias",
  132 + "in": "formData",
  133 + "type": "string",
  134 + "description": "[WMS,WMTS,影像WMS,影像WMTS]"},
  135 + {"name": "description",
  136 + "in": "formData",
  137 + "type": "string",
  138 + "description": "[WMS,WMTS,影像WMS,影像WMTS]"},
  139 + {"name": "type",
  140 + "in": "formData",
  141 + "type": "string",
  142 + "enum": ["WMS", "WMTS", "影像WMS", "影像WMTS"],
  143 + "required": "true",
  144 + "description": "[WMS,WMTS,影像WMS,影像WMTS]"},
  145 + {"name": "catalog_guid",
  146 + "in": "formData",
  147 + "type": "string",
  148 + "description": "[WMS,WMTS,影像WMS,影像WMTS]"},
  149 +
  150 + # 影像参数
70 {"name": "guids", 151 {"name": "guids",
71 "in": "formData", 152 "in": "formData",
72 "type": "string", 153 "type": "string",
73 - "description": "影像guids,以英文逗号相隔"},  
74 - {"name": "file", 154 + "description": "[影像WMS,影像WMTS]影像guids,以英文逗号相隔"},
  155 + {"name": "scheme_guid",
75 "in": "formData", 156 "in": "formData",
76 - "type": "file",  
77 - "description": "切片方案"}, 157 + "type": "string",
  158 + "description": "[WMTS,影像WMTS]切片方案"},
  159 +
78 ], 160 ],
79 "responses": { 161 "responses": {
80 200: { 162 200: {
@@ -84,4 +166,7 @@ class Api(ApiTemplate): @@ -84,4 +166,7 @@ class Api(ApiTemplate):
84 } 166 }
85 } 167 }
86 } 168 }
87 - }  
  169 + }
  170 +
  171 +if __name__ == '__main__':
  172 + pass
  1 +# coding=utf-8
  2 +#author: 4N
  3 +#createtime: 2021/9/8
  4 +#email: nheweijun@sina.com
  5 +
  6 +
  7 +from app.util.component.ApiTemplate import ApiTemplate
  8 +from app.util.component.ModelVisitor import ModelVisitor
  9 +from kazoo.client import KazooClient
  10 +import configure
  11 +from .models import ImageTag
  12 +import uuid
  13 +from app.models import db
  14 +class Api(ApiTemplate):
  15 +
  16 + api_name = "create tag"
  17 +
  18 + def process(self):
  19 +
  20 + # 返回结果
  21 + res = {}
  22 + try:
  23 + tag_guid = uuid.uuid1().__str__()
  24 +
  25 + image_tag = ImageTag(guid=tag_guid,name=self.para.get("name"))
  26 + db.session.add(image_tag)
  27 + db.session.commit()
  28 + res["data"] = tag_guid
  29 + res["result"] = True
  30 + except Exception as e:
  31 + raise e
  32 + return res
  33 +
  34 + api_doc = {
  35 + "tags": ["影像接口"],
  36 + "parameters": [
  37 + {"name": "name",
  38 + "in": "formData",
  39 + "type": "string"},
  40 + ],
  41 + "responses": {
  42 + 200: {
  43 + "schema": {
  44 + "properties": {
  45 + }
  46 + }
  47 + }
  48 + }
  49 + }
  1 +# coding=utf-8
  2 +#author: 4N
  3 +#createtime: 2021/9/8
  4 +#email: nheweijun@sina.com
  5 +
  6 +
  7 +from app.util.component.ApiTemplate import ApiTemplate
  8 +from app.models import db
  9 +from .models import ImageTag
  10 +class Api(ApiTemplate):
  11 +
  12 + api_name = "delete tag"
  13 +
  14 + def process(self):
  15 +
  16 + # 返回结果
  17 + res = {}
  18 + try:
  19 + image_tag = ImageTag.query.filter_by(guid=self.para.get("guid")).one_or_none()
  20 + if image_tag:
  21 + db.session.delete(image_tag)
  22 + db.session.commit()
  23 + res["result"] = True
  24 + except Exception as e:
  25 + raise e
  26 + return res
  27 +
  28 + api_doc = {
  29 + "tags": ["影像接口"],
  30 + "parameters": [
  31 + {"name": "guid",
  32 + "in": "formData",
  33 + "type": "string"},
  34 + ],
  35 + "responses": {
  36 + 200: {
  37 + "schema": {
  38 + "properties": {
  39 + }
  40 + }
  41 + }
  42 + }
  43 + }
@@ -2,3 +2,39 @@ @@ -2,3 +2,39 @@
2 #author: 4N 2 #author: 4N
3 #createtime: 2021/9/8 3 #createtime: 2021/9/8
4 #email: nheweijun@sina.com 4 #email: nheweijun@sina.com
  5 +
  6 +
  7 +from app.util.component.ApiTemplate import ApiTemplate
  8 +from app.util.component.ModelVisitor import ModelVisitor
  9 +from kazoo.client import KazooClient
  10 +import configure
  11 +from .models import ImageTag
  12 +class Api(ApiTemplate):
  13 +
  14 + api_name = "获取tag列表"
  15 +
  16 + def process(self):
  17 +
  18 + # 返回结果
  19 + res = {}
  20 + try:
  21 + image_tags = ImageTag.query.all()
  22 + res["data"] = ModelVisitor.objects_to_jsonarray(image_tags)
  23 + res["result"] = True
  24 + except Exception as e:
  25 + raise e
  26 + return res
  27 +
  28 + api_doc = {
  29 + "tags": ["影像接口"],
  30 + "parameters": [
  31 + ],
  32 + "responses": {
  33 + 200: {
  34 + "schema": {
  35 + "properties": {
  36 + }
  37 + }
  38 + }
  39 + }
  40 + }
@@ -17,7 +17,7 @@ from PIL import Image @@ -17,7 +17,7 @@ from PIL import Image
17 import time 17 import time
18 import cv2 18 import cv2
19 from app.modules.service.image.models import ImageService,Image 19 from app.modules.service.image.models import ImageService,Image
20 -from app.models import db 20 +from app.models import db,TileScheme
21 from app.util.component.ApiTemplate import ApiTemplate 21 from app.util.component.ApiTemplate import ApiTemplate
22 import uuid 22 import uuid
23 from app.util.component.SliceScheme import SliceScheme 23 from app.util.component.SliceScheme import SliceScheme
@@ -27,7 +27,7 @@ from app.util.component.GeometryAdapter import GeometryAdapter @@ -27,7 +27,7 @@ from app.util.component.GeometryAdapter import GeometryAdapter
27 import os 27 import os
28 import json 28 import json
29 from kazoo.client import KazooClient 29 from kazoo.client import KazooClient
30 -from app import GLOBAL_DIC 30 +
31 from threading import Thread 31 from threading import Thread
32 32
33 from app.modules.service.image.util.ThriftConnect import ThriftConnect 33 from app.modules.service.image.util.ThriftConnect import ThriftConnect
@@ -46,7 +46,7 @@ class Api(ApiTemplate): @@ -46,7 +46,7 @@ class Api(ApiTemplate):
46 self.col = col 46 self.col = col
47 47
48 def process(self): 48 def process(self):
49 - 49 + from app import GLOBAL_DIC
50 result = {} 50 result = {}
51 parameter: dict = self.para 51 parameter: dict = self.para
52 52
@@ -54,8 +54,16 @@ class Api(ApiTemplate): @@ -54,8 +54,16 @@ class Api(ApiTemplate):
54 if parameter.get("guid"): 54 if parameter.get("guid"):
55 self.guid = parameter.get("guid") 55 self.guid = parameter.get("guid")
56 56
57 - image_service = ImageService.query.filter_by(guid = self.guid).one_or_none()  
58 - images = image_service.images.all() 57 + #缓存服务信息
  58 + image_service_info = GLOBAL_DIC.get(self.guid)
  59 + if image_service_info is None:
  60 + image_service:ImageService = ImageService.query.filter_by(guid = self.guid).one_or_none()
  61 + images = image_service.images.all()
  62 + scheme:TileScheme = TileScheme.query.filter_by(guid=image_service.scheme_guid).one_or_none()
  63 + GLOBAL_DIC[self.guid] = {"service":image_service,"images":images,"scheme":json.loads(scheme.parameter)}
  64 + image_service_info = GLOBAL_DIC[self.guid]
  65 + else:
  66 + image_service_info = GLOBAL_DIC[self.guid]
59 67
60 zoo = GLOBAL_DIC.get("zookeeper") 68 zoo = GLOBAL_DIC.get("zookeeper")
61 if zoo is None: 69 if zoo is None:
@@ -85,14 +93,15 @@ class Api(ApiTemplate): @@ -85,14 +93,15 @@ class Api(ApiTemplate):
85 93
86 image_type = parameter.get("format") if parameter.get("format") else "image/png" 94 image_type = parameter.get("format") if parameter.get("format") else "image/png"
87 quality = int(parameter.get("quality")) if parameter.get("quality") else 30 95 quality = int(parameter.get("quality")) if parameter.get("quality") else 30
88 - slice_para = json.loads(image_service.slice_scheme) 96 + slice_para = image_service_info["scheme"]
89 extent = SliceScheme.get_polygon(slice_para, self.level, self.row, self.col) 97 extent = SliceScheme.get_polygon(slice_para, self.level, self.row, self.col)
90 98
  99 +
91 height, width = 256,256 100 height, width = 256,256
92 101
93 # 多线程获取分布式数据 102 # 多线程获取分布式数据
94 103
95 - intersect_image = [im for im in images if self.determin_intersect(json.loads(im.origin_extent),extent)] 104 + intersect_image = [im for im in image_service_info["images"] if self.determin_intersect(json.loads(im.extent),extent)]
96 105
97 if len(intersect_image) > 1: 106 if len(intersect_image) > 1:
98 107
@@ -109,7 +118,6 @@ class Api(ApiTemplate): @@ -109,7 +118,6 @@ class Api(ApiTemplate):
109 image_servers = image.server.split(",") 118 image_servers = image.server.split(",")
110 indx = int(random.random() * len(image_servers)) 119 indx = int(random.random() * len(image_servers))
111 image_server = image_servers[indx] 120 image_server = image_servers[indx]
112 -  
113 thread: MyThread = MyThread(self.get_data, 121 thread: MyThread = MyThread(self.get_data,
114 args=(zoo, image_server, image, extent, bands, height, width)) 122 args=(zoo, image_server, image, extent, bands, height, width))
115 thread.start() 123 thread.start()
@@ -141,7 +149,9 @@ class Api(ApiTemplate): @@ -141,7 +149,9 @@ class Api(ApiTemplate):
141 image = intersect_image[0] 149 image = intersect_image[0]
142 image_servers = image.server.split(",") 150 image_servers = image.server.split(",")
143 indx = int(random.random() * len(image_servers)) 151 indx = int(random.random() * len(image_servers))
  152 +
144 image_server = image_servers[indx] 153 image_server = image_servers[indx]
  154 +
145 pixel_array_t = self.get_data(zoo, image_server, image, extent, bands, height, width) 155 pixel_array_t = self.get_data(zoo, image_server, image, extent, bands, height, width)
146 pixel_array = numpy.zeros((height, width, 3), dtype=int) 156 pixel_array = numpy.zeros((height, width, 3), dtype=int)
147 for ii in [0, 1, 2]: 157 for ii in [0, 1, 2]:
@@ -205,13 +215,13 @@ class Api(ApiTemplate): @@ -205,13 +215,13 @@ class Api(ApiTemplate):
205 else: 215 else:
206 ser = image_server 216 ser = image_server
207 if zoo.exists("/rpc/{}".format(ser)): 217 if zoo.exists("/rpc/{}".format(ser)):
208 - data = self.get_remote_wms_data(image, extent, bands, height, width) 218 + data = self.get_remote_wms_data(ser,image, extent, bands, height, width)
209 else: 219 else:
210 data = numpy.zeros((height, width, 3), dtype=int) + 65536 220 data = numpy.zeros((height, width, 3), dtype=int) + 65536
211 221
212 return data 222 return data
213 223
214 - def get_remote_wms_data(self, image, extent, bands, height, width): 224 + def get_remote_wms_data(self, image_server,image, extent, bands, height, width):
215 ''' 225 '''
216 通过RPC获取远程数据 226 通过RPC获取远程数据
217 :param image: 227 :param image:
@@ -219,14 +229,19 @@ class Api(ApiTemplate): @@ -219,14 +229,19 @@ class Api(ApiTemplate):
219 :param bands: 229 :param bands:
220 :return: 230 :return:
221 ''' 231 '''
222 - thrift_connect = ThriftConnect(image.server) 232 +
  233 +
  234 + #需要做thrift连接的缓存,连接池
  235 +
  236 + thrift_connect = ThriftConnect(image_server)
223 t1 = time.time() 237 t1 = time.time()
224 - image_extent = image.origin_extent if abs(extent[0]) > 180 else image.geo_origin_extent 238 + image_extent = image.extent
225 239
226 data = thrift_connect.client.getData(image.path, extent, json.loads(image_extent), bands, width, height) 240 data = thrift_connect.client.getData(image.path, extent, json.loads(image_extent), bands, width, height)
227 241
228 thrift_connect.close() 242 thrift_connect.close()
229 - current_app.logger.info("time {}".format(time.time() - t1)) 243 +
  244 + # current_app.logger.info("time {}".format(time.time() - t1))
230 data = gzip.decompress(data) 245 data = gzip.decompress(data)
231 data = numpy.frombuffer(data, dtype='int64') 246 data = numpy.frombuffer(data, dtype='int64')
232 data = data.reshape((height, width, 3)) 247 data = data.reshape((height, width, 3))
@@ -250,7 +265,7 @@ class Api(ApiTemplate): @@ -250,7 +265,7 @@ class Api(ApiTemplate):
250 # 自决定金字塔等级 265 # 自决定金字塔等级
251 xysize = [img.RasterXSize, img.RasterYSize] 266 xysize = [img.RasterXSize, img.RasterYSize]
252 267
253 - origin_extent = image.origin_extent if abs(extent[0]) > 180 else image.geo_origin_extent 268 + origin_extent = image.extent
254 band_data: Band = img.GetRasterBand(band) 269 band_data: Band = img.GetRasterBand(band)
255 270
256 max_level = band_data.GetOverviewCount() 271 max_level = band_data.GetOverviewCount()
@@ -337,8 +352,8 @@ class Api(ApiTemplate): @@ -337,8 +352,8 @@ class Api(ApiTemplate):
337 return pixel_array 352 return pixel_array
338 353
339 def determin_intersect(self, extent1, extent2): 354 def determin_intersect(self, extent1, extent2):
340 - g1 = GeometryAdapter.envelop_2_polygon(extent1)  
341 - g2 = GeometryAdapter.envelop_2_polygon(extent2) 355 + g1 = GeometryAdapter.bbox_2_polygon(extent1)
  356 + g2 = GeometryAdapter.bbox_2_polygon(extent2)
342 return g1.Intersect(g2) 357 return g1.Intersect(g2)
343 358
344 api_doc = { 359 api_doc = {
@@ -20,7 +20,7 @@ from app.modules.service.image.util.ThriftConnect import ThriftConnect @@ -20,7 +20,7 @@ from app.modules.service.image.util.ThriftConnect import ThriftConnect
20 from app.util.component.ParameterUtil import ParameterUtil 20 from app.util.component.ParameterUtil import ParameterUtil
21 import json 21 import json
22 from kazoo.client import KazooClient 22 from kazoo.client import KazooClient
23 -from app import GLOBAL_DIC 23 +
24 from threading import Thread 24 from threading import Thread
25 from flask import current_app 25 from flask import current_app
26 import gzip 26 import gzip
@@ -30,6 +30,7 @@ class Api(ApiTemplate): @@ -30,6 +30,7 @@ class Api(ApiTemplate):
30 api_name = "WMS" 30 api_name = "WMS"
31 31
32 def process(self): 32 def process(self):
  33 + from app import GLOBAL_DIC
33 34
34 result = {} 35 result = {}
35 parameter: dict = self.para 36 parameter: dict = self.para
@@ -45,16 +46,22 @@ class Api(ApiTemplate): @@ -45,16 +46,22 @@ class Api(ApiTemplate):
45 quality = int(parameter.get("quality")) if parameter.get("quality") else 30 46 quality = int(parameter.get("quality")) if parameter.get("quality") else 30
46 47
47 48
48 -  
49 -  
50 #缓存起来 49 #缓存起来
51 - image_service = ImageService.query.filter_by(guid = guid).one_or_none()  
52 - images = image_service.images.all() 50 + #缓存服务信息
  51 + image_service_info = GLOBAL_DIC.get(guid)
  52 + if image_service_info is None:
  53 + image_service:ImageService = ImageService.query.filter_by(guid=guid).one_or_none()
  54 + images = image_service.images.all()
  55 + GLOBAL_DIC[guid] = {"service":image_service,"images":images}
  56 + image_service_info = GLOBAL_DIC[guid]
  57 + else:
  58 + image_service_info = GLOBAL_DIC[guid]
  59 +
53 60
54 re = parameter.get("request") 61 re = parameter.get("request")
55 62
56 if re and re.__eq__("GetCapabilities"): 63 if re and re.__eq__("GetCapabilities"):
57 - return self.get_capabilities(image_service) 64 + return self.get_capabilities(image_service_info["service"])
58 65
59 zoo = GLOBAL_DIC.get("zookeeper") 66 zoo = GLOBAL_DIC.get("zookeeper")
60 if zoo is None: 67 if zoo is None:
@@ -66,11 +73,10 @@ class Api(ApiTemplate): @@ -66,11 +73,10 @@ class Api(ApiTemplate):
66 zoo.start() 73 zoo.start()
67 74
68 bands = [1, 2, 3] 75 bands = [1, 2, 3]
69 - extent = [float(x) for x in bbox.split(",")]  
70 - # extent = [extent[1],extent[0],extent[3],extent[2]]  
71 76
  77 + extent = [float(x) for x in bbox.split(",")]
72 78
73 - intersect_image = [im for im in images if self.determin_intersect(json.loads(im.origin_extent),extent)] 79 + intersect_image = [im for im in image_service_info["images"] if self.determin_intersect(json.loads(im.extent),extent)]
74 80
75 if len(intersect_image)>1: 81 if len(intersect_image)>1:
76 82
@@ -131,6 +137,9 @@ class Api(ApiTemplate): @@ -131,6 +137,9 @@ class Api(ApiTemplate):
131 137
132 # 将图片生成在内存中,然后直接返回response 138 # 将图片生成在内存中,然后直接返回response
133 im_data = self.create_by_opencv(image_type, pixel_array, quality) 139 im_data = self.create_by_opencv(image_type, pixel_array, quality)
  140 +
  141 + if self.para.get("overview"):
  142 + return pixel_array
134 return Response(im_data, mimetype=image_type.lower()) 143 return Response(im_data, mimetype=image_type.lower())
135 144
136 except Exception as e: 145 except Exception as e:
@@ -180,7 +189,7 @@ class Api(ApiTemplate): @@ -180,7 +189,7 @@ class Api(ApiTemplate):
180 else: 189 else:
181 ser = image_server 190 ser = image_server
182 if zoo.exists("/rpc/{}".format(ser)): 191 if zoo.exists("/rpc/{}".format(ser)):
183 - data = self.get_remote_wms_data(image, extent, bands, height, width) 192 + data = self.get_remote_wms_data(image_server,image, extent, bands, height, width)
184 else: 193 else:
185 data = numpy.zeros((height, width, 3), dtype=int) + 65536 194 data = numpy.zeros((height, width, 3), dtype=int) + 65536
186 195
@@ -188,7 +197,7 @@ class Api(ApiTemplate): @@ -188,7 +197,7 @@ class Api(ApiTemplate):
188 197
189 198
190 199
191 - def get_remote_wms_data(self,image,extent,bands,height,width): 200 + def get_remote_wms_data(self,image_server,image,extent,bands,height,width):
192 ''' 201 '''
193 通过RPC获取远程数据 202 通过RPC获取远程数据
194 :param image: 203 :param image:
@@ -196,14 +205,14 @@ class Api(ApiTemplate): @@ -196,14 +205,14 @@ class Api(ApiTemplate):
196 :param bands: 205 :param bands:
197 :return: 206 :return:
198 ''' 207 '''
199 - thrift_connect = ThriftConnect(image.server) 208 + thrift_connect = ThriftConnect(image_server)
200 t1 = time.time() 209 t1 = time.time()
201 - image_extent = image.origin_extent 210 + image_extent = image.extent
202 211
203 data = thrift_connect.client.getData(image.path, extent, json.loads(image_extent), bands,width,height) 212 data = thrift_connect.client.getData(image.path, extent, json.loads(image_extent), bands,width,height)
204 213
205 thrift_connect.close() 214 thrift_connect.close()
206 - current_app.logger.info("time {}".format(time.time() - t1)) 215 + # current_app.logger.info("time {}".format(time.time() - t1))
207 data = gzip.decompress(data) 216 data = gzip.decompress(data)
208 data = numpy.frombuffer(data, dtype='int64') 217 data = numpy.frombuffer(data, dtype='int64')
209 data = data.reshape((height,width, 3)) 218 data = data.reshape((height,width, 3))
@@ -227,9 +236,11 @@ class Api(ApiTemplate): @@ -227,9 +236,11 @@ class Api(ApiTemplate):
227 # 自决定金字塔等级 236 # 自决定金字塔等级
228 xysize = [img.RasterXSize, img.RasterYSize] 237 xysize = [img.RasterXSize, img.RasterYSize]
229 238
230 - origin_extent = image.origin_extent if abs(extent[0]) > 180 else image.geo_origin_extent 239 + origin_extent = image.extent
231 band_data: Band = img.GetRasterBand(band) 240 band_data: Band = img.GetRasterBand(band)
232 241
  242 +
  243 +
233 max_level = band_data.GetOverviewCount() 244 max_level = band_data.GetOverviewCount()
234 245
235 # 超出空间范围 246 # 超出空间范围
@@ -314,8 +325,8 @@ class Api(ApiTemplate): @@ -314,8 +325,8 @@ class Api(ApiTemplate):
314 return pixel_array 325 return pixel_array
315 326
316 def determin_intersect(self,extent1,extent2): 327 def determin_intersect(self,extent1,extent2):
317 - g1 = GeometryAdapter.envelop_2_polygon(extent1)  
318 - g2 = GeometryAdapter.envelop_2_polygon(extent2) 328 + g1 = GeometryAdapter.bbox_2_polygon(extent1)
  329 + g2 = GeometryAdapter.bbox_2_polygon(extent2)
319 return g1.Intersect(g2) 330 return g1.Intersect(g2)
320 331
321 def get_capabilities(self,image_service:ImageService): 332 def get_capabilities(self,image_service:ImageService):
@@ -417,7 +428,7 @@ class Api(ApiTemplate): @@ -417,7 +428,7 @@ class Api(ApiTemplate):
417 extent = json.loads(image_service.extent) 428 extent = json.loads(image_service.extent)
418 xml = xml.format(service_title=image_service.name, 429 xml = xml.format(service_title=image_service.name,
419 service_name=image_service.name, 430 service_name=image_service.name,
420 - abstract=image_service.description if image_service.description else "None" , 431 + abstract= "None" ,
421 crs="ESPG:4326", 432 crs="ESPG:4326",
422 layer_name=image_service.name, 433 layer_name=image_service.name,
423 layer_title=image_service.name, 434 layer_title=image_service.name,
@@ -54,15 +54,17 @@ class ImageService(db.Model): @@ -54,15 +54,17 @@ class ImageService(db.Model):
54 ''' 54 '''
55 __tablename__ = 'dmap_image_service' 55 __tablename__ = 'dmap_image_service'
56 guid = Column(String(256), primary_key=True) 56 guid = Column(String(256), primary_key=True)
57 -  
58 - scheme_guid = Column(Text) 57 + name = Column(String)
  58 + scheme_guid = Column(String)
59 extent = Column(String(256)) 59 extent = Column(String(256))
60 # node = Column(Integer) 60 # node = Column(Integer)
61 #可视范围geojson 61 #可视范围geojson
62 visual_region = Column(Text) 62 visual_region = Column(Text)
63 crs = Column(String(256)) 63 crs = Column(String(256))
  64 + create_time = Column(DateTime)
  65 + # service_guid = Column(String, ForeignKey('dmap_service.guid'))
64 66
65 - service_guid = Column(String, ForeignKey('dmap_service.guid')) 67 + service_guid = Column(String)
66 68
67 images = db.relationship('Image', 69 images = db.relationship('Image',
68 secondary=dmap_image_rel, 70 secondary=dmap_image_rel,
  1 +# coding=utf-8
  2 +#author: 4N
  3 +#createtime: 2021/9/26
  4 +#email: nheweijun@sina.com
  5 +
  6 +from app.modules.service.image.tutorial.ttypes import RasterData
  7 +
  8 +from thrift.transport import TSocket
  9 +from thrift.transport import TTransport
  10 +from thrift.protocol import TBinaryProtocol
  11 +from app.modules.service.image.ImageDataService import ImageDataService
  12 +from app.modules.service.image.tutorial import Calculator
  13 +
  14 +from struct import Struct
  15 +
  16 +host = "192.168.184.246"
  17 +port = 9090
  18 +transport: TSocket = TSocket.TSocket(host, port)
  19 +transport = TTransport.TBufferedTransport(transport)
  20 +protocol = TBinaryProtocol.TBinaryProtocol(transport)
  21 +
  22 +client = Calculator.Client(protocol)
  23 +
  24 +
  25 +transport.open()
  26 +
  27 +test = client.getData("江南_01.tif",[1340.27, -1911.31, 4351.79, 5410.6],[1340.27, -1911.31, 4351.79, 5410.6],[3,2,1],768,768)
  28 +print(type(test))
  29 +
  30 +
  31 +
  1 +#!/usr/bin/env python
  2 +#
  3 +# Autogenerated by Thrift Compiler (0.14.2)
  4 +#
  5 +# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
  6 +#
  7 +# options string: py
  8 +#
  9 +
  10 +import sys
  11 +import pprint
  12 +if sys.version_info[0] > 2:
  13 + from urllib.parse import urlparse
  14 +else:
  15 + from urlparse import urlparse
  16 +from thrift.transport import TTransport, TSocket, TSSLSocket, THttpClient
  17 +from thrift.protocol.TBinaryProtocol import TBinaryProtocol
  18 +
  19 +from . import Calculator
  20 +from .ttypes import *
  21 +
  22 +if len(sys.argv) <= 1 or sys.argv[1] == '--help':
  23 + print('')
  24 + print('Usage: ' + sys.argv[0] + ' [-h host[:port]] [-u url] [-f[ramed]] [-s[sl]] [-novalidate] [-ca_certs certs] [-keyfile keyfile] [-certfile certfile] function [arg1 [arg2...]]')
  25 + print('')
  26 + print('Functions:')
  27 + print(' RasterData getData(string path, queryRange, originRange, bands, i32 width, i32 height)')
  28 + print(' Raster getInfo(string path)')
  29 + print(' bool buildOverview(string path)')
  30 + print(' getImageList(string path)')
  31 + print('')
  32 + sys.exit(0)
  33 +
  34 +pp = pprint.PrettyPrinter(indent=2)
  35 +host = 'localhost'
  36 +port = 9090
  37 +uri = ''
  38 +framed = False
  39 +ssl = False
  40 +validate = True
  41 +ca_certs = None
  42 +keyfile = None
  43 +certfile = None
  44 +http = False
  45 +argi = 1
  46 +
  47 +if sys.argv[argi] == '-h':
  48 + parts = sys.argv[argi + 1].split(':')
  49 + host = parts[0]
  50 + if len(parts) > 1:
  51 + port = int(parts[1])
  52 + argi += 2
  53 +
  54 +if sys.argv[argi] == '-u':
  55 + url = urlparse(sys.argv[argi + 1])
  56 + parts = url[1].split(':')
  57 + host = parts[0]
  58 + if len(parts) > 1:
  59 + port = int(parts[1])
  60 + else:
  61 + port = 80
  62 + uri = url[2]
  63 + if url[4]:
  64 + uri += '?%s' % url[4]
  65 + http = True
  66 + argi += 2
  67 +
  68 +if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
  69 + framed = True
  70 + argi += 1
  71 +
  72 +if sys.argv[argi] == '-s' or sys.argv[argi] == '-ssl':
  73 + ssl = True
  74 + argi += 1
  75 +
  76 +if sys.argv[argi] == '-novalidate':
  77 + validate = False
  78 + argi += 1
  79 +
  80 +if sys.argv[argi] == '-ca_certs':
  81 + ca_certs = sys.argv[argi+1]
  82 + argi += 2
  83 +
  84 +if sys.argv[argi] == '-keyfile':
  85 + keyfile = sys.argv[argi+1]
  86 + argi += 2
  87 +
  88 +if sys.argv[argi] == '-certfile':
  89 + certfile = sys.argv[argi+1]
  90 + argi += 2
  91 +
  92 +cmd = sys.argv[argi]
  93 +args = sys.argv[argi + 1:]
  94 +
  95 +if http:
  96 + transport = THttpClient.THttpClient(host, port, uri)
  97 +else:
  98 + if ssl:
  99 + socket = TSSLSocket.TSSLSocket(host, port, validate=validate, ca_certs=ca_certs, keyfile=keyfile, certfile=certfile)
  100 + else:
  101 + socket = TSocket.TSocket(host, port)
  102 + if framed:
  103 + transport = TTransport.TFramedTransport(socket)
  104 + else:
  105 + transport = TTransport.TBufferedTransport(socket)
  106 +protocol = TBinaryProtocol(transport)
  107 +client = Calculator.Client(protocol)
  108 +transport.open()
  109 +
  110 +if cmd == 'getData':
  111 + if len(args) != 6:
  112 + print('getData requires 6 args')
  113 + sys.exit(1)
  114 + pp.pprint(client.getData(args[0], eval(args[1]), eval(args[2]), eval(args[3]), eval(args[4]), eval(args[5]),))
  115 +
  116 +elif cmd == 'getInfo':
  117 + if len(args) != 1:
  118 + print('getInfo requires 1 args')
  119 + sys.exit(1)
  120 + pp.pprint(client.getInfo(args[0],))
  121 +
  122 +elif cmd == 'buildOverview':
  123 + if len(args) != 1:
  124 + print('buildOverview requires 1 args')
  125 + sys.exit(1)
  126 + pp.pprint(client.buildOverview(args[0],))
  127 +
  128 +elif cmd == 'getImageList':
  129 + if len(args) != 1:
  130 + print('getImageList requires 1 args')
  131 + sys.exit(1)
  132 + pp.pprint(client.getImageList(args[0],))
  133 +
  134 +else:
  135 + print('Unrecognized method %s' % cmd)
  136 + sys.exit(1)
  137 +
  138 +transport.close()
  1 +#
  2 +# Autogenerated by Thrift Compiler (0.14.2)
  3 +#
  4 +# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
  5 +#
  6 +# options string: py
  7 +#
  8 +
  9 +from thrift.Thrift import TType, TMessageType, TFrozenDict, TException, TApplicationException
  10 +from thrift.protocol.TProtocol import TProtocolException
  11 +from thrift.TRecursive import fix_spec
  12 +
  13 +import sys
  14 +import logging
  15 +from .ttypes import *
  16 +from thrift.Thrift import TProcessor
  17 +from thrift.transport import TTransport
  18 +all_structs = []
  19 +
  20 +
  21 +class Iface(object):
  22 + """
  23 + Ahh, now onto the cool part, defining a service. Services just need a name
  24 + and can optionally inherit from another service using the extends keyword.
  25 +
  26 + """
  27 + def getData(self, path, queryRange, originRange, bands, width, height):
  28 + """
  29 + Parameters:
  30 + - path
  31 + - queryRange
  32 + - originRange
  33 + - bands
  34 + - width
  35 + - height
  36 +
  37 + """
  38 + pass
  39 +
  40 + def getInfo(self, path):
  41 + """
  42 + Parameters:
  43 + - path
  44 +
  45 + """
  46 + pass
  47 +
  48 + def buildOverview(self, path):
  49 + """
  50 + Parameters:
  51 + - path
  52 +
  53 + """
  54 + pass
  55 +
  56 + def getImageList(self, path):
  57 + """
  58 + Parameters:
  59 + - path
  60 +
  61 + """
  62 + pass
  63 +
  64 +
  65 +class Client(Iface):
  66 + """
  67 + Ahh, now onto the cool part, defining a service. Services just need a name
  68 + and can optionally inherit from another service using the extends keyword.
  69 +
  70 + """
  71 + def __init__(self, iprot, oprot=None):
  72 + self._iprot = self._oprot = iprot
  73 + if oprot is not None:
  74 + self._oprot = oprot
  75 + self._seqid = 0
  76 +
  77 + def getData(self, path, queryRange, originRange, bands, width, height):
  78 + """
  79 + Parameters:
  80 + - path
  81 + - queryRange
  82 + - originRange
  83 + - bands
  84 + - width
  85 + - height
  86 +
  87 + """
  88 + self.send_getData(path, queryRange, originRange, bands, width, height)
  89 + return self.recv_getData()
  90 +
  91 + def send_getData(self, path, queryRange, originRange, bands, width, height):
  92 + self._oprot.writeMessageBegin('getData', TMessageType.CALL, self._seqid)
  93 + args = getData_args()
  94 + args.path = path
  95 + args.queryRange = queryRange
  96 + args.originRange = originRange
  97 + args.bands = bands
  98 + args.width = width
  99 + args.height = height
  100 + args.write(self._oprot)
  101 + self._oprot.writeMessageEnd()
  102 + self._oprot.trans.flush()
  103 +
  104 + def recv_getData(self):
  105 + iprot = self._iprot
  106 + (fname, mtype, rseqid) = iprot.readMessageBegin()
  107 + if mtype == TMessageType.EXCEPTION:
  108 + x = TApplicationException()
  109 + x.read(iprot)
  110 + iprot.readMessageEnd()
  111 + raise x
  112 + result = getData_result()
  113 + result.read(iprot)
  114 + iprot.readMessageEnd()
  115 + if result.success is not None:
  116 + return result.success
  117 + raise TApplicationException(TApplicationException.MISSING_RESULT, "getData failed: unknown result")
  118 +
  119 + def getInfo(self, path):
  120 + """
  121 + Parameters:
  122 + - path
  123 +
  124 + """
  125 + self.send_getInfo(path)
  126 + return self.recv_getInfo()
  127 +
  128 + def send_getInfo(self, path):
  129 + self._oprot.writeMessageBegin('getInfo', TMessageType.CALL, self._seqid)
  130 + args = getInfo_args()
  131 + args.path = path
  132 + args.write(self._oprot)
  133 + self._oprot.writeMessageEnd()
  134 + self._oprot.trans.flush()
  135 +
  136 + def recv_getInfo(self):
  137 + iprot = self._iprot
  138 + (fname, mtype, rseqid) = iprot.readMessageBegin()
  139 + if mtype == TMessageType.EXCEPTION:
  140 + x = TApplicationException()
  141 + x.read(iprot)
  142 + iprot.readMessageEnd()
  143 + raise x
  144 + result = getInfo_result()
  145 + result.read(iprot)
  146 + iprot.readMessageEnd()
  147 + if result.success is not None:
  148 + return result.success
  149 + raise TApplicationException(TApplicationException.MISSING_RESULT, "getInfo failed: unknown result")
  150 +
  151 + def buildOverview(self, path):
  152 + """
  153 + Parameters:
  154 + - path
  155 +
  156 + """
  157 + self.send_buildOverview(path)
  158 + return self.recv_buildOverview()
  159 +
  160 + def send_buildOverview(self, path):
  161 + self._oprot.writeMessageBegin('buildOverview', TMessageType.CALL, self._seqid)
  162 + args = buildOverview_args()
  163 + args.path = path
  164 + args.write(self._oprot)
  165 + self._oprot.writeMessageEnd()
  166 + self._oprot.trans.flush()
  167 +
  168 + def recv_buildOverview(self):
  169 + iprot = self._iprot
  170 + (fname, mtype, rseqid) = iprot.readMessageBegin()
  171 + if mtype == TMessageType.EXCEPTION:
  172 + x = TApplicationException()
  173 + x.read(iprot)
  174 + iprot.readMessageEnd()
  175 + raise x
  176 + result = buildOverview_result()
  177 + result.read(iprot)
  178 + iprot.readMessageEnd()
  179 + if result.success is not None:
  180 + return result.success
  181 + raise TApplicationException(TApplicationException.MISSING_RESULT, "buildOverview failed: unknown result")
  182 +
  183 + def getImageList(self, path):
  184 + """
  185 + Parameters:
  186 + - path
  187 +
  188 + """
  189 + self.send_getImageList(path)
  190 + return self.recv_getImageList()
  191 +
  192 + def send_getImageList(self, path):
  193 + self._oprot.writeMessageBegin('getImageList', TMessageType.CALL, self._seqid)
  194 + args = getImageList_args()
  195 + args.path = path
  196 + args.write(self._oprot)
  197 + self._oprot.writeMessageEnd()
  198 + self._oprot.trans.flush()
  199 +
  200 + def recv_getImageList(self):
  201 + iprot = self._iprot
  202 + (fname, mtype, rseqid) = iprot.readMessageBegin()
  203 + if mtype == TMessageType.EXCEPTION:
  204 + x = TApplicationException()
  205 + x.read(iprot)
  206 + iprot.readMessageEnd()
  207 + raise x
  208 + result = getImageList_result()
  209 + result.read(iprot)
  210 + iprot.readMessageEnd()
  211 + if result.success is not None:
  212 + return result.success
  213 + raise TApplicationException(TApplicationException.MISSING_RESULT, "getImageList failed: unknown result")
  214 +
  215 +
  216 +class Processor(Iface, TProcessor):
  217 + def __init__(self, handler):
  218 + self._handler = handler
  219 + self._processMap = {}
  220 + self._processMap["getData"] = Processor.process_getData
  221 + self._processMap["getInfo"] = Processor.process_getInfo
  222 + self._processMap["buildOverview"] = Processor.process_buildOverview
  223 + self._processMap["getImageList"] = Processor.process_getImageList
  224 + self._on_message_begin = None
  225 +
  226 + def on_message_begin(self, func):
  227 + self._on_message_begin = func
  228 +
  229 + def process(self, iprot, oprot):
  230 + (name, type, seqid) = iprot.readMessageBegin()
  231 + if self._on_message_begin:
  232 + self._on_message_begin(name, type, seqid)
  233 + if name not in self._processMap:
  234 + iprot.skip(TType.STRUCT)
  235 + iprot.readMessageEnd()
  236 + x = TApplicationException(TApplicationException.UNKNOWN_METHOD, 'Unknown function %s' % (name))
  237 + oprot.writeMessageBegin(name, TMessageType.EXCEPTION, seqid)
  238 + x.write(oprot)
  239 + oprot.writeMessageEnd()
  240 + oprot.trans.flush()
  241 + return
  242 + else:
  243 + self._processMap[name](self, seqid, iprot, oprot)
  244 + return True
  245 +
  246 + def process_getData(self, seqid, iprot, oprot):
  247 + args = getData_args()
  248 + args.read(iprot)
  249 + iprot.readMessageEnd()
  250 + result = getData_result()
  251 + try:
  252 + result.success = self._handler.getData(args.path, args.queryRange, args.originRange, args.bands, args.width, args.height)
  253 + msg_type = TMessageType.REPLY
  254 + except TTransport.TTransportException:
  255 + raise
  256 + except TApplicationException as ex:
  257 + logging.exception('TApplication exception in handler')
  258 + msg_type = TMessageType.EXCEPTION
  259 + result = ex
  260 + except Exception:
  261 + logging.exception('Unexpected exception in handler')
  262 + msg_type = TMessageType.EXCEPTION
  263 + result = TApplicationException(TApplicationException.INTERNAL_ERROR, 'Internal error')
  264 + oprot.writeMessageBegin("getData", msg_type, seqid)
  265 + result.write(oprot)
  266 + oprot.writeMessageEnd()
  267 + oprot.trans.flush()
  268 +
  269 + def process_getInfo(self, seqid, iprot, oprot):
  270 + args = getInfo_args()
  271 + args.read(iprot)
  272 + iprot.readMessageEnd()
  273 + result = getInfo_result()
  274 + try:
  275 + result.success = self._handler.getInfo(args.path)
  276 + msg_type = TMessageType.REPLY
  277 + except TTransport.TTransportException:
  278 + raise
  279 + except TApplicationException as ex:
  280 + logging.exception('TApplication exception in handler')
  281 + msg_type = TMessageType.EXCEPTION
  282 + result = ex
  283 + except Exception:
  284 + logging.exception('Unexpected exception in handler')
  285 + msg_type = TMessageType.EXCEPTION
  286 + result = TApplicationException(TApplicationException.INTERNAL_ERROR, 'Internal error')
  287 + oprot.writeMessageBegin("getInfo", msg_type, seqid)
  288 + result.write(oprot)
  289 + oprot.writeMessageEnd()
  290 + oprot.trans.flush()
  291 +
  292 + def process_buildOverview(self, seqid, iprot, oprot):
  293 + args = buildOverview_args()
  294 + args.read(iprot)
  295 + iprot.readMessageEnd()
  296 + result = buildOverview_result()
  297 + try:
  298 + result.success = self._handler.buildOverview(args.path)
  299 + msg_type = TMessageType.REPLY
  300 + except TTransport.TTransportException:
  301 + raise
  302 + except TApplicationException as ex:
  303 + logging.exception('TApplication exception in handler')
  304 + msg_type = TMessageType.EXCEPTION
  305 + result = ex
  306 + except Exception:
  307 + logging.exception('Unexpected exception in handler')
  308 + msg_type = TMessageType.EXCEPTION
  309 + result = TApplicationException(TApplicationException.INTERNAL_ERROR, 'Internal error')
  310 + oprot.writeMessageBegin("buildOverview", msg_type, seqid)
  311 + result.write(oprot)
  312 + oprot.writeMessageEnd()
  313 + oprot.trans.flush()
  314 +
  315 + def process_getImageList(self, seqid, iprot, oprot):
  316 + args = getImageList_args()
  317 + args.read(iprot)
  318 + iprot.readMessageEnd()
  319 + result = getImageList_result()
  320 + try:
  321 + result.success = self._handler.getImageList(args.path)
  322 + msg_type = TMessageType.REPLY
  323 + except TTransport.TTransportException:
  324 + raise
  325 + except TApplicationException as ex:
  326 + logging.exception('TApplication exception in handler')
  327 + msg_type = TMessageType.EXCEPTION
  328 + result = ex
  329 + except Exception:
  330 + logging.exception('Unexpected exception in handler')
  331 + msg_type = TMessageType.EXCEPTION
  332 + result = TApplicationException(TApplicationException.INTERNAL_ERROR, 'Internal error')
  333 + oprot.writeMessageBegin("getImageList", msg_type, seqid)
  334 + result.write(oprot)
  335 + oprot.writeMessageEnd()
  336 + oprot.trans.flush()
  337 +
  338 +# HELPER FUNCTIONS AND STRUCTURES
  339 +
  340 +
  341 +class getData_args(object):
  342 + """
  343 + Attributes:
  344 + - path
  345 + - queryRange
  346 + - originRange
  347 + - bands
  348 + - width
  349 + - height
  350 +
  351 + """
  352 +
  353 +
  354 + def __init__(self, path=None, queryRange=None, originRange=None, bands=None, width=None, height=None,):
  355 + self.path = path
  356 + self.queryRange = queryRange
  357 + self.originRange = originRange
  358 + self.bands = bands
  359 + self.width = width
  360 + self.height = height
  361 +
  362 + def read(self, iprot):
  363 + if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None:
  364 + iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec])
  365 + return
  366 + iprot.readStructBegin()
  367 + while True:
  368 + (fname, ftype, fid) = iprot.readFieldBegin()
  369 + if ftype == TType.STOP:
  370 + break
  371 + if fid == 1:
  372 + if ftype == TType.STRING:
  373 + self.path = iprot.readString().decode('utf-8', errors='replace') if sys.version_info[0] == 2 else iprot.readString()
  374 + else:
  375 + iprot.skip(ftype)
  376 + elif fid == 2:
  377 + if ftype == TType.LIST:
  378 + self.queryRange = []
  379 + (_etype38, _size35) = iprot.readListBegin()
  380 + for _i39 in range(_size35):
  381 + _elem40 = iprot.readDouble()
  382 + self.queryRange.append(_elem40)
  383 + iprot.readListEnd()
  384 + else:
  385 + iprot.skip(ftype)
  386 + elif fid == 3:
  387 + if ftype == TType.LIST:
  388 + self.originRange = []
  389 + (_etype44, _size41) = iprot.readListBegin()
  390 + for _i45 in range(_size41):
  391 + _elem46 = iprot.readDouble()
  392 + self.originRange.append(_elem46)
  393 + iprot.readListEnd()
  394 + else:
  395 + iprot.skip(ftype)
  396 + elif fid == 4:
  397 + if ftype == TType.LIST:
  398 + self.bands = []
  399 + (_etype50, _size47) = iprot.readListBegin()
  400 + for _i51 in range(_size47):
  401 + _elem52 = iprot.readI32()
  402 + self.bands.append(_elem52)
  403 + iprot.readListEnd()
  404 + else:
  405 + iprot.skip(ftype)
  406 + elif fid == 5:
  407 + if ftype == TType.I32:
  408 + self.width = iprot.readI32()
  409 + else:
  410 + iprot.skip(ftype)
  411 + elif fid == 6:
  412 + if ftype == TType.I32:
  413 + self.height = iprot.readI32()
  414 + else:
  415 + iprot.skip(ftype)
  416 + else:
  417 + iprot.skip(ftype)
  418 + iprot.readFieldEnd()
  419 + iprot.readStructEnd()
  420 +
  421 + def write(self, oprot):
  422 + if oprot._fast_encode is not None and self.thrift_spec is not None:
  423 + oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec]))
  424 + return
  425 + oprot.writeStructBegin('getData_args')
  426 + if self.path is not None:
  427 + oprot.writeFieldBegin('path', TType.STRING, 1)
  428 + oprot.writeString(self.path.encode('utf-8') if sys.version_info[0] == 2 else self.path)
  429 + oprot.writeFieldEnd()
  430 + if self.queryRange is not None:
  431 + oprot.writeFieldBegin('queryRange', TType.LIST, 2)
  432 + oprot.writeListBegin(TType.DOUBLE, len(self.queryRange))
  433 + for iter53 in self.queryRange:
  434 + oprot.writeDouble(iter53)
  435 + oprot.writeListEnd()
  436 + oprot.writeFieldEnd()
  437 + if self.originRange is not None:
  438 + oprot.writeFieldBegin('originRange', TType.LIST, 3)
  439 + oprot.writeListBegin(TType.DOUBLE, len(self.originRange))
  440 + for iter54 in self.originRange:
  441 + oprot.writeDouble(iter54)
  442 + oprot.writeListEnd()
  443 + oprot.writeFieldEnd()
  444 + if self.bands is not None:
  445 + oprot.writeFieldBegin('bands', TType.LIST, 4)
  446 + oprot.writeListBegin(TType.I32, len(self.bands))
  447 + for iter55 in self.bands:
  448 + oprot.writeI32(iter55)
  449 + oprot.writeListEnd()
  450 + oprot.writeFieldEnd()
  451 + if self.width is not None:
  452 + oprot.writeFieldBegin('width', TType.I32, 5)
  453 + oprot.writeI32(self.width)
  454 + oprot.writeFieldEnd()
  455 + if self.height is not None:
  456 + oprot.writeFieldBegin('height', TType.I32, 6)
  457 + oprot.writeI32(self.height)
  458 + oprot.writeFieldEnd()
  459 + oprot.writeFieldStop()
  460 + oprot.writeStructEnd()
  461 +
  462 + def validate(self):
  463 + return
  464 +
  465 + def __repr__(self):
  466 + L = ['%s=%r' % (key, value)
  467 + for key, value in self.__dict__.items()]
  468 + return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
  469 +
  470 + def __eq__(self, other):
  471 + return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
  472 +
  473 + def __ne__(self, other):
  474 + return not (self == other)
  475 +all_structs.append(getData_args)
  476 +getData_args.thrift_spec = (
  477 + None, # 0
  478 + (1, TType.STRING, 'path', 'UTF8', None, ), # 1
  479 + (2, TType.LIST, 'queryRange', (TType.DOUBLE, None, False), None, ), # 2
  480 + (3, TType.LIST, 'originRange', (TType.DOUBLE, None, False), None, ), # 3
  481 + (4, TType.LIST, 'bands', (TType.I32, None, False), None, ), # 4
  482 + (5, TType.I32, 'width', None, None, ), # 5
  483 + (6, TType.I32, 'height', None, None, ), # 6
  484 +)
  485 +
  486 +
  487 +class getData_result(object):
  488 + """
  489 + Attributes:
  490 + - success
  491 +
  492 + """
  493 +
  494 +
  495 + def __init__(self, success=None,):
  496 + self.success = success
  497 +
  498 + def read(self, iprot):
  499 + if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None:
  500 + iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec])
  501 + return
  502 + iprot.readStructBegin()
  503 + while True:
  504 + (fname, ftype, fid) = iprot.readFieldBegin()
  505 + if ftype == TType.STOP:
  506 + break
  507 + if fid == 0:
  508 + if ftype == TType.STRUCT:
  509 + self.success = RasterData()
  510 + self.success.read(iprot)
  511 + else:
  512 + iprot.skip(ftype)
  513 + else:
  514 + iprot.skip(ftype)
  515 + iprot.readFieldEnd()
  516 + iprot.readStructEnd()
  517 +
  518 + def write(self, oprot):
  519 + if oprot._fast_encode is not None and self.thrift_spec is not None:
  520 + oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec]))
  521 + return
  522 + oprot.writeStructBegin('getData_result')
  523 + if self.success is not None:
  524 + oprot.writeFieldBegin('success', TType.STRUCT, 0)
  525 + self.success.write(oprot)
  526 + oprot.writeFieldEnd()
  527 + oprot.writeFieldStop()
  528 + oprot.writeStructEnd()
  529 +
  530 + def validate(self):
  531 + return
  532 +
  533 + def __repr__(self):
  534 + L = ['%s=%r' % (key, value)
  535 + for key, value in self.__dict__.items()]
  536 + return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
  537 +
  538 + def __eq__(self, other):
  539 + return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
  540 +
  541 + def __ne__(self, other):
  542 + return not (self == other)
  543 +all_structs.append(getData_result)
  544 +getData_result.thrift_spec = (
  545 + (0, TType.STRUCT, 'success', [RasterData, None], None, ), # 0
  546 +)
  547 +
  548 +
  549 +class getInfo_args(object):
  550 + """
  551 + Attributes:
  552 + - path
  553 +
  554 + """
  555 +
  556 +
  557 + def __init__(self, path=None,):
  558 + self.path = path
  559 +
  560 + def read(self, iprot):
  561 + if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None:
  562 + iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec])
  563 + return
  564 + iprot.readStructBegin()
  565 + while True:
  566 + (fname, ftype, fid) = iprot.readFieldBegin()
  567 + if ftype == TType.STOP:
  568 + break
  569 + if fid == 1:
  570 + if ftype == TType.STRING:
  571 + self.path = iprot.readString().decode('utf-8', errors='replace') if sys.version_info[0] == 2 else iprot.readString()
  572 + else:
  573 + iprot.skip(ftype)
  574 + else:
  575 + iprot.skip(ftype)
  576 + iprot.readFieldEnd()
  577 + iprot.readStructEnd()
  578 +
  579 + def write(self, oprot):
  580 + if oprot._fast_encode is not None and self.thrift_spec is not None:
  581 + oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec]))
  582 + return
  583 + oprot.writeStructBegin('getInfo_args')
  584 + if self.path is not None:
  585 + oprot.writeFieldBegin('path', TType.STRING, 1)
  586 + oprot.writeString(self.path.encode('utf-8') if sys.version_info[0] == 2 else self.path)
  587 + oprot.writeFieldEnd()
  588 + oprot.writeFieldStop()
  589 + oprot.writeStructEnd()
  590 +
  591 + def validate(self):
  592 + return
  593 +
  594 + def __repr__(self):
  595 + L = ['%s=%r' % (key, value)
  596 + for key, value in self.__dict__.items()]
  597 + return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
  598 +
  599 + def __eq__(self, other):
  600 + return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
  601 +
  602 + def __ne__(self, other):
  603 + return not (self == other)
  604 +all_structs.append(getInfo_args)
  605 +getInfo_args.thrift_spec = (
  606 + None, # 0
  607 + (1, TType.STRING, 'path', 'UTF8', None, ), # 1
  608 +)
  609 +
  610 +
  611 +class getInfo_result(object):
  612 + """
  613 + Attributes:
  614 + - success
  615 +
  616 + """
  617 +
  618 +
  619 + def __init__(self, success=None,):
  620 + self.success = success
  621 +
  622 + def read(self, iprot):
  623 + if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None:
  624 + iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec])
  625 + return
  626 + iprot.readStructBegin()
  627 + while True:
  628 + (fname, ftype, fid) = iprot.readFieldBegin()
  629 + if ftype == TType.STOP:
  630 + break
  631 + if fid == 0:
  632 + if ftype == TType.STRUCT:
  633 + self.success = Raster()
  634 + self.success.read(iprot)
  635 + else:
  636 + iprot.skip(ftype)
  637 + else:
  638 + iprot.skip(ftype)
  639 + iprot.readFieldEnd()
  640 + iprot.readStructEnd()
  641 +
  642 + def write(self, oprot):
  643 + if oprot._fast_encode is not None and self.thrift_spec is not None:
  644 + oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec]))
  645 + return
  646 + oprot.writeStructBegin('getInfo_result')
  647 + if self.success is not None:
  648 + oprot.writeFieldBegin('success', TType.STRUCT, 0)
  649 + self.success.write(oprot)
  650 + oprot.writeFieldEnd()
  651 + oprot.writeFieldStop()
  652 + oprot.writeStructEnd()
  653 +
  654 + def validate(self):
  655 + return
  656 +
  657 + def __repr__(self):
  658 + L = ['%s=%r' % (key, value)
  659 + for key, value in self.__dict__.items()]
  660 + return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
  661 +
  662 + def __eq__(self, other):
  663 + return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
  664 +
  665 + def __ne__(self, other):
  666 + return not (self == other)
  667 +all_structs.append(getInfo_result)
  668 +getInfo_result.thrift_spec = (
  669 + (0, TType.STRUCT, 'success', [Raster, None], None, ), # 0
  670 +)
  671 +
  672 +
  673 +class buildOverview_args(object):
  674 + """
  675 + Attributes:
  676 + - path
  677 +
  678 + """
  679 +
  680 +
  681 + def __init__(self, path=None,):
  682 + self.path = path
  683 +
  684 + def read(self, iprot):
  685 + if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None:
  686 + iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec])
  687 + return
  688 + iprot.readStructBegin()
  689 + while True:
  690 + (fname, ftype, fid) = iprot.readFieldBegin()
  691 + if ftype == TType.STOP:
  692 + break
  693 + if fid == 1:
  694 + if ftype == TType.STRING:
  695 + self.path = iprot.readString().decode('utf-8', errors='replace') if sys.version_info[0] == 2 else iprot.readString()
  696 + else:
  697 + iprot.skip(ftype)
  698 + else:
  699 + iprot.skip(ftype)
  700 + iprot.readFieldEnd()
  701 + iprot.readStructEnd()
  702 +
  703 + def write(self, oprot):
  704 + if oprot._fast_encode is not None and self.thrift_spec is not None:
  705 + oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec]))
  706 + return
  707 + oprot.writeStructBegin('buildOverview_args')
  708 + if self.path is not None:
  709 + oprot.writeFieldBegin('path', TType.STRING, 1)
  710 + oprot.writeString(self.path.encode('utf-8') if sys.version_info[0] == 2 else self.path)
  711 + oprot.writeFieldEnd()
  712 + oprot.writeFieldStop()
  713 + oprot.writeStructEnd()
  714 +
  715 + def validate(self):
  716 + return
  717 +
  718 + def __repr__(self):
  719 + L = ['%s=%r' % (key, value)
  720 + for key, value in self.__dict__.items()]
  721 + return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
  722 +
  723 + def __eq__(self, other):
  724 + return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
  725 +
  726 + def __ne__(self, other):
  727 + return not (self == other)
  728 +all_structs.append(buildOverview_args)
  729 +buildOverview_args.thrift_spec = (
  730 + None, # 0
  731 + (1, TType.STRING, 'path', 'UTF8', None, ), # 1
  732 +)
  733 +
  734 +
  735 +class buildOverview_result(object):
  736 + """
  737 + Attributes:
  738 + - success
  739 +
  740 + """
  741 +
  742 +
  743 + def __init__(self, success=None,):
  744 + self.success = success
  745 +
  746 + def read(self, iprot):
  747 + if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None:
  748 + iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec])
  749 + return
  750 + iprot.readStructBegin()
  751 + while True:
  752 + (fname, ftype, fid) = iprot.readFieldBegin()
  753 + if ftype == TType.STOP:
  754 + break
  755 + if fid == 0:
  756 + if ftype == TType.BOOL:
  757 + self.success = iprot.readBool()
  758 + else:
  759 + iprot.skip(ftype)
  760 + else:
  761 + iprot.skip(ftype)
  762 + iprot.readFieldEnd()
  763 + iprot.readStructEnd()
  764 +
  765 + def write(self, oprot):
  766 + if oprot._fast_encode is not None and self.thrift_spec is not None:
  767 + oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec]))
  768 + return
  769 + oprot.writeStructBegin('buildOverview_result')
  770 + if self.success is not None:
  771 + oprot.writeFieldBegin('success', TType.BOOL, 0)
  772 + oprot.writeBool(self.success)
  773 + oprot.writeFieldEnd()
  774 + oprot.writeFieldStop()
  775 + oprot.writeStructEnd()
  776 +
  777 + def validate(self):
  778 + return
  779 +
  780 + def __repr__(self):
  781 + L = ['%s=%r' % (key, value)
  782 + for key, value in self.__dict__.items()]
  783 + return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
  784 +
  785 + def __eq__(self, other):
  786 + return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
  787 +
  788 + def __ne__(self, other):
  789 + return not (self == other)
  790 +all_structs.append(buildOverview_result)
  791 +buildOverview_result.thrift_spec = (
  792 + (0, TType.BOOL, 'success', None, None, ), # 0
  793 +)
  794 +
  795 +
  796 +class getImageList_args(object):
  797 + """
  798 + Attributes:
  799 + - path
  800 +
  801 + """
  802 +
  803 +
  804 + def __init__(self, path=None,):
  805 + self.path = path
  806 +
  807 + def read(self, iprot):
  808 + if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None:
  809 + iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec])
  810 + return
  811 + iprot.readStructBegin()
  812 + while True:
  813 + (fname, ftype, fid) = iprot.readFieldBegin()
  814 + if ftype == TType.STOP:
  815 + break
  816 + if fid == 1:
  817 + if ftype == TType.STRING:
  818 + self.path = iprot.readString().decode('utf-8', errors='replace') if sys.version_info[0] == 2 else iprot.readString()
  819 + else:
  820 + iprot.skip(ftype)
  821 + else:
  822 + iprot.skip(ftype)
  823 + iprot.readFieldEnd()
  824 + iprot.readStructEnd()
  825 +
  826 + def write(self, oprot):
  827 + if oprot._fast_encode is not None and self.thrift_spec is not None:
  828 + oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec]))
  829 + return
  830 + oprot.writeStructBegin('getImageList_args')
  831 + if self.path is not None:
  832 + oprot.writeFieldBegin('path', TType.STRING, 1)
  833 + oprot.writeString(self.path.encode('utf-8') if sys.version_info[0] == 2 else self.path)
  834 + oprot.writeFieldEnd()
  835 + oprot.writeFieldStop()
  836 + oprot.writeStructEnd()
  837 +
  838 + def validate(self):
  839 + return
  840 +
  841 + def __repr__(self):
  842 + L = ['%s=%r' % (key, value)
  843 + for key, value in self.__dict__.items()]
  844 + return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
  845 +
  846 + def __eq__(self, other):
  847 + return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
  848 +
  849 + def __ne__(self, other):
  850 + return not (self == other)
  851 +all_structs.append(getImageList_args)
  852 +getImageList_args.thrift_spec = (
  853 + None, # 0
  854 + (1, TType.STRING, 'path', 'UTF8', None, ), # 1
  855 +)
  856 +
  857 +
  858 +class getImageList_result(object):
  859 + """
  860 + Attributes:
  861 + - success
  862 +
  863 + """
  864 +
  865 +
  866 + def __init__(self, success=None,):
  867 + self.success = success
  868 +
  869 + def read(self, iprot):
  870 + if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None:
  871 + iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec])
  872 + return
  873 + iprot.readStructBegin()
  874 + while True:
  875 + (fname, ftype, fid) = iprot.readFieldBegin()
  876 + if ftype == TType.STOP:
  877 + break
  878 + if fid == 0:
  879 + if ftype == TType.LIST:
  880 + self.success = []
  881 + (_etype59, _size56) = iprot.readListBegin()
  882 + for _i60 in range(_size56):
  883 + _elem61 = Image()
  884 + _elem61.read(iprot)
  885 + self.success.append(_elem61)
  886 + iprot.readListEnd()
  887 + else:
  888 + iprot.skip(ftype)
  889 + else:
  890 + iprot.skip(ftype)
  891 + iprot.readFieldEnd()
  892 + iprot.readStructEnd()
  893 +
  894 + def write(self, oprot):
  895 + if oprot._fast_encode is not None and self.thrift_spec is not None:
  896 + oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec]))
  897 + return
  898 + oprot.writeStructBegin('getImageList_result')
  899 + if self.success is not None:
  900 + oprot.writeFieldBegin('success', TType.LIST, 0)
  901 + oprot.writeListBegin(TType.STRUCT, len(self.success))
  902 + for iter62 in self.success:
  903 + iter62.write(oprot)
  904 + oprot.writeListEnd()
  905 + oprot.writeFieldEnd()
  906 + oprot.writeFieldStop()
  907 + oprot.writeStructEnd()
  908 +
  909 + def validate(self):
  910 + return
  911 +
  912 + def __repr__(self):
  913 + L = ['%s=%r' % (key, value)
  914 + for key, value in self.__dict__.items()]
  915 + return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
  916 +
  917 + def __eq__(self, other):
  918 + return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
  919 +
  920 + def __ne__(self, other):
  921 + return not (self == other)
  922 +all_structs.append(getImageList_result)
  923 +getImageList_result.thrift_spec = (
  924 + (0, TType.LIST, 'success', (TType.STRUCT, [Image, None], False), None, ), # 0
  925 +)
  926 +fix_spec(all_structs)
  927 +del all_structs
  1 +__all__ = ['ttypes', 'constants', 'Calculator']
  1 +#
  2 +# Autogenerated by Thrift Compiler (0.14.2)
  3 +#
  4 +# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
  5 +#
  6 +# options string: py
  7 +#
  8 +
  9 +from thrift.Thrift import TType, TMessageType, TFrozenDict, TException, TApplicationException
  10 +from thrift.protocol.TProtocol import TProtocolException
  11 +from thrift.TRecursive import fix_spec
  12 +
  13 +import sys
  14 +from .ttypes import *
  1 +# coding=utf-8
  2 +#author: 4N
  3 +#createtime: 2021/9/27
  4 +#email: nheweijun@sina.com
  5 +
  6 +
  7 +# from .ttypes import RasterData
  8 +
  9 +from thrift.transport import TSocket
  10 +from thrift.transport import TTransport
  11 +from thrift.protocol import TBinaryProtocol
  12 +from app.modules.service.image.ImageDataService import ImageDataService
  13 +from . import Calculator
  14 +
  15 +from struct import Struct
  16 +
  17 +host = 1
  18 +port = 9090
  19 +transport: TSocket = TSocket.TSocket(host, port)
  20 +transport = TTransport.TBufferedTransport(transport)
  21 +protocol = TBinaryProtocol.TBinaryProtocol(transport)
  22 +
  23 +client = Calculator.Client(protocol)
  24 +
  25 +
  26 +transport.open()
  27 +
  28 +test = client.getData("江南_01.tif",[1340.27, -1911.31, 4351.79, 5410.6],[1340.27, -1911.31, 4351.79, 5410.6],[3,2,1],768,768)
  29 +print(type(test))
  1 +#
  2 +# Autogenerated by Thrift Compiler (0.14.2)
  3 +#
  4 +# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
  5 +#
  6 +# options string: py
  7 +#
  8 +
  9 +from thrift.Thrift import TType, TMessageType, TFrozenDict, TException, TApplicationException
  10 +from thrift.protocol.TProtocol import TProtocolException
  11 +from thrift.TRecursive import fix_spec
  12 +
  13 +import sys
  14 +
  15 +from thrift.transport import TTransport
  16 +all_structs = []
  17 +
  18 +
  19 +class Image(object):
  20 + """
  21 + Structs are the basic complex data structures. They are comprised of fields
  22 + which each have an integer identifier, a type, a symbolic name, and an
  23 + optional default value.
  24 +
  25 + Fields can be declared "optional", which ensures they will not be included
  26 + in the serialized output if they aren't set. Note that this requires some
  27 + manual management in some languages.
  28 +
  29 + Attributes:
  30 + - name
  31 + - path
  32 + - size
  33 + - create_time
  34 + - type
  35 +
  36 + """
  37 +
  38 +
  39 + def __init__(self, name=None, path=None, size=None, create_time=None, type=None,):
  40 + self.name = name
  41 + self.path = path
  42 + self.size = size
  43 + self.create_time = create_time
  44 + self.type = type
  45 +
  46 + def read(self, iprot):
  47 + if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None:
  48 + iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec])
  49 + return
  50 + iprot.readStructBegin()
  51 + while True:
  52 + (fname, ftype, fid) = iprot.readFieldBegin()
  53 + if ftype == TType.STOP:
  54 + break
  55 + if fid == 1:
  56 + if ftype == TType.STRING:
  57 + self.name = iprot.readString().decode('utf-8', errors='replace') if sys.version_info[0] == 2 else iprot.readString()
  58 + else:
  59 + iprot.skip(ftype)
  60 + elif fid == 2:
  61 + if ftype == TType.STRING:
  62 + self.path = iprot.readString().decode('utf-8', errors='replace') if sys.version_info[0] == 2 else iprot.readString()
  63 + else:
  64 + iprot.skip(ftype)
  65 + elif fid == 3:
  66 + if ftype == TType.STRING:
  67 + self.size = iprot.readString().decode('utf-8', errors='replace') if sys.version_info[0] == 2 else iprot.readString()
  68 + else:
  69 + iprot.skip(ftype)
  70 + elif fid == 4:
  71 + if ftype == TType.STRING:
  72 + self.create_time = iprot.readString().decode('utf-8', errors='replace') if sys.version_info[0] == 2 else iprot.readString()
  73 + else:
  74 + iprot.skip(ftype)
  75 + elif fid == 5:
  76 + if ftype == TType.STRING:
  77 + self.type = iprot.readString().decode('utf-8', errors='replace') if sys.version_info[0] == 2 else iprot.readString()
  78 + else:
  79 + iprot.skip(ftype)
  80 + else:
  81 + iprot.skip(ftype)
  82 + iprot.readFieldEnd()
  83 + iprot.readStructEnd()
  84 +
  85 + def write(self, oprot):
  86 + if oprot._fast_encode is not None and self.thrift_spec is not None:
  87 + oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec]))
  88 + return
  89 + oprot.writeStructBegin('Image')
  90 + if self.name is not None:
  91 + oprot.writeFieldBegin('name', TType.STRING, 1)
  92 + oprot.writeString(self.name.encode('utf-8') if sys.version_info[0] == 2 else self.name)
  93 + oprot.writeFieldEnd()
  94 + if self.path is not None:
  95 + oprot.writeFieldBegin('path', TType.STRING, 2)
  96 + oprot.writeString(self.path.encode('utf-8') if sys.version_info[0] == 2 else self.path)
  97 + oprot.writeFieldEnd()
  98 + if self.size is not None:
  99 + oprot.writeFieldBegin('size', TType.STRING, 3)
  100 + oprot.writeString(self.size.encode('utf-8') if sys.version_info[0] == 2 else self.size)
  101 + oprot.writeFieldEnd()
  102 + if self.create_time is not None:
  103 + oprot.writeFieldBegin('create_time', TType.STRING, 4)
  104 + oprot.writeString(self.create_time.encode('utf-8') if sys.version_info[0] == 2 else self.create_time)
  105 + oprot.writeFieldEnd()
  106 + if self.type is not None:
  107 + oprot.writeFieldBegin('type', TType.STRING, 5)
  108 + oprot.writeString(self.type.encode('utf-8') if sys.version_info[0] == 2 else self.type)
  109 + oprot.writeFieldEnd()
  110 + oprot.writeFieldStop()
  111 + oprot.writeStructEnd()
  112 +
  113 + def validate(self):
  114 + return
  115 +
  116 + def __repr__(self):
  117 + L = ['%s=%r' % (key, value)
  118 + for key, value in self.__dict__.items()]
  119 + return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
  120 +
  121 + def __eq__(self, other):
  122 + return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
  123 +
  124 + def __ne__(self, other):
  125 + return not (self == other)
  126 +
  127 +
  128 +class RasterData(object):
  129 + """
  130 + Attributes:
  131 + - R
  132 + - G
  133 + - B
  134 +
  135 + """
  136 +
  137 +
  138 + def __init__(self, R=None, G=None, B=None,):
  139 + self.R = R
  140 + self.G = G
  141 + self.B = B
  142 +
  143 + def read(self, iprot):
  144 + if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None:
  145 + iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec])
  146 + return
  147 + iprot.readStructBegin()
  148 + while True:
  149 + (fname, ftype, fid) = iprot.readFieldBegin()
  150 + if ftype == TType.STOP:
  151 + break
  152 + if fid == 1:
  153 + if ftype == TType.LIST:
  154 + self.R = []
  155 + (_etype3, _size0) = iprot.readListBegin()
  156 + for _i4 in range(_size0):
  157 + _elem5 = iprot.readI16()
  158 + self.R.append(_elem5)
  159 + iprot.readListEnd()
  160 + else:
  161 + iprot.skip(ftype)
  162 + elif fid == 2:
  163 + if ftype == TType.LIST:
  164 + self.G = []
  165 + (_etype9, _size6) = iprot.readListBegin()
  166 + for _i10 in range(_size6):
  167 + _elem11 = iprot.readI16()
  168 + self.G.append(_elem11)
  169 + iprot.readListEnd()
  170 + else:
  171 + iprot.skip(ftype)
  172 + elif fid == 3:
  173 + if ftype == TType.LIST:
  174 + self.B = []
  175 + (_etype15, _size12) = iprot.readListBegin()
  176 + for _i16 in range(_size12):
  177 + _elem17 = iprot.readI16()
  178 + self.B.append(_elem17)
  179 + iprot.readListEnd()
  180 + else:
  181 + iprot.skip(ftype)
  182 + else:
  183 + iprot.skip(ftype)
  184 + iprot.readFieldEnd()
  185 + iprot.readStructEnd()
  186 +
  187 + def write(self, oprot):
  188 + if oprot._fast_encode is not None and self.thrift_spec is not None:
  189 + oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec]))
  190 + return
  191 + oprot.writeStructBegin('RasterData')
  192 + if self.R is not None:
  193 + oprot.writeFieldBegin('R', TType.LIST, 1)
  194 + oprot.writeListBegin(TType.I16, len(self.R))
  195 + for iter18 in self.R:
  196 + oprot.writeI16(iter18)
  197 + oprot.writeListEnd()
  198 + oprot.writeFieldEnd()
  199 + if self.G is not None:
  200 + oprot.writeFieldBegin('G', TType.LIST, 2)
  201 + oprot.writeListBegin(TType.I16, len(self.G))
  202 + for iter19 in self.G:
  203 + oprot.writeI16(iter19)
  204 + oprot.writeListEnd()
  205 + oprot.writeFieldEnd()
  206 + if self.B is not None:
  207 + oprot.writeFieldBegin('B', TType.LIST, 3)
  208 + oprot.writeListBegin(TType.I16, len(self.B))
  209 + for iter20 in self.B:
  210 + oprot.writeI16(iter20)
  211 + oprot.writeListEnd()
  212 + oprot.writeFieldEnd()
  213 + oprot.writeFieldStop()
  214 + oprot.writeStructEnd()
  215 +
  216 + def validate(self):
  217 + return
  218 +
  219 + def __repr__(self):
  220 + L = ['%s=%r' % (key, value)
  221 + for key, value in self.__dict__.items()]
  222 + return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
  223 +
  224 + def __eq__(self, other):
  225 + return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
  226 +
  227 + def __ne__(self, other):
  228 + return not (self == other)
  229 +
  230 +
  231 +class Raster(object):
  232 + """
  233 + Attributes:
  234 + - band_count
  235 + - overview_count
  236 + - xy_size
  237 + - origin_extent
  238 + - null_value
  239 + - sr_wkt
  240 + - epsg
  241 + - sr_proj4
  242 + - size
  243 + - path
  244 + - cell_x_size
  245 + - cell_y_size
  246 +
  247 + """
  248 +
  249 +
  250 + def __init__(self, band_count=None, overview_count=None, xy_size=None, origin_extent=None, null_value=None, sr_wkt=None, epsg=None, sr_proj4=None, size=None, path=None, cell_x_size=None, cell_y_size=None,):
  251 + self.band_count = band_count
  252 + self.overview_count = overview_count
  253 + self.xy_size = xy_size
  254 + self.origin_extent = origin_extent
  255 + self.null_value = null_value
  256 + self.sr_wkt = sr_wkt
  257 + self.epsg = epsg
  258 + self.sr_proj4 = sr_proj4
  259 + self.size = size
  260 + self.path = path
  261 + self.cell_x_size = cell_x_size
  262 + self.cell_y_size = cell_y_size
  263 +
  264 + def read(self, iprot):
  265 + if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None:
  266 + iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec])
  267 + return
  268 + iprot.readStructBegin()
  269 + while True:
  270 + (fname, ftype, fid) = iprot.readFieldBegin()
  271 + if ftype == TType.STOP:
  272 + break
  273 + if fid == 1:
  274 + if ftype == TType.I32:
  275 + self.band_count = iprot.readI32()
  276 + else:
  277 + iprot.skip(ftype)
  278 + elif fid == 2:
  279 + if ftype == TType.I32:
  280 + self.overview_count = iprot.readI32()
  281 + else:
  282 + iprot.skip(ftype)
  283 + elif fid == 3:
  284 + if ftype == TType.LIST:
  285 + self.xy_size = []
  286 + (_etype24, _size21) = iprot.readListBegin()
  287 + for _i25 in range(_size21):
  288 + _elem26 = iprot.readI32()
  289 + self.xy_size.append(_elem26)
  290 + iprot.readListEnd()
  291 + else:
  292 + iprot.skip(ftype)
  293 + elif fid == 4:
  294 + if ftype == TType.LIST:
  295 + self.origin_extent = []
  296 + (_etype30, _size27) = iprot.readListBegin()
  297 + for _i31 in range(_size27):
  298 + _elem32 = iprot.readDouble()
  299 + self.origin_extent.append(_elem32)
  300 + iprot.readListEnd()
  301 + else:
  302 + iprot.skip(ftype)
  303 + elif fid == 5:
  304 + if ftype == TType.DOUBLE:
  305 + self.null_value = iprot.readDouble()
  306 + else:
  307 + iprot.skip(ftype)
  308 + elif fid == 6:
  309 + if ftype == TType.STRING:
  310 + self.sr_wkt = iprot.readString().decode('utf-8', errors='replace') if sys.version_info[0] == 2 else iprot.readString()
  311 + else:
  312 + iprot.skip(ftype)
  313 + elif fid == 7:
  314 + if ftype == TType.STRING:
  315 + self.epsg = iprot.readString().decode('utf-8', errors='replace') if sys.version_info[0] == 2 else iprot.readString()
  316 + else:
  317 + iprot.skip(ftype)
  318 + elif fid == 8:
  319 + if ftype == TType.STRING:
  320 + self.sr_proj4 = iprot.readString().decode('utf-8', errors='replace') if sys.version_info[0] == 2 else iprot.readString()
  321 + else:
  322 + iprot.skip(ftype)
  323 + elif fid == 9:
  324 + if ftype == TType.I32:
  325 + self.size = iprot.readI32()
  326 + else:
  327 + iprot.skip(ftype)
  328 + elif fid == 10:
  329 + if ftype == TType.STRING:
  330 + self.path = iprot.readString().decode('utf-8', errors='replace') if sys.version_info[0] == 2 else iprot.readString()
  331 + else:
  332 + iprot.skip(ftype)
  333 + elif fid == 11:
  334 + if ftype == TType.DOUBLE:
  335 + self.cell_x_size = iprot.readDouble()
  336 + else:
  337 + iprot.skip(ftype)
  338 + elif fid == 12:
  339 + if ftype == TType.DOUBLE:
  340 + self.cell_y_size = iprot.readDouble()
  341 + else:
  342 + iprot.skip(ftype)
  343 + else:
  344 + iprot.skip(ftype)
  345 + iprot.readFieldEnd()
  346 + iprot.readStructEnd()
  347 +
  348 + def write(self, oprot):
  349 + if oprot._fast_encode is not None and self.thrift_spec is not None:
  350 + oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec]))
  351 + return
  352 + oprot.writeStructBegin('Raster')
  353 + if self.band_count is not None:
  354 + oprot.writeFieldBegin('band_count', TType.I32, 1)
  355 + oprot.writeI32(self.band_count)
  356 + oprot.writeFieldEnd()
  357 + if self.overview_count is not None:
  358 + oprot.writeFieldBegin('overview_count', TType.I32, 2)
  359 + oprot.writeI32(self.overview_count)
  360 + oprot.writeFieldEnd()
  361 + if self.xy_size is not None:
  362 + oprot.writeFieldBegin('xy_size', TType.LIST, 3)
  363 + oprot.writeListBegin(TType.I32, len(self.xy_size))
  364 + for iter33 in self.xy_size:
  365 + oprot.writeI32(iter33)
  366 + oprot.writeListEnd()
  367 + oprot.writeFieldEnd()
  368 + if self.origin_extent is not None:
  369 + oprot.writeFieldBegin('origin_extent', TType.LIST, 4)
  370 + oprot.writeListBegin(TType.DOUBLE, len(self.origin_extent))
  371 + for iter34 in self.origin_extent:
  372 + oprot.writeDouble(iter34)
  373 + oprot.writeListEnd()
  374 + oprot.writeFieldEnd()
  375 + if self.null_value is not None:
  376 + oprot.writeFieldBegin('null_value', TType.DOUBLE, 5)
  377 + oprot.writeDouble(self.null_value)
  378 + oprot.writeFieldEnd()
  379 + if self.sr_wkt is not None:
  380 + oprot.writeFieldBegin('sr_wkt', TType.STRING, 6)
  381 + oprot.writeString(self.sr_wkt.encode('utf-8') if sys.version_info[0] == 2 else self.sr_wkt)
  382 + oprot.writeFieldEnd()
  383 + if self.epsg is not None:
  384 + oprot.writeFieldBegin('epsg', TType.STRING, 7)
  385 + oprot.writeString(self.epsg.encode('utf-8') if sys.version_info[0] == 2 else self.epsg)
  386 + oprot.writeFieldEnd()
  387 + if self.sr_proj4 is not None:
  388 + oprot.writeFieldBegin('sr_proj4', TType.STRING, 8)
  389 + oprot.writeString(self.sr_proj4.encode('utf-8') if sys.version_info[0] == 2 else self.sr_proj4)
  390 + oprot.writeFieldEnd()
  391 + if self.size is not None:
  392 + oprot.writeFieldBegin('size', TType.I32, 9)
  393 + oprot.writeI32(self.size)
  394 + oprot.writeFieldEnd()
  395 + if self.path is not None:
  396 + oprot.writeFieldBegin('path', TType.STRING, 10)
  397 + oprot.writeString(self.path.encode('utf-8') if sys.version_info[0] == 2 else self.path)
  398 + oprot.writeFieldEnd()
  399 + if self.cell_x_size is not None:
  400 + oprot.writeFieldBegin('cell_x_size', TType.DOUBLE, 11)
  401 + oprot.writeDouble(self.cell_x_size)
  402 + oprot.writeFieldEnd()
  403 + if self.cell_y_size is not None:
  404 + oprot.writeFieldBegin('cell_y_size', TType.DOUBLE, 12)
  405 + oprot.writeDouble(self.cell_y_size)
  406 + oprot.writeFieldEnd()
  407 + oprot.writeFieldStop()
  408 + oprot.writeStructEnd()
  409 +
  410 + def validate(self):
  411 + return
  412 +
  413 + def __repr__(self):
  414 + L = ['%s=%r' % (key, value)
  415 + for key, value in self.__dict__.items()]
  416 + return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
  417 +
  418 + def __eq__(self, other):
  419 + return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
  420 +
  421 + def __ne__(self, other):
  422 + return not (self == other)
  423 +
  424 +
  425 +class InvalidOperation(TException):
  426 + """
  427 + Structs can also be exceptions, if they are nasty.
  428 +
  429 + Attributes:
  430 + - whatOp
  431 + - why
  432 +
  433 + """
  434 +
  435 +
  436 + def __init__(self, whatOp=None, why=None,):
  437 + super(InvalidOperation, self).__setattr__('whatOp', whatOp)
  438 + super(InvalidOperation, self).__setattr__('why', why)
  439 +
  440 + def __setattr__(self, *args):
  441 + raise TypeError("can't modify immutable instance")
  442 +
  443 + def __delattr__(self, *args):
  444 + raise TypeError("can't modify immutable instance")
  445 +
  446 + def __hash__(self):
  447 + return hash(self.__class__) ^ hash((self.whatOp, self.why, ))
  448 +
  449 + @classmethod
  450 + def read(cls, iprot):
  451 + if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and cls.thrift_spec is not None:
  452 + return iprot._fast_decode(None, iprot, [cls, cls.thrift_spec])
  453 + iprot.readStructBegin()
  454 + whatOp = None
  455 + why = None
  456 + while True:
  457 + (fname, ftype, fid) = iprot.readFieldBegin()
  458 + if ftype == TType.STOP:
  459 + break
  460 + if fid == 1:
  461 + if ftype == TType.I32:
  462 + whatOp = iprot.readI32()
  463 + else:
  464 + iprot.skip(ftype)
  465 + elif fid == 2:
  466 + if ftype == TType.STRING:
  467 + why = iprot.readString().decode('utf-8', errors='replace') if sys.version_info[0] == 2 else iprot.readString()
  468 + else:
  469 + iprot.skip(ftype)
  470 + else:
  471 + iprot.skip(ftype)
  472 + iprot.readFieldEnd()
  473 + iprot.readStructEnd()
  474 + return cls(
  475 + whatOp=whatOp,
  476 + why=why,
  477 + )
  478 +
  479 + def write(self, oprot):
  480 + if oprot._fast_encode is not None and self.thrift_spec is not None:
  481 + oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec]))
  482 + return
  483 + oprot.writeStructBegin('InvalidOperation')
  484 + if self.whatOp is not None:
  485 + oprot.writeFieldBegin('whatOp', TType.I32, 1)
  486 + oprot.writeI32(self.whatOp)
  487 + oprot.writeFieldEnd()
  488 + if self.why is not None:
  489 + oprot.writeFieldBegin('why', TType.STRING, 2)
  490 + oprot.writeString(self.why.encode('utf-8') if sys.version_info[0] == 2 else self.why)
  491 + oprot.writeFieldEnd()
  492 + oprot.writeFieldStop()
  493 + oprot.writeStructEnd()
  494 +
  495 + def validate(self):
  496 + return
  497 +
  498 + def __str__(self):
  499 + return repr(self)
  500 +
  501 + def __repr__(self):
  502 + L = ['%s=%r' % (key, value)
  503 + for key, value in self.__dict__.items()]
  504 + return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
  505 +
  506 + def __eq__(self, other):
  507 + return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
  508 +
  509 + def __ne__(self, other):
  510 + return not (self == other)
  511 +all_structs.append(Image)
  512 +Image.thrift_spec = (
  513 + None, # 0
  514 + (1, TType.STRING, 'name', 'UTF8', None, ), # 1
  515 + (2, TType.STRING, 'path', 'UTF8', None, ), # 2
  516 + (3, TType.STRING, 'size', 'UTF8', None, ), # 3
  517 + (4, TType.STRING, 'create_time', 'UTF8', None, ), # 4
  518 + (5, TType.STRING, 'type', 'UTF8', None, ), # 5
  519 +)
  520 +all_structs.append(RasterData)
  521 +RasterData.thrift_spec = (
  522 + None, # 0
  523 + (1, TType.LIST, 'R', (TType.I16, None, False), None, ), # 1
  524 + (2, TType.LIST, 'G', (TType.I16, None, False), None, ), # 2
  525 + (3, TType.LIST, 'B', (TType.I16, None, False), None, ), # 3
  526 +)
  527 +all_structs.append(Raster)
  528 +Raster.thrift_spec = (
  529 + None, # 0
  530 + (1, TType.I32, 'band_count', None, None, ), # 1
  531 + (2, TType.I32, 'overview_count', None, None, ), # 2
  532 + (3, TType.LIST, 'xy_size', (TType.I32, None, False), None, ), # 3
  533 + (4, TType.LIST, 'origin_extent', (TType.DOUBLE, None, False), None, ), # 4
  534 + (5, TType.DOUBLE, 'null_value', None, None, ), # 5
  535 + (6, TType.STRING, 'sr_wkt', 'UTF8', None, ), # 6
  536 + (7, TType.STRING, 'epsg', 'UTF8', None, ), # 7
  537 + (8, TType.STRING, 'sr_proj4', 'UTF8', None, ), # 8
  538 + (9, TType.I32, 'size', None, None, ), # 9
  539 + (10, TType.STRING, 'path', 'UTF8', None, ), # 10
  540 + (11, TType.DOUBLE, 'cell_x_size', None, None, ), # 11
  541 + (12, TType.DOUBLE, 'cell_y_size', None, None, ), # 12
  542 +)
  543 +all_structs.append(InvalidOperation)
  544 +InvalidOperation.thrift_spec = (
  545 + None, # 0
  546 + (1, TType.I32, 'whatOp', None, None, ), # 1
  547 + (2, TType.STRING, 'why', 'UTF8', None, ), # 2
  548 +)
  549 +fix_spec(all_structs)
  550 +del all_structs
@@ -26,4 +26,7 @@ class ThriftConnect: @@ -26,4 +26,7 @@ class ThriftConnect:
26 self.transport.open() 26 self.transport.open()
27 27
28 def close(self): 28 def close(self):
29 - self.transport.close()  
  29 + self.transport.close()
  30 +
  31 +class ThriftPool:
  32 + pass
@@ -24,6 +24,8 @@ class Api(ApiTemplate): @@ -24,6 +24,8 @@ class Api(ApiTemplate):
24 # extent = [float(x) for x in data.get("extent").split(",")] if data.get("extent") else [0,0,0,0] 24 # extent = [float(x) for x in data.get("extent").split(",")] if data.get("extent") else [0,0,0,0]
25 # top_left = [float(x) for x in data.get("top_left").split(",")] if data.get("top_left") else [0, 0] 25 # top_left = [float(x) for x in data.get("top_left").split(",")] if data.get("top_left") else [0, 0]
26 26
  27 +
  28 +
27 guid = uuid.uuid1().__str__() 29 guid = uuid.uuid1().__str__()
28 tile_scheme = TileScheme( 30 tile_scheme = TileScheme(
29 guid = guid, 31 guid = guid,
@@ -39,11 +41,12 @@ class Api(ApiTemplate): @@ -39,11 +41,12 @@ class Api(ApiTemplate):
39 # ymax = extent[3], 41 # ymax = extent[3],
40 # origin_x = top_left[0], 42 # origin_x = top_left[0],
41 # origin_y = top_left[1], 43 # origin_y = top_left[1],
42 - levels = json.dumps(data.get("levels")), 44 + levels = json.dumps(json.loads(data.get("levels"))),
43 dpi = int(data.get("dpi")), 45 dpi = int(data.get("dpi")),
44 rows = int(data.get("rows")), 46 rows = int(data.get("rows")),
45 - cols = int(data.get("clos")),  
46 - update_time = datetime.datetime.now() 47 + cols = int(data.get("cols")),
  48 + update_time = datetime.datetime.now(),
  49 + parameter=json.dumps(json.loads(data.get("parameter")))
47 ) 50 )
48 51
49 db.session.add(tile_scheme) 52 db.session.add(tile_scheme)
@@ -89,6 +92,9 @@ class Api(ApiTemplate): @@ -89,6 +92,9 @@ class Api(ApiTemplate):
89 {"name": "levels", 92 {"name": "levels",
90 "in": "formData", 93 "in": "formData",
91 "type": "string"}, 94 "type": "string"},
  95 + {"name": "parameter",
  96 + "in": "formData",
  97 + "type": "string"},
92 98
93 ], 99 ],
94 "responses": { 100 "responses": {
@@ -10,6 +10,7 @@ from app.util.component.FileProcess import FileProcess @@ -10,6 +10,7 @@ from app.util.component.FileProcess import FileProcess
10 from app.util.component.SliceScheme import SliceScheme 10 from app.util.component.SliceScheme import SliceScheme
11 import shutil 11 import shutil
12 from app.util.component.StructuredPrint import StructurePrint 12 from app.util.component.StructuredPrint import StructurePrint
  13 +import json
13 class Api(ApiTemplate): 14 class Api(ApiTemplate):
14 api_name = "解析方案" 15 api_name = "解析方案"
15 16
@@ -30,7 +31,8 @@ class Api(ApiTemplate): @@ -30,7 +31,8 @@ class Api(ApiTemplate):
30 "dpi": scheme.parameter.get("dpi"), 31 "dpi": scheme.parameter.get("dpi"),
31 "rows": scheme.parameter.get("rows"), 32 "rows": scheme.parameter.get("rows"),
32 "cols": scheme.parameter.get("cols"), 33 "cols": scheme.parameter.get("cols"),
33 - "levels": scheme.levels 34 + "levels": scheme.levels,
  35 + "parameter":scheme.parameter
34 } 36 }
35 37
36 res["data"] = data 38 res["data"] = data
@@ -47,11 +49,11 @@ class Api(ApiTemplate): @@ -47,11 +49,11 @@ class Api(ApiTemplate):
47 i+=1 49 i+=1
48 if i<30: 50 if i<30:
49 shutil.rmtree(dir_path,True) 51 shutil.rmtree(dir_path,True)
50 - StructurePrint.print("删除文件成功!") 52 + StructurePrint().print("删除文件成功!")
51 else: 53 else:
52 raise Exception("找不到文件!") 54 raise Exception("找不到文件!")
53 except Exception as e: 55 except Exception as e:
54 - StructurePrint.print("删除文件失败!","ERROR") 56 + StructurePrint().print("删除文件失败!","ERROR")
55 return res 57 return res
56 58
57 api_doc = { 59 api_doc = {
  1 +<?xml version="1.0" encoding="utf-8" ?>
  2 +<TileCacheInfo xmlns:typens="http://www.esri.com/schemas/ArcGIS/10.1" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="typens:TileCacheInfo">
  3 + <SpatialReference xsi:type="typens:GeographicCoordinateSystem">
  4 + <WKT>GEOGCS[&quot;GCS_China_Geodetic_Coordinate_System_2000&quot;,DATUM[&quot;D_China_2000&quot;,SPHEROID[&quot;CGCS2000&quot;,6378137.0,298.257222101]],PRIMEM[&quot;Greenwich&quot;,0.0],UNIT[&quot;Degree&quot;,0.0174532925199433],AUTHORITY[&quot;EPSG&quot;,4490]]</WKT>
  5 + <XOrigin>-400</XOrigin>
  6 + <YOrigin>-400</YOrigin>
  7 + <XYScale>11258999068426.24</XYScale>
  8 + <ZOrigin>0</ZOrigin>
  9 + <ZScale>1</ZScale>
  10 + <MOrigin>-100000</MOrigin>
  11 + <MScale>10000</MScale>
  12 + <XYTolerance>8.98315284119521e-009</XYTolerance>
  13 + <ZTolerance>2</ZTolerance>
  14 + <MTolerance>0.001</MTolerance>
  15 + <HighPrecision>true</HighPrecision>
  16 + <LeftLongitude>-180</LeftLongitude>
  17 + <WKID>4490</WKID>
  18 + <LatestWKID>4490</LatestWKID>
  19 + </SpatialReference>
  20 + <TileOrigin xsi:type="typens:PointN">
  21 + <X>-180</X>
  22 + <Y>90</Y>
  23 + </TileOrigin>
  24 + <TileCols>256</TileCols>
  25 + <TileRows>256</TileRows>
  26 + <DPI>96</DPI>
  27 + <PreciseDPI>96</PreciseDPI>
  28 + <LODInfos xsi:type="typens:ArrayOfLODInfo">
  29 + <LODInfo xsi:type="typens:LODInfo">
  30 + <LevelID>0</LevelID>
  31 + <Scale>295497593.05875003</Scale>
  32 + <Resolution>0.70312500000000022</Resolution>
  33 + </LODInfo>
  34 + <LODInfo xsi:type="typens:LODInfo">
  35 + <LevelID>1</LevelID>
  36 + <Scale>147748796.52937502</Scale>
  37 + <Resolution>0.35156250000000011</Resolution>
  38 + </LODInfo>
  39 + <LODInfo xsi:type="typens:LODInfo">
  40 + <LevelID>2</LevelID>
  41 + <Scale>73874398.264687508</Scale>
  42 + <Resolution>0.17578125000000006</Resolution>
  43 + </LODInfo>
  44 + <LODInfo xsi:type="typens:LODInfo">
  45 + <LevelID>3</LevelID>
  46 + <Scale>36937199.132343754</Scale>
  47 + <Resolution>0.087890625000000028</Resolution>
  48 + </LODInfo>
  49 + <LODInfo xsi:type="typens:LODInfo">
  50 + <LevelID>4</LevelID>
  51 + <Scale>18468599.566171877</Scale>
  52 + <Resolution>0.043945312500000014</Resolution>
  53 + </LODInfo>
  54 + <LODInfo xsi:type="typens:LODInfo">
  55 + <LevelID>5</LevelID>
  56 + <Scale>9234299.7830859385</Scale>
  57 + <Resolution>0.021972656250000007</Resolution>
  58 + </LODInfo>
  59 + <LODInfo xsi:type="typens:LODInfo">
  60 + <LevelID>6</LevelID>
  61 + <Scale>4617149.8915429693</Scale>
  62 + <Resolution>0.010986328125000003</Resolution>
  63 + </LODInfo>
  64 + <LODInfo xsi:type="typens:LODInfo">
  65 + <LevelID>7</LevelID>
  66 + <Scale>2308574.9457714846</Scale>
  67 + <Resolution>0.0054931640625000017</Resolution>
  68 + </LODInfo>
  69 + <LODInfo xsi:type="typens:LODInfo">
  70 + <LevelID>8</LevelID>
  71 + <Scale>1154287.4728857423</Scale>
  72 + <Resolution>0.0027465820312500009</Resolution>
  73 + </LODInfo>
  74 + <LODInfo xsi:type="typens:LODInfo">
  75 + <LevelID>9</LevelID>
  76 + <Scale>577143.73644287116</Scale>
  77 + <Resolution>0.0013732910156250004</Resolution>
  78 + </LODInfo>
  79 + <LODInfo xsi:type="typens:LODInfo">
  80 + <LevelID>10</LevelID>
  81 + <Scale>288571.86822143558</Scale>
  82 + <Resolution>0.00068664550781250022</Resolution>
  83 + </LODInfo>
  84 + <LODInfo xsi:type="typens:LODInfo">
  85 + <LevelID>11</LevelID>
  86 + <Scale>144285.93411071779</Scale>
  87 + <Resolution>0.00034332275390625011</Resolution>
  88 + </LODInfo>
  89 + <LODInfo xsi:type="typens:LODInfo">
  90 + <LevelID>12</LevelID>
  91 + <Scale>72142.967055358895</Scale>
  92 + <Resolution>0.00017166137695312505</Resolution>
  93 + </LODInfo>
  94 + <LODInfo xsi:type="typens:LODInfo">
  95 + <LevelID>13</LevelID>
  96 + <Scale>36071.483527679447</Scale>
  97 + <Resolution>8.5830688476562527e-005</Resolution>
  98 + </LODInfo>
  99 + <LODInfo xsi:type="typens:LODInfo">
  100 + <LevelID>14</LevelID>
  101 + <Scale>18035.741763839724</Scale>
  102 + <Resolution>4.2915344238281264e-005</Resolution>
  103 + </LODInfo>
  104 + <LODInfo xsi:type="typens:LODInfo">
  105 + <LevelID>15</LevelID>
  106 + <Scale>9017.8708819198619</Scale>
  107 + <Resolution>2.1457672119140632e-005</Resolution>
  108 + </LODInfo>
  109 + <LODInfo xsi:type="typens:LODInfo">
  110 + <LevelID>16</LevelID>
  111 + <Scale>4508.9354409599309</Scale>
  112 + <Resolution>1.0728836059570316e-005</Resolution>
  113 + </LODInfo>
  114 + <LODInfo xsi:type="typens:LODInfo">
  115 + <LevelID>17</LevelID>
  116 + <Scale>2254.4677204799655</Scale>
  117 + <Resolution>5.3644180297851579e-006</Resolution>
  118 + </LODInfo>
  119 + <LODInfo xsi:type="typens:LODInfo">
  120 + <LevelID>18</LevelID>
  121 + <Scale>1127.2338602399827</Scale>
  122 + <Resolution>2.682209014892579e-006</Resolution>
  123 + </LODInfo>
  124 + <LODInfo xsi:type="typens:LODInfo">
  125 + <LevelID>19</LevelID>
  126 + <Scale>563.61693011999137</Scale>
  127 + <Resolution>1.3411045074462895e-006</Resolution>
  128 + </LODInfo>
  129 + </LODInfos>
  130 +</TileCacheInfo>
  1 +<?xml version="1.0" encoding="utf-8" ?>
  2 +<TileCacheInfo xmlns:typens="http://www.esri.com/schemas/ArcGIS/10.1" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="typens:TileCacheInfo">
  3 + <SpatialReference xsi:type="typens:GeographicCoordinateSystem">
  4 + <WKT>GEOGCS[&quot;GCS_China_Geodetic_Coordinate_System_2000&quot;,DATUM[&quot;D_China_2000&quot;,SPHEROID[&quot;CGCS2000&quot;,6378137.0,298.257222101]],PRIMEM[&quot;Greenwich&quot;,0.0],UNIT[&quot;Degree&quot;,0.0174532925199433],AUTHORITY[&quot;EPSG&quot;,4490]]</WKT>
  5 + <XOrigin>-400</XOrigin>
  6 + <YOrigin>-400</YOrigin>
  7 + <XYScale>11258999068426.24</XYScale>
  8 + <ZOrigin>0</ZOrigin>
  9 + <ZScale>1</ZScale>
  10 + <MOrigin>-100000</MOrigin>
  11 + <MScale>10000</MScale>
  12 + <XYTolerance>8.98315284119521e-009</XYTolerance>
  13 + <ZTolerance>2</ZTolerance>
  14 + <MTolerance>0.001</MTolerance>
  15 + <HighPrecision>true</HighPrecision>
  16 + <LeftLongitude>-180</LeftLongitude>
  17 + <WKID>4490</WKID>
  18 + <LatestWKID>4490</LatestWKID>
  19 + </SpatialReference>
  20 + <TileOrigin xsi:type="typens:PointN">
  21 + <X>-180</X>
  22 + <Y>90</Y>
  23 + </TileOrigin>
  24 + <TileCols>256</TileCols>
  25 + <TileRows>256</TileRows>
  26 + <DPI>96</DPI>
  27 + <PreciseDPI>96</PreciseDPI>
  28 + <LODInfos xsi:type="typens:ArrayOfLODInfo">
  29 + <LODInfo xsi:type="typens:LODInfo">
  30 + <LevelID>0</LevelID>
  31 + <Scale>590995186.11750006</Scale>
  32 + <Resolution>1.4062500000000004</Resolution>
  33 + </LODInfo>
  34 + <LODInfo xsi:type="typens:LODInfo">
  35 + <LevelID>1</LevelID>
  36 + <Scale>295497593.05875003</Scale>
  37 + <Resolution>0.70312500000000022</Resolution>
  38 + </LODInfo>
  39 + <LODInfo xsi:type="typens:LODInfo">
  40 + <LevelID>2</LevelID>
  41 + <Scale>147748796.52937502</Scale>
  42 + <Resolution>0.35156250000000011</Resolution>
  43 + </LODInfo>
  44 + <LODInfo xsi:type="typens:LODInfo">
  45 + <LevelID>3</LevelID>
  46 + <Scale>73874398.264687508</Scale>
  47 + <Resolution>0.17578125000000006</Resolution>
  48 + </LODInfo>
  49 + <LODInfo xsi:type="typens:LODInfo">
  50 + <LevelID>4</LevelID>
  51 + <Scale>36937199.132343754</Scale>
  52 + <Resolution>0.087890625000000028</Resolution>
  53 + </LODInfo>
  54 + <LODInfo xsi:type="typens:LODInfo">
  55 + <LevelID>5</LevelID>
  56 + <Scale>18468599.566171877</Scale>
  57 + <Resolution>0.043945312500000014</Resolution>
  58 + </LODInfo>
  59 + <LODInfo xsi:type="typens:LODInfo">
  60 + <LevelID>6</LevelID>
  61 + <Scale>9234299.7830859385</Scale>
  62 + <Resolution>0.021972656250000007</Resolution>
  63 + </LODInfo>
  64 + <LODInfo xsi:type="typens:LODInfo">
  65 + <LevelID>7</LevelID>
  66 + <Scale>4617149.8915429693</Scale>
  67 + <Resolution>0.010986328125000003</Resolution>
  68 + </LODInfo>
  69 + <LODInfo xsi:type="typens:LODInfo">
  70 + <LevelID>8</LevelID>
  71 + <Scale>2308574.9457714846</Scale>
  72 + <Resolution>0.0054931640625000017</Resolution>
  73 + </LODInfo>
  74 + <LODInfo xsi:type="typens:LODInfo">
  75 + <LevelID>9</LevelID>
  76 + <Scale>1154287.4728857423</Scale>
  77 + <Resolution>0.0027465820312500009</Resolution>
  78 + </LODInfo>
  79 + <LODInfo xsi:type="typens:LODInfo">
  80 + <LevelID>10</LevelID>
  81 + <Scale>577143.73644287116</Scale>
  82 + <Resolution>0.0013732910156250004</Resolution>
  83 + </LODInfo>
  84 + <LODInfo xsi:type="typens:LODInfo">
  85 + <LevelID>11</LevelID>
  86 + <Scale>288571.86822143558</Scale>
  87 + <Resolution>0.00068664550781250022</Resolution>
  88 + </LODInfo>
  89 + <LODInfo xsi:type="typens:LODInfo">
  90 + <LevelID>12</LevelID>
  91 + <Scale>144285.93411071779</Scale>
  92 + <Resolution>0.00034332275390625011</Resolution>
  93 + </LODInfo>
  94 + <LODInfo xsi:type="typens:LODInfo">
  95 + <LevelID>13</LevelID>
  96 + <Scale>72142.967055358895</Scale>
  97 + <Resolution>0.00017166137695312505</Resolution>
  98 + </LODInfo>
  99 + <LODInfo xsi:type="typens:LODInfo">
  100 + <LevelID>14</LevelID>
  101 + <Scale>36071.483527679447</Scale>
  102 + <Resolution>8.5830688476562527e-005</Resolution>
  103 + </LODInfo>
  104 + <LODInfo xsi:type="typens:LODInfo">
  105 + <LevelID>15</LevelID>
  106 + <Scale>18035.741763839724</Scale>
  107 + <Resolution>4.2915344238281264e-005</Resolution>
  108 + </LODInfo>
  109 + <LODInfo xsi:type="typens:LODInfo">
  110 + <LevelID>16</LevelID>
  111 + <Scale>9017.8708819198619</Scale>
  112 + <Resolution>2.1457672119140632e-005</Resolution>
  113 + </LODInfo>
  114 + <LODInfo xsi:type="typens:LODInfo">
  115 + <LevelID>17</LevelID>
  116 + <Scale>4508.9354409599309</Scale>
  117 + <Resolution>1.0728836059570316e-005</Resolution>
  118 + </LODInfo>
  119 + <LODInfo xsi:type="typens:LODInfo">
  120 + <LevelID>18</LevelID>
  121 + <Scale>2254.4677204799655</Scale>
  122 + <Resolution>5.3644180297851579e-006</Resolution>
  123 + </LODInfo>
  124 + <LODInfo xsi:type="typens:LODInfo">
  125 + <LevelID>19</LevelID>
  126 + <Scale>1127.2338602399827</Scale>
  127 + <Resolution>2.682209014892579e-006</Resolution>
  128 + </LODInfo>
  129 + <LODInfo xsi:type="typens:LODInfo">
  130 + <LevelID>20</LevelID>
  131 + <Scale>563.61693011999137</Scale>
  132 + <Resolution>1.3411045074462895e-006</Resolution>
  133 + </LODInfo>
  134 + </LODInfos>
  135 +</TileCacheInfo>
@@ -19,7 +19,7 @@ class Api(ApiTemplate): @@ -19,7 +19,7 @@ class Api(ApiTemplate):
19 try: 19 try:
20 guid = self.para.get("guid") 20 guid = self.para.get("guid")
21 service = Service.query.filter_by(guid=guid).one_or_none() 21 service = Service.query.filter_by(guid=guid).one_or_none()
22 - db.session.remove(service) 22 + db.session.delete(service)
23 db.session.commit() 23 db.session.commit()
24 res["result"] = True 24 res["result"] = True
25 except Exception as e: 25 except Exception as e:
@@ -13,17 +13,16 @@ class Api(ApiTemplate): @@ -13,17 +13,16 @@ class Api(ApiTemplate):
13 def process(self): 13 def process(self):
14 res = {} 14 res = {}
15 try: 15 try:
16 - if self.para.get("type").__eq__("影像WMS"):  
17 - from app.modules.service.image.image_service_edit import Api  
18 - elif self.para.get("type").__eq__("影像WMTS"):  
19 - from app.modules.service.image.image_service_edit import Api  
20 - elif self.para.get("type").__eq__("WMS"):  
21 - from app.modules.service.wms.wms_edit import Api  
22 - elif self.para.get("type").__eq__("WMTS"):  
23 - from app.modules.service.wmts.wmts_edit import Api 16 +
  17 + if self.para.get("type")in ["ImageWMTS","ImageWMS"]:
  18 + from app.modules.service.image.image_service_edit import Api as Api2
  19 + elif self.para.get("type").__eq__("WMS/WFS"):
  20 + from app.modules.service.wms.wms_edit import Api as Api2
  21 + elif self.para.get("type") in ["WMTS","MTS"]:
  22 + from app.modules.service.wmts.wmts_edit import Api as Api2
24 else: 23 else:
25 return res 24 return res
26 - api = Api() 25 + api = Api2()
27 api.para = self.para 26 api.para = self.para
28 res = api.process() 27 res = api.process()
29 28
  1 +# coding=utf-8
  2 +#author: 4N
  3 +#createtime: 2021/9/22
  4 +#email: nheweijun@sina.com
  5 +
  6 +
  7 +from app.util.component.ApiTemplate import ApiTemplate
  8 +from app.util.component.ModelVisitor import ModelVisitor
  9 +from app.models import Service
  10 +
  11 +class Api(ApiTemplate):
  12 + api_name = "服务Info"
  13 + def process(self):
  14 + res = {}
  15 + try:
  16 + guid = self.para.get("guid")
  17 + service = Service.query.filter_by(guid=guid).one_or_none()
  18 +
  19 + if service.type in ["ImageWMS","ImageWMTS"]:
  20 + from app.modules.service.image.models import ImageService
  21 + speci_service = ImageService.query.filter_by(guid=guid).one_or_none()
  22 + elif service.type.__eq__("WMTS") or service.type.__eq__("MTS"):
  23 + from app.modules.service.wmts.models import WMTS
  24 + speci_service = WMTS.query.filter_by(guid=guid).one_or_none()
  25 + elif service.type.__eq__("WMS/WFS"):
  26 + from app.modules.service.wms.models import WMS
  27 + speci_service = WMS.query.filter_by(guid=guid).one_or_none()
  28 + else:
  29 + speci_service = {}
  30 + res["data"] = ModelVisitor.object_to_json(speci_service)
  31 + except Exception as e:
  32 + raise e
  33 + return res
  34 +
  35 +
  36 + api_doc = {
  37 + "tags": ["服务接口"],
  38 + "parameters": [
  39 + {"name": "guid",
  40 + "in": "formData",
  41 + "type": "string",
  42 + "description": "guid"},
  43 + ],
  44 + "responses": {
  45 + 200: {
  46 + "schema": {
  47 + "properties": {
  48 + }
  49 + }
  50 + }
  51 + }
  52 + }
@@ -4,23 +4,28 @@ @@ -4,23 +4,28 @@
4 #email: nheweijun@sina.com 4 #email: nheweijun@sina.com
5 5
6 from app.util.component.ApiTemplate import ApiTemplate 6 from app.util.component.ApiTemplate import ApiTemplate
7 - 7 +from app.models import Service
8 class Api(ApiTemplate): 8 class Api(ApiTemplate):
9 api_name = "注册服务" 9 api_name = "注册服务"
10 def process(self): 10 def process(self):
11 res = {} 11 res = {}
12 try: 12 try:
13 - if self.para.get("type").__eq__("影像WMS"):  
14 - from app.modules.service.image.image_service_register import Api  
15 - elif self.para.get("type").__eq__("影像WMTS"):  
16 - from app.modules.service.image.image_service_register import Api 13 +
  14 + service = Service.query.filter_by(name=self.para.get("name")).one_or_none()
  15 + if service:
  16 + raise Exception("服务已存在!")
  17 +
  18 + if self.para.get("type").__eq__("ImageWMS"):
  19 + from app.modules.service.image.image_service_register import Api as Api2
  20 + elif self.para.get("type").__eq__("ImageWMTS"):
  21 + from app.modules.service.image.image_service_register import Api as Api2
17 elif self.para.get("type").__eq__("WMS"): 22 elif self.para.get("type").__eq__("WMS"):
18 - from app.modules.service.wms.wms_register import Api  
19 - elif self.para.get("type").__eq__("WMTS"):  
20 - from app.modules.service.wmts.wmts_register import Api 23 + from app.modules.service.wms.wms_register import Api as Api2
  24 + elif self.para.get("type").__eq__("WMTS") or self.para.get("type").__eq__("MTS"):
  25 + from app.modules.service.wmts.wmts_register import Api as Api2
21 else: 26 else:
22 return res 27 return res
23 - api = Api() 28 + api = Api2()
24 api.para = self.para 29 api.para = self.para
25 res = api.process() 30 res = api.process()
26 except Exception as e: 31 except Exception as e:
@@ -31,6 +36,134 @@ class Api(ApiTemplate): @@ -31,6 +36,134 @@ class Api(ApiTemplate):
31 api_doc = { 36 api_doc = {
32 "tags": ["服务接口"], 37 "tags": ["服务接口"],
33 "parameters": [ 38 "parameters": [
  39 +
  40 + #通用参数
  41 + {"name": "name",
  42 + "in": "formData",
  43 + "type": "string",
  44 + "required": "true",
  45 + "description": "[WMS,WMTS,影像WMS,影像WMTS]"},
  46 + {"name": "alias",
  47 + "in": "formData",
  48 + "type": "string",
  49 + "description": "[WMS,WMTS,影像WMS,影像WMTS]"},
  50 + {"name": "description",
  51 + "in": "formData",
  52 + "type": "string",
  53 + "description": "[WMS,WMTS,影像WMS,影像WMTS]"},
  54 + {"name": "type",
  55 + "in": "formData",
  56 + "type": "string",
  57 + "enum":["WMS/WFS","WMTS","MTS","ImageWMS","ImageWMTS"],
  58 + "required": "true",
  59 + "description": "[WMS,WMTS,影像WMS,影像WMTS]"},
  60 + {"name": "catalog_guid",
  61 + "in": "formData",
  62 + "type": "string",
  63 + "description": "[WMS,WMTS,影像WMS,影像WMTS]"},
  64 +
  65 + #影像参数
  66 + {"name": "guids",
  67 + "in": "formData",
  68 + "type": "string",
  69 + "description": "[影像WMS,影像WMTS]影像guids,以英文逗号相隔"},
  70 + {"name": "scheme_guid",
  71 + "in": "formData",
  72 + "type": "string",
  73 + "description": "[WMTS,影像WMTS]切片方案"},
  74 +
  75 + # WMTS参数
  76 + {"name": "overview",
  77 + "in": "formData",
  78 + "type": "string",
  79 + "description": "[WMTS]缩略图"},
  80 + {"name": "wmts_type",
  81 + "in": "formData",
  82 + "type": "string",
  83 + "description": "[WMTS]wmts_type"},
  84 + {"name": "vendor",
  85 + "in": "formData",
  86 + "type": "string",
  87 + "description": "[WMTS]厂商"},
  88 + {"name": "crs",
  89 + "in": "formData",
  90 + "type": "string",
  91 + "description": "[WMTS]坐标系"},
  92 + {"name": "datasource",
  93 + "in": "formData",
  94 + "type": "string",
  95 + "description": "[WMTS]数据路径"},
  96 + {"name": "layer_name",
  97 + "in": "formData",
  98 + "type": "string",
  99 + "description": "[WMTS]图层名"},
  100 + {"name": "layer_alias",
  101 + "in": "formData",
  102 + "type": "string",
  103 + "description": "[WMTS]图层别名"},
  104 + {"name": "layer_title",
  105 + "in": "formData",
  106 + "type": "string",
  107 + "description": "[WMTS]图层标题"},
  108 + {"name": "layer_style",
  109 + "in": "formData",
  110 + "type": "string",
  111 + "description": "[WMTS,WMS]图层样式"},
  112 + {"name": "layer_format",
  113 + "in": "formData",
  114 + "type": "string",
  115 + "description": "[WMTS]图层format"},
  116 + {"name": "layer_extent",
  117 + "in": "formData",
  118 + "type": "string",
  119 + "description": "[WMTS]图层范围"},
  120 + {"name": "layer_description",
  121 + "in": "formData",
  122 + "type": "string",
  123 + "description": "[WMTS]图层描述"},
  124 +
  125 + #WMS参数
  126 + {"name": "status",
  127 + "in": "formData",
  128 + "type": "string",
  129 + "description": "[WMS]status"},
  130 + {"name": "username",
  131 + "in": "formData",
  132 + "type": "string",
  133 + "description": "[WMS]username"},
  134 + {"name": "readonly",
  135 + "in": "formData",
  136 + "type": "string",
  137 + "description": "[WMS]readonly"},
  138 + {"name": "sid",
  139 + "in": "formData",
  140 + "type": "string",
  141 + "description": "[WMS]sid"},
  142 + {"name": "stype",
  143 + "in": "formData",
  144 + "type": "string",
  145 + "description": "[WMS]stype"},
  146 + {"name": "ssupply",
  147 + "in": "formData",
  148 + "type": "string",
  149 + "description": "[WMS]ssupply"},
  150 + {"name": "sctime",
  151 + "in": "formData",
  152 + "type": "string",
  153 + "description": "[WMS]sctime"},
  154 + {"name": "company",
  155 + "in": "formData",
  156 + "type": "string",
  157 + "description": "[WMS]company"},
  158 + {"name": "abstract",
  159 + "in": "formData",
  160 + "type": "string",
  161 + "description": "[WMS]abstract"},
  162 + {"name": "thumbnail",
  163 + "in": "formData",
  164 + "type": "string",
  165 + "description": "[WMS]thumbnail"},
  166 +
34 ], 167 ],
35 "responses": { 168 "responses": {
36 200: { 169 200: {
@@ -36,4 +36,5 @@ class WMS(db.Model): @@ -36,4 +36,5 @@ class WMS(db.Model):
36 36
37 layer_style = Column(Text) 37 layer_style = Column(Text)
38 38
39 - service_guid = Column(String,ForeignKey('dmdms_service.guid'))  
  39 + # service_guid = Column(String,ForeignKey('dmdms_service.guid'))
  40 + service_guid = Column(String)
@@ -2,3 +2,67 @@ @@ -2,3 +2,67 @@
2 #author: 4N 2 #author: 4N
3 #createtime: 2021/9/17 3 #createtime: 2021/9/17
4 #email: nheweijun@sina.com 4 #email: nheweijun@sina.com
  5 +
  6 +
  7 +from app.util.component.ApiTemplate import ApiTemplate
  8 +import uuid
  9 +from .models import WMS
  10 +from app.models import Service,db
  11 +
  12 +import datetime
  13 +class Api(ApiTemplate):
  14 +
  15 + api_name = "修改WMTS服务"
  16 +
  17 + def process(self):
  18 +
  19 +
  20 +
  21 + # 返回结果
  22 + res = {}
  23 +
  24 + try:
  25 + guid = self.para.get("guid")
  26 + service = Service.query.filter_by(guid=guid).one_or_none()
  27 + this_time = datetime.datetime.now()
  28 +
  29 +
  30 + service_update = {"upate_time":this_time}
  31 + wms_update = {"upatetime":this_time}
  32 + for key in self.para.keys():
  33 + if key in ["name","alias","state","description","overview","catalog_guid"]:
  34 + service_update[key] = self.para.get(key)
  35 + if key in ["status","description","username","readonly",
  36 + "sid","stype","ssupply","sctime","company","abstract","thumbnail","layer_style"]:
  37 + wms_update[key] = self.para.get(key)
  38 + if key.__eq__("name"):
  39 + wms_update["service"] = self.para.get(key)
  40 +
  41 +
  42 +
  43 + wms = WMS.query.filter_by(guid=service.service_guid).one_or_none()
  44 + service.update(service_update)
  45 + wms.update(wms_update)
  46 +
  47 + db.session.commit()
  48 +
  49 + res["result"] = True
  50 + except Exception as e:
  51 + raise e
  52 +
  53 + return res
  54 +
  55 + api_doc = {
  56 + "tags": ["影像接口"],
  57 + "parameters": [
  58 +
  59 + ],
  60 + "responses": {
  61 + 200: {
  62 + "schema": {
  63 + "properties": {
  64 + }
  65 + }
  66 + }
  67 + }
  68 + }
@@ -36,15 +36,16 @@ class Api(ApiTemplate): @@ -36,15 +36,16 @@ class Api(ApiTemplate):
36 update_time = this_time, 36 update_time = this_time,
37 description = self.para.get("description"), 37 description = self.para.get("description"),
38 #node = Column(Integer), 38 #node = Column(Integer),
  39 + node = 1 ,
39 overview = "xxxx", 40 overview = "xxxx",
40 - type = self.para.get("service_type"), 41 + type = self.para.get("type"),
41 service_guid = wms_service_guid, 42 service_guid = wms_service_guid,
42 catalog_guid = self.para.get("catalog_guid") 43 catalog_guid = self.para.get("catalog_guid")
43 ) 44 )
44 45
45 wms = WMS( 46 wms = WMS(
46 guid = wms_service_guid, 47 guid = wms_service_guid,
47 - name = self.para.get("name"), 48 + service = self.para.get("name"),
48 status = self.para.get("status"), 49 status = self.para.get("status"),
49 description=self.para.get("description"), 50 description=self.para.get("description"),
50 username = self.para.get("username"), 51 username = self.para.get("username"),
@@ -76,6 +77,80 @@ class Api(ApiTemplate): @@ -76,6 +77,80 @@ class Api(ApiTemplate):
76 "tags": ["WMTS接口"], 77 "tags": ["WMTS接口"],
77 "parameters": [ 78 "parameters": [
78 79
  80 + {"name": "name",
  81 + "in": "formData",
  82 + "type": "string",
  83 + "required": "true",
  84 + "description": "[WMS,WMTS,影像WMS,影像WMTS]"},
  85 + {"name": "alias",
  86 + "in": "formData",
  87 + "type": "string",
  88 + "description": "[WMS,WMTS,影像WMS,影像WMTS]"},
  89 + {"name": "description",
  90 + "in": "formData",
  91 + "type": "string",
  92 + "description": "[WMS,WMTS,影像WMS,影像WMTS]"},
  93 + {"name": "type",
  94 + "in": "formData",
  95 + "type": "string",
  96 + "enum": ["WMS", "WMTS", "影像WMS", "影像WMTS"],
  97 + "required": "true",
  98 + "description": "[WMS,WMTS,影像WMS,影像WMTS]"},
  99 + {"name": "catalog_guid",
  100 + "in": "formData",
  101 + "type": "string",
  102 + "description": "[WMS,WMTS,影像WMS,影像WMTS]"},
  103 +
  104 + {"name": "catalog_guid",
  105 + "in": "formData",
  106 + "type": "string",
  107 + "description": "[WMS,WMTS,影像WMS,影像WMTS]"},
  108 +
  109 + {"name": "status",
  110 + "in": "formData",
  111 + "type": "string",
  112 + "description": "[WMS]status"},
  113 + {"name": "username",
  114 + "in": "formData",
  115 + "type": "string",
  116 + "description": "[WMS]username"},
  117 + {"name": "readonly",
  118 + "in": "formData",
  119 + "type": "string",
  120 + "description": "[WMS]readonly"},
  121 + {"name": "sid",
  122 + "in": "formData",
  123 + "type": "string",
  124 + "description": "[WMS]sid"},
  125 + {"name": "stype",
  126 + "in": "formData",
  127 + "type": "string",
  128 + "description": "[WMS]stype"},
  129 + {"name": "ssupply",
  130 + "in": "formData",
  131 + "type": "string",
  132 + "description": "[WMS]ssupply"},
  133 + {"name": "sctime",
  134 + "in": "formData",
  135 + "type": "string",
  136 + "description": "[WMS]sctime"},
  137 + {"name": "company",
  138 + "in": "formData",
  139 + "type": "string",
  140 + "description": "[WMS]company"},
  141 + {"name": "abstract",
  142 + "in": "formData",
  143 + "type": "string",
  144 + "description": "[WMS]abstract"},
  145 + {"name": "thumbnail",
  146 + "in": "formData",
  147 + "type": "string",
  148 + "description": "[WMS]thumbnail"},
  149 + {"name": "layer_style",
  150 + "in": "formData",
  151 + "type": "string",
  152 + "description": "[WMS,WMTS]layer_style"},
  153 +
79 ], 154 ],
80 "responses": { 155 "responses": {
81 200: { 156 200: {
@@ -25,12 +25,3 @@ class DataManager(BlueprintApi): @@ -25,12 +25,3 @@ class DataManager(BlueprintApi):
25 上传缩略图 25 上传缩略图
26 """ 26 """
27 return upload_oview.Api().result 27 return upload_oview.Api().result
28 -  
29 - @staticmethod  
30 - @bp.route('/UploadOverview', methods=['POST'])  
31 - @swag_from(upload_oview.Api.api_doc)  
32 - def api_upload_oview():  
33 - """  
34 - 上传缩略图  
35 - """  
36 - return upload_oview.Api().result  
@@ -48,6 +48,9 @@ class WMTS(db.Model): @@ -48,6 +48,9 @@ class WMTS(db.Model):
48 #图层描述 48 #图层描述
49 layer_description = Column(String) 49 layer_description = Column(String)
50 50
51 - scheme_guid = Column(String,ForeignKey('dmap_tile_scheme.guid')) 51 + # scheme_guid = Column(String,ForeignKey('dmap_tile_scheme.guid'))
  52 + #
  53 + # service_guid = Column(String,ForeignKey('dmap_service.guid'))
52 54
53 - service_guid = Column(String,ForeignKey('dmap_service.guid'))  
  55 + scheme_guid = Column(String)
  56 + service_guid = Column(String)
@@ -10,6 +10,9 @@ from .models import WMTS @@ -10,6 +10,9 @@ from .models import WMTS
10 from app.models import Service,db 10 from app.models import Service,db
11 import datetime 11 import datetime
12 import configure 12 import configure
  13 +import requests
  14 +from requests import Response
  15 +import json
13 class Api(ApiTemplate): 16 class Api(ApiTemplate):
14 17
15 api_name = "注册WMTS服务" 18 api_name = "注册WMTS服务"
@@ -24,25 +27,28 @@ class Api(ApiTemplate): @@ -24,25 +27,28 @@ class Api(ApiTemplate):
24 service_guid = uuid.uuid1().__str__() 27 service_guid = uuid.uuid1().__str__()
25 wmts_service_guid = uuid.uuid1().__str__() 28 wmts_service_guid = uuid.uuid1().__str__()
26 29
27 -  
28 -  
29 service = Service( 30 service = Service(
30 guid = service_guid, 31 guid = service_guid,
31 name = self.para.get("name"), 32 name = self.para.get("name"),
32 alias = self.para.get("alias"), 33 alias = self.para.get("alias"),
33 - state = int(self.para.get("state")) if self.para.get("state") else None, 34 + state = 1,
34 create_time = this_time, 35 create_time = this_time,
35 update_time = this_time, 36 update_time = this_time,
36 description = self.para.get("description"), 37 description = self.para.get("description"),
37 - #node = Column(Integer), 38 + node = 1,
38 overview = "http://{}/API/Service/Overview/{}".format( 39 overview = "http://{}/API/Service/Overview/{}".format(
39 configure.deploy_ip_host, 40 configure.deploy_ip_host,
40 self.para.get("overview") if self.para.get("overview") else "wmts_tb.png"), 41 self.para.get("overview") if self.para.get("overview") else "wmts_tb.png"),
41 - type = self.para.get("service_type"), 42 + type = self.para.get("type"),
42 service_guid = wmts_service_guid, 43 service_guid = wmts_service_guid,
43 catalog_guid = self.para.get("catalog_guid") 44 catalog_guid = self.para.get("catalog_guid")
44 ) 45 )
45 46
  47 + #已存在就删除
  48 + wmts_isexist = WMTS.query.filter_by(name=self.para.get("name")).one_or_none()
  49 + if wmts_isexist:
  50 + db.session.delete(wmts_isexist)
  51 +
46 wmts = WMTS( 52 wmts = WMTS(
47 guid = wmts_service_guid, 53 guid = wmts_service_guid,
48 name = self.para.get("name"), 54 name = self.para.get("name"),
@@ -60,16 +66,25 @@ class Api(ApiTemplate): @@ -60,16 +66,25 @@ class Api(ApiTemplate):
60 layer_extent = self.para.get("layer_extent"), 66 layer_extent = self.para.get("layer_extent"),
61 layer_description = self.para.get("layer_description"), 67 layer_description = self.para.get("layer_description"),
62 scheme_guid = self.para.get("scheme_guid"), 68 scheme_guid = self.para.get("scheme_guid"),
63 - service_guid = service_guid 69 + service_guid = service_guid,
  70 + metadata_url="{}/DMap/Services/{}/MapServer/WMTSServer".format(configure.wmts_url,self.para.get("name"))
64 ) 71 )
65 72
66 -  
67 - #调用WMTS的注册服务接口  
68 -  
69 -  
70 db.session.add(service) 73 db.session.add(service)
71 db.session.add(wmts) 74 db.session.add(wmts)
72 db.session.commit() 75 db.session.commit()
  76 +
  77 + # 调用WMTS的注册服务接口
  78 + try:
  79 + url = "{}/dmap/api/manager/updatecache?servicename={}".format(configure.wmts_url,service.name)
  80 + resp:Response = requests.get(url)
  81 + if not resp.json()["status"].__eq__("true"):
  82 + raise Exception("调用WMTS的注册服务接口失败!")
  83 + except Exception as e:
  84 + db.session.delete(service)
  85 + db.session.delete(wmts)
  86 + db.session.commit()
  87 + raise e
73 res["data"] = service_guid 88 res["data"] = service_guid
74 res["result"] = True 89 res["result"] = True
75 except Exception as e: 90 except Exception as e:
@@ -80,7 +95,78 @@ class Api(ApiTemplate): @@ -80,7 +95,78 @@ class Api(ApiTemplate):
80 api_doc = { 95 api_doc = {
81 "tags": ["WMTS接口"], 96 "tags": ["WMTS接口"],
82 "parameters": [ 97 "parameters": [
83 - 98 + {"name": "name",
  99 + "in": "formData",
  100 + "type": "string",
  101 + "description": "[WMS,WMTS,影像WMS,影像WMTS]"},
  102 + {"name": "alias",
  103 + "in": "formData",
  104 + "type": "string",
  105 + "description": "[WMS,WMTS,影像WMS,影像WMTS]"},
  106 + {"name": "description",
  107 + "in": "formData",
  108 + "type": "string",
  109 + "description": "[WMS,WMTS,影像WMS,影像WMTS]"},
  110 + {"name": "type",
  111 + "in": "formData",
  112 + "type": "string",
  113 + "description": "[WMS,WMTS,影像WMS,影像WMTS]"},
  114 + {"name": "catalog_guid",
  115 + "in": "formData",
  116 + "type": "string",
  117 + "description": "[WMS,WMTS,影像WMS,影像WMTS]"},
  118 + {"name": "scheme_guid",
  119 + "in": "formData",
  120 + "type": "string",
  121 + "description": "[WMTS,影像WMTS]切片方案"},
  122 + {"name": "overview",
  123 + "in": "formData",
  124 + "type": "string",
  125 + "description": "[WMTS]缩略图"},
  126 + {"name": "wmts_type",
  127 + "in": "formData",
  128 + "type": "string",
  129 + "description": "[WMTS]wmts_type"},
  130 + {"name": "vendor",
  131 + "in": "formData",
  132 + "type": "string",
  133 + "description": "[WMTS]厂商"},
  134 + {"name": "crs",
  135 + "in": "formData",
  136 + "type": "string",
  137 + "description": "[WMTS]坐标系"},
  138 + {"name": "datasource",
  139 + "in": "formData",
  140 + "type": "string",
  141 + "description": "[WMTS]数据路径"},
  142 + {"name": "layer_name",
  143 + "in": "formData",
  144 + "type": "string",
  145 + "description": "[WMTS]图层名"},
  146 + {"name": "layer_alias",
  147 + "in": "formData",
  148 + "type": "string",
  149 + "description": "[WMTS]图层别名"},
  150 + {"name": "layer_title",
  151 + "in": "formData",
  152 + "type": "string",
  153 + "description": "[WMTS]图层标题"},
  154 + {"name": "layer_style",
  155 + "in": "formData",
  156 + "type": "string",
  157 + "description": "[WMTS]图层样式"},
  158 + {"name": "layer_format",
  159 + "in": "formData",
  160 + "type": "string",
  161 + "description": "[WMTS]图层format"},
  162 + {"name": "layer_extent",
  163 + "in": "formData",
  164 + "type": "string",
  165 + "description": "[WMTS]图层范围"},
  166 + {"name": "layer_description",
  167 + "in": "formData",
  168 + "type": "string",
  169 + "description": "[WMTS]图层描述"},
84 ], 170 ],
85 "responses": { 171 "responses": {
86 200: { 172 200: {
@@ -65,7 +65,7 @@ class EntryData: @@ -65,7 +65,7 @@ class EntryData:
65 except Exception as e: 65 except Exception as e:
66 this_task.write_process("{} 任务结束!".format(e.__str__())) 66 this_task.write_process("{} 任务结束!".format(e.__str__()))
67 this_task.update({"state": -1, "process": "入库失败", "update_time": datetime.datetime.now()}) 67 this_task.update({"state": -1, "process": "入库失败", "update_time": datetime.datetime.now()})
68 - StructurePrint.print(e.__str__(),"ERROR") 68 + StructurePrint().print(e.__str__(),"ERROR")
69 # rollback 69 # rollback
70 this_task.pg_ds.RollbackTransaction() 70 this_task.pg_ds.RollbackTransaction()
71 finally: 71 finally:
@@ -79,13 +79,13 @@ class EntryData: @@ -79,13 +79,13 @@ class EntryData:
79 i+=1 79 i+=1
80 if i<30: 80 if i<30:
81 shutil.rmtree(dir_path,True) 81 shutil.rmtree(dir_path,True)
82 - StructurePrint.print("删除文件成功!") 82 + StructurePrint().print("删除文件成功!")
83 else: 83 else:
84 raise Exception("找不到文件!") 84 raise Exception("找不到文件!")
85 85
86 except Exception as e: 86 except Exception as e:
87 - StructurePrint.print(e.__str__(), "ERROR")  
88 - StructurePrint.print("删除文件失败!","ERROR") 87 + StructurePrint().print(e.__str__(), "ERROR")
  88 + StructurePrint().print("删除文件失败!","ERROR")
89 89
90 def entry_shp(self,data_path,this_task): 90 def entry_shp(self,data_path,this_task):
91 ''' 91 '''
@@ -186,7 +186,7 @@ class EntryData: @@ -186,7 +186,7 @@ class EntryData:
186 for feature in layer: 186 for feature in layer:
187 count+=1 187 count+=1
188 if count%10000==0: 188 if count%10000==0:
189 - StructurePrint.print("{}图层已入库{}个对象".format(new_layer_name,count)) 189 + StructurePrint().print("{}图层已入库{}个对象".format(new_layer_name,count))
190 # print(time.time()-this_time) 190 # print(time.time()-this_time)
191 this_time=time.time() 191 this_time=time.time()
192 geo :Geometry = feature.GetGeometryRef() 192 geo :Geometry = feature.GetGeometryRef()
@@ -194,7 +194,7 @@ class EntryData: @@ -194,7 +194,7 @@ class EntryData:
194 if geo is not None: 194 if geo is not None:
195 if geo.IsEmpty(): 195 if geo.IsEmpty():
196 this_task.write_process("FID:{}要素的空间字段为空,跳过该要素!".format(feature.GetFID())) 196 this_task.write_process("FID:{}要素的空间字段为空,跳过该要素!".format(feature.GetFID()))
197 - StructurePrint.print("FID:{}要素的空间字段为空,跳过该要素!".format(feature.GetFID()),"WARN") 197 + StructurePrint().print("FID:{}要素的空间字段为空,跳过该要素!".format(feature.GetFID()),"WARN")
198 continue 198 continue
199 out_feature: Feature = copy.copy(feature) 199 out_feature: Feature = copy.copy(feature)
200 200
@@ -210,7 +210,7 @@ class EntryData: @@ -210,7 +210,7 @@ class EntryData:
210 except Exception as e: 210 except Exception as e:
211 # this_task.pg_ds.RollbackTransaction() 211 # this_task.pg_ds.RollbackTransaction()
212 this_task.write_process("{}入库失败,数据回滚!原因:{}".format(new_layer_name,e.__str__())) 212 this_task.write_process("{}入库失败,数据回滚!原因:{}".format(new_layer_name,e.__str__()))
213 - StructurePrint.print("{}入库失败,数据回滚!原因:{}".format(new_layer_name,e.__str__()), "error") 213 + StructurePrint().print("{}入库失败,数据回滚!原因:{}".format(new_layer_name,e.__str__()), "error")
214 return False,new_layer_name 214 return False,new_layer_name
215 # finally: 215 # finally:
216 216
@@ -87,7 +87,7 @@ class EntryDataVacuate: @@ -87,7 +87,7 @@ class EntryDataVacuate:
87 except Exception as e: 87 except Exception as e:
88 this_task.write_process("{} 任务结束!".format(e.__str__())) 88 this_task.write_process("{} 任务结束!".format(e.__str__()))
89 this_task.update({"state": -1, "process": "入库失败", "update_time": datetime.datetime.now()}) 89 this_task.update({"state": -1, "process": "入库失败", "update_time": datetime.datetime.now()})
90 - StructurePrint.print(e.__str__(),"ERROR") 90 + StructurePrint().print(e.__str__(),"ERROR")
91 # rollback 91 # rollback
92 this_task.rollback() 92 this_task.rollback()
93 finally: 93 finally:
@@ -101,13 +101,13 @@ class EntryDataVacuate: @@ -101,13 +101,13 @@ class EntryDataVacuate:
101 i+=1 101 i+=1
102 if i<30: 102 if i<30:
103 shutil.rmtree(dir_path,True) 103 shutil.rmtree(dir_path,True)
104 - StructurePrint.print("删除文件成功!") 104 + StructurePrint().print("删除文件成功!")
105 else: 105 else:
106 raise Exception("找不到文件!") 106 raise Exception("找不到文件!")
107 107
108 except Exception as e: 108 except Exception as e:
109 - StructurePrint.print(e.__str__(), "ERROR")  
110 - StructurePrint.print("删除文件失败!","ERROR") 109 + StructurePrint().print(e.__str__(), "ERROR")
  110 + StructurePrint().print("删除文件失败!","ERROR")
111 111
112 112
113 def entry_shp(self,data_path,this_task,meta): 113 def entry_shp(self,data_path,this_task,meta):
@@ -209,7 +209,7 @@ class EntryDataVacuate: @@ -209,7 +209,7 @@ class EntryDataVacuate:
209 for feature in layer: 209 for feature in layer:
210 count+=1 210 count+=1
211 if count%10000==0: 211 if count%10000==0:
212 - StructurePrint.print("{}图层已入库{}个对象".format(new_layer_name,count)) 212 + StructurePrint().print("{}图层已入库{}个对象".format(new_layer_name,count))
213 # print(time.time()-this_time) 213 # print(time.time()-this_time)
214 #this_time=time.time() 214 #this_time=time.time()
215 geo :Geometry = feature.GetGeometryRef() 215 geo :Geometry = feature.GetGeometryRef()
@@ -217,7 +217,7 @@ class EntryDataVacuate: @@ -217,7 +217,7 @@ class EntryDataVacuate:
217 if geo is not None: 217 if geo is not None:
218 if geo.IsEmpty(): 218 if geo.IsEmpty():
219 this_task.write_process("FID:{}要素的空间字段为空,跳过该要素!".format(feature.GetFID())) 219 this_task.write_process("FID:{}要素的空间字段为空,跳过该要素!".format(feature.GetFID()))
220 - StructurePrint.print("FID:{}要素的空间字段为空,跳过该要素!".format(feature.GetFID()),"WARN") 220 + StructurePrint().print("FID:{}要素的空间字段为空,跳过该要素!".format(feature.GetFID()),"WARN")
221 continue 221 continue
222 222
223 out_feature: Feature = copy.copy(feature) 223 out_feature: Feature = copy.copy(feature)
@@ -248,7 +248,7 @@ class EntryDataVacuate: @@ -248,7 +248,7 @@ class EntryDataVacuate:
248 except Exception as e: 248 except Exception as e:
249 249
250 this_task.write_process("{}入库失败,数据回滚!原因:{}".format(new_layer_name,e.__str__())) 250 this_task.write_process("{}入库失败,数据回滚!原因:{}".format(new_layer_name,e.__str__()))
251 - StructurePrint.print("{}入库失败,数据回滚!原因:{}".format(new_layer_name,e.__str__()), "error") 251 + StructurePrint().print("{}入库失败,数据回滚!原因:{}".format(new_layer_name,e.__str__()), "error")
252 print(traceback.format_exc()) 252 print(traceback.format_exc())
253 # 抽稀回滚 253 # 抽稀回滚
254 # vacuate_process.rollback() 254 # vacuate_process.rollback()
@@ -440,7 +440,7 @@ class VacuateProcess: @@ -440,7 +440,7 @@ class VacuateProcess:
440 p_x = (extent[1]-extent[0])/10.0 440 p_x = (extent[1]-extent[0])/10.0
441 p_y = (extent[3] - extent[2]) / 10.0 441 p_y = (extent[3] - extent[2]) / 10.0
442 fill_precent=0 442 fill_precent=0
443 - StructurePrint.print("判断疏密") 443 + StructurePrint().print("判断疏密")
444 for ix in range(10): 444 for ix in range(10):
445 for iy in range(10): 445 for iy in range(10):
446 grid_extent = [extent[0]+ix*p_x,extent[0]+ix*p_x+p_x,extent[2]+iy*p_y,extent[2]+iy*p_y+p_y] 446 grid_extent = [extent[0]+ix*p_x,extent[0]+ix*p_x+p_x,extent[2]+iy*p_y,extent[2]+iy*p_y+p_y]
@@ -453,7 +453,7 @@ class VacuateProcess: @@ -453,7 +453,7 @@ class VacuateProcess:
453 fill_precent += 1 453 fill_precent += 1
454 454
455 print(fill_precent) 455 print(fill_precent)
456 - StructurePrint.print("判断疏密结束") 456 + StructurePrint().print("判断疏密结束")
457 457
458 layer.SetSpatialFilter(None) 458 layer.SetSpatialFilter(None)
459 layer.ResetReading() 459 layer.ResetReading()
@@ -155,6 +155,19 @@ class GeometryAdapter: @@ -155,6 +155,19 @@ class GeometryAdapter:
155 return poly 155 return poly
156 156
157 @classmethod 157 @classmethod
  158 + def bbox_2_polygon(cls,bbox):
  159 + ring = ogr.Geometry(ogr.wkbLinearRing)
  160 + ring.AddPoint(bbox[0], bbox[1])
  161 + ring.AddPoint(bbox[0], bbox[3])
  162 + ring.AddPoint(bbox[2], bbox[3])
  163 + ring.AddPoint(bbox[2], bbox[1])
  164 + ring.AddPoint(bbox[0], bbox[1])
  165 + # Create polygon
  166 + poly = ogr.Geometry(ogr.wkbPolygon)
  167 + poly.AddGeometry(ring)
  168 + return poly
  169 +
  170 + @classmethod
158 def tuple_2_point(cls,tup): 171 def tuple_2_point(cls,tup):
159 point = ogr.Geometry(ogr.wkbPoint) 172 point = ogr.Geometry(ogr.wkbPoint)
160 point.AddPoint(tup[0], tup[1]) 173 point.AddPoint(tup[0], tup[1])
@@ -51,8 +51,8 @@ class SliceScheme: @@ -51,8 +51,8 @@ class SliceScheme:
51 col = int(col) 51 col = int(col)
52 detaxy = parameter.get(str(level)).get("resolution")* parameter.get("cols") 52 detaxy = parameter.get(str(level)).get("resolution")* parameter.get("cols")
53 53
54 - minx = detaxy*col + parameter.get("x")  
55 - maxy = -detaxy*row +parameter.get("y") 54 + minx = detaxy * col + parameter.get("x")
  55 + maxy = -detaxy * row + parameter.get("y")
56 maxx = detaxy + minx 56 maxx = detaxy + minx
57 miny = -detaxy + maxy 57 miny = -detaxy + maxy
58 58
@@ -5,15 +5,42 @@ @@ -5,15 +5,42 @@
5 import datetime 5 import datetime
6 import os 6 import os
7 7
  8 +import logging
  9 +
8 class StructurePrint: 10 class StructurePrint:
9 11
  12 + # 单例模式作为打印
  13 + singleton = None
  14 + f = None
  15 +
  16 +
  17 + def __new__(cls, *args, **kwargs):
  18 + if not cls.singleton:
  19 + cls.singleton = super().__new__(cls)
  20 + return cls.singleton
  21 +
10 log_file = os.path.join(os.path.dirname( 22 log_file = os.path.join(os.path.dirname(
11 os.path.dirname( 23 os.path.dirname(
12 os.path.dirname( 24 os.path.dirname(
13 os.path.dirname( 25 os.path.dirname(
14 os.path.realpath(__file__))))), "logs", "log.txt") 26 os.path.realpath(__file__))))), "logs", "log.txt")
15 - @classmethod  
16 - def print(cls,mes, type="info"):  
17 - with open(cls.log_file,"a",encoding="utf-8") as f: 27 +
  28 + def __init__(self):
  29 + if not self.f:
  30 + self.f = open(self.log_file,"a",encoding="utf-8")
  31 +
  32 +
  33 + # def print(self,mes, type="info"):
  34 + # message = "[{}] {} {}\n".format(type.upper(), datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), mes)
  35 + # self.f.write(message)
  36 + # dd =1
  37 +
  38 +
  39 + def print(self,mes, type="info"):
  40 + with open(self.log_file,"a",encoding="utf-8") as f:
18 message = "[{}] {} {}\n".format(type.upper(), datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), mes) 41 message = "[{}] {} {}\n".format(type.upper(), datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), mes)
19 f.write(message) 42 f.write(message)
  43 +
  44 +
  45 +
  46 +
@@ -4,11 +4,11 @@ @@ -4,11 +4,11 @@
4 deploy_ip_host = "172.26.40.105:8840" 4 deploy_ip_host = "172.26.40.105:8840"
5 # 系统数据库 5 # 系统数据库
6 6
7 -SQLALCHEMY_DATABASE_URI = "postgresql://postgres:chinadci@172.26.60.100:5432/dmap_manager" 7 +SQLALCHEMY_DATABASE_URI = "postgresql://postgres:chinadci@172.26.60.100:5432/dmap_manager_test"
8 8
9 # 指定精华表所在位置(必须为空间库),设置为None则存放在各自的实体库中 9 # 指定精华表所在位置(必须为空间库),设置为None则存放在各自的实体库中
10 -VACUATE_DB_URI = None  
11 -# VACUATE_DB_URI = SQLALCHEMY_DATABASE_URI 10 +#VACUATE_DB_URI = None
  11 +VACUATE_DB_URI = SQLALCHEMY_DATABASE_URI
12 12
13 # 部署模式cluster,standalone 13 # 部署模式cluster,standalone
14 deployment_mode = "cluster" 14 deployment_mode = "cluster"
@@ -17,6 +17,10 @@ application_name = "master" @@ -17,6 +17,10 @@ application_name = "master"
17 17
18 zookeeper = "172.26.99.168:2181" 18 zookeeper = "172.26.99.168:2181"
19 19
  20 +#WMTS服务器
  21 +wmts_url = "http://172.26.99.160:6080"
  22 +
  23 +
20 # 固定配置不需要修改 24 # 固定配置不需要修改
21 swagger_configure = {"title": "DMapManager"} 25 swagger_configure = {"title": "DMapManager"}
22 entry_data_thread = 3 26 entry_data_thread = 3
1 #! /bin/sh 1 #! /bin/sh
2 - 2 +dn="dmapmanager"
3 #停止容器 3 #停止容器
4 echo "正在关闭容器..." 4 echo "正在关闭容器..."
5 -docker stop dmapmanager  
6 -docker rm dmapmanager 5 +docker stop $dn
  6 +docker rm $dn
7 7
8 curPath=$(readlink -f $(dirname $0)) 8 curPath=$(readlink -f $(dirname $0))
9 9
@@ -24,7 +24,7 @@ fi @@ -24,7 +24,7 @@ fi
24 #启动容器和apache 24 #启动容器和apache
25 echo "正在启动容器..." 25 echo "正在启动容器..."
26 set="--privileged=true -e TZ="Asia/Shanghai" --restart=always -e ALLOW_IP_RANGE=0.0.0.0/0" 26 set="--privileged=true -e TZ="Asia/Shanghai" --restart=always -e ALLOW_IP_RANGE=0.0.0.0/0"
27 -docker run -d --name dmapmanager $set -p $port:80 -v $curPath:/usr/src/app -v $curPath/httpd.conf:/etc/httpd/conf/httpd.conf dci/dmapmanager:4.0 /usr/sbin/init  
28 -docker exec -d dmapmanager systemctl start httpd 27 +docker run -d --name $dn $set -p $port:80 -v $curPath:/usr/src/app -v $curPath/httpd.conf:/etc/httpd/conf/httpd.conf dci/dmapmanager:4.0 /usr/sbin/init
  28 +docker exec -d $dn systemctl start httpd
29 sleep 5 29 sleep 5
30 curl localhost:$port/release 30 curl localhost:$port/release
1 #! /bin/bash 1 #! /bin/bash
2 -docker stop dmapmanager  
3 -docker rm dmapmanager 2 +dn="dmapmanager"
  3 +#停止容器
  4 +echo "正在关闭容器..."
  5 +docker stop $dn
  6 +docker rm $dn
4 curPath=$(readlink -f "$(dirname "$0")") 7 curPath=$(readlink -f "$(dirname "$0")")
5 #设置端口 8 #设置端口
6 port="" 9 port=""
@@ -11,7 +14,7 @@ else @@ -11,7 +14,7 @@ else
11 port=$1 14 port=$1
12 echo "端口设置为$1 ..." 15 echo "端口设置为$1 ..."
13 fi 16 fi
14 -docker run -d --name dmapmanager -e TZ="Asia/Shanghai" --restart=always -e ALLOW_IP_RANGE=0.0.0.0/0 -p $port:8840 -v $curPath:/usr/src/app -w /usr/src/app dci/dmapdms:4.0 gunicorn -c gun_conf.py run:app 17 +docker run -d --name $dn -e TZ="Asia/Shanghai" --restart=always -e ALLOW_IP_RANGE=0.0.0.0/0 -p $port:8840 -v $curPath:/usr/src/app -w /usr/src/app dci/dmapdms:4.0 gunicorn -c gun_conf.py run:app
15 # 清除未完成的任务任务 18 # 清除未完成的任务任务
16 sleep 5 19 sleep 5
17 curl localhost:$port/release 20 curl localhost:$port/release
1 #! /bin/bash 1 #! /bin/bash
2 -docker stop dmapmanager  
3 -docker rm dmapmanager 2 +dn="dmapmanager"
  3 +#停止容器
  4 +echo "正在关闭容器..."
  5 +docker stop $dn
  6 +docker rm $dn
  7 +
4 curPath=$(readlink -f "$(dirname "$0")") 8 curPath=$(readlink -f "$(dirname "$0")")
5 #设置端口 9 #设置端口
6 port="" 10 port=""
@@ -12,7 +16,7 @@ else @@ -12,7 +16,7 @@ else
12 echo "端口设置为$1 ..." 16 echo "端口设置为$1 ..."
13 fi 17 fi
14 18
15 -docker run -d --name dmapmanager -e TZ="Asia/Shanghai" --restart=always -e ALLOW_IP_RANGE=0.0.0.0/0 -p $port:8840 -v $curPath:/usr/src/app -w /usr/src/app dci/dmapdms:3.0 python3 ./run.py 19 +docker run -d --name $dn -e TZ="Asia/Shanghai" --restart=always -e ALLOW_IP_RANGE=0.0.0.0/0 -p $port:8840 -v $curPath:/usr/src/app -w /usr/src/app dci/dmapdms:3.0 python3 ./run.py
16 # 清除未完成的任务任务 20 # 清除未完成的任务任务
17 sleep 5 21 sleep 5
18 curl localhost:$port/release 22 curl localhost:$port/release
注册登录 后发表评论