管道基础大数据平台系统开发-【CS】-ExportMap
1
13693261870
2023-03-09 835ae099ab21503ea86a76d382a348dd6008fedc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env
# -*- coding: utf-8 -*-
 
import os
import sys
import math
import argparse
from qgis.core import *
from qgis.gui import *
from qgis.PyQt.QtGui import *
from qgis.PyQt.QtCore import *
from qgis.PyQt.QtWidgets import *
from qgis.PyQt.QtXml import *
 
 
# 获取完整路径
def get_full_path():
    return os.path.split(sys.argv[0])[0]
 
 
# 获取参数
def get_args():
    print("argv = ", sys.argv[1:])
    parser = argparse.ArgumentParser(description='ArgUtils')
    parser.add_argument("-src", type=str, default=get_full_path(), required=False)
    parser.add_argument("-qgz", type=str, default="xyz.qgz", required=False)
    parser.add_argument("-file", type=str, default=r"D:\xyz\tiles.txt", required=False)
    parser.add_argument("-out", type=str, default=r"D:\xyz\tiles\zy", required=False)
 
    return parser.parse_args()
 
 
# 读取文本文件
def readTxt(filePath):
    f = open(filePath, encoding="utf-8")
    lines = f.readlines()
    f.close()
 
    for line in lines:
        line = line.replace('\n', '')
 
    return lines
 
 
# 加载图层
def loadLayers(args):
    lines = readTxt(args.file)
    for line in lines:
        print(line.replace('\n', ''))
 
 
# 初始化
def init():
    qgs = QgsApplication([], True)
    qgs.initQgis()
 
    args = get_args()
    project = QgsProject.instance()
    project.read(os.path.join(args.src, args.qgz))
    print("FileName: " + project.fileName())
 
    loadLayers(args)
 
    qgs.exitQgis()
 
 
if __name__ == '__main__':
    init()