管道基础大数据平台系统开发-【CS】-ExportMap
1
13693261870
2023-03-09 4ba52868a1bce41b11b943fcc73f59f19e154953
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env
# -*- coding: utf-8 -*-
 
 
import os
import sys
sys.path.append(r"C:\Program Files\QGIS 3.16\apps\qgis-ltr\python\plugins")
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 processing.core.Processing import Processing
import processing
 
 
# 获取完整路径
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 i in range(0, len(lines)):
        lines[i] = lines[i].replace('\n', '')
 
    return lines
 
 
# 加载图层
def loadLayers(prj, args):
    lines = readTxt(args.file)
    for i in range(0, len(lines)):
        line = lines[i]
        if len(line) == 0:
            continue
 
        print("layer: " + line)
        layer = QgsRasterLayer(line, "layer_" + str(i))
        if not layer.isValid():
            print("layer_" + str(i) + ": failed to load!")
 
 
# 初始化
def init():
    # QgsApplication.setPrefixPath("C:\Program Files\QGIS 3.16", True)
    qgs = QgsApplication([], True)
    Processing.initialize()
    qgs.initQgis()
 
    args = get_args()
    project = QgsProject.instance()
    #project.read(os.path.join(args.src, args.qgz))
    #print("FileName: " + project.fileName())
 
    loadLayers(project, args)
 
    ops = {
        'BACKGROUND_COLOR': QColor(0, 0, 0, 0),
        'DPI': 96,
        'EXTENT': '38399769.358700000,38403264.373400003,3558330.210400000,3561632.889400000 []',
        'METATILESIZE': 4,
        'OUTPUT_DIRECTORY': args.out,
        'OUTPUT_HTML': args.out + "\\view.html",
        'QUALITY': 100,
        'TILE_FORMAT': 0,
        'TILE_HEIGHT': 256,
        'TILE_WIDTH': 256,
        'TMS_CONVENTION': True,
        'ZOOM_MAX': 8,
        'ZOOM_MIN': 8
    }
    processing.run("qgis:tilesxyzdirectory", ops)
 
    qgs.exitQgis()
 
 
# main
if __name__ == '__main__':
    init()