| | |
| | | #!/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 * |
| | | |
| | | |
| | | # 获取完整路径 |
| | |
| | | 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() |
| | | |
| | |
| | | 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() |
| | | |