From b849a185e1bf8e37a85cbfa6ee251ff5a531b45c Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期四, 09 三月 2023 15:26:47 +0800 Subject: [PATCH] 1 --- ExportMap/Sources/xyz.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 46 insertions(+), 8 deletions(-) diff --git a/ExportMap/Sources/xyz.py b/ExportMap/Sources/xyz.py index e2335f8..733f9b0 100644 --- a/ExportMap/Sources/xyz.py +++ b/ExportMap/Sources/xyz.py @@ -1,16 +1,24 @@ #!/usr/bin/env # -*- coding: utf-8 -*- + import os import sys + +from qgis.core import * +# C:\Program Files\QGIS 3.16\apps\qgis-ltr\python\qgis +sys.path.append(r"C:\Program Files\QGIS 3.16\apps\qgis-ltr\python\plugins") +from processing.core.Processing import Processing +Processing.initialize() +import processing +#from qgis import processing + 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 * # 鑾峰彇瀹屾暣璺緞 @@ -36,21 +44,30 @@ lines = f.readlines() f.close() - for line in lines: - line = line.replace('\n', '') + for i in range(0, len(lines)): + lines[i] = lines[i].replace('\n', '') return lines # 鍔犺浇鍥惧眰 -def loadLayers(args): +def loadLayers(prj, args): lines = readTxt(args.file) - for line in lines: - print(line.replace('\n', '')) + 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!") + #prj.addRasterLayer(line, "layer_" + str(i)) # 鍒濆鍖� def init(): + # QgsApplication.setPrefixPath("C:\Program Files\QGIS 3.16", True) qgs = QgsApplication([], True) qgs.initQgis() @@ -59,11 +76,32 @@ project.read(os.path.join(args.src, args.qgz)) print("FileName: " + project.fileName()) - loadLayers(args) + loadLayers(project, args) + + for alg in qgs.processingRegistry().algorithms(): + print(alg.id(), "->", alg.displayName()) + + ops = { + 'BACKGROUND_COLOR': QColor(0, 0, 0, 0), + 'DPI': 96, + 'EXTENT': '38399808.872500002,38403271.749600001,3558251.197600000,3561749.171400000 []', + 'METATILESIZE': 4, + 'OUTPUT_DIRECTORY': args.out, + 'OUTPUT_HTML': 'TEMPORARY_OUTPUT', + 'QUALITY': 100, + 'TILE_FORMAT': 0, + 'TILE_HEIGHT': 256, + 'TILE_WIDTH': 256, + 'TMS_CONVENTION': True, + 'ZOOM_MAX': 12, + 'ZOOM_MIN': 12 + } + processing.run("qgis:tilesxyzdirectory", ops) qgs.exitQgis() +# main if __name__ == '__main__': init() -- Gitblit v1.9.3