-
Notifications
You must be signed in to change notification settings - Fork 5
/
standalone.py
115 lines (98 loc) · 3.87 KB
/
standalone.py
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import argparse
from pathlib import Path
import os
import sys
from pathlib import Path
# import ptvsd
# ptvsd.enable_attach(address=("localhost", 5678))
# ptvsd.wait_for_attach()
from qgis.core import QgsApplication, QgsNetworkAccessManager, QgsExpression
from qgis.PyQt.QtNetwork import QNetworkProxy
from qgis import core, gui
def exportMaps(args):
from ferramentas_edicao.controllers.mapBuilderController import MapBuildController
sys.path.append(os.path.dirname(os.path.dirname(__file__)))
controller = MapBuildController(args, None)
controller.run()
def setupArgparser():
parser = argparse.ArgumentParser()
parser.add_argument("pathQgis", default=str(getInstallationFolder()))
parser.add_argument(
"-t",
"--tipo",
default="Carta Topográfica 1.3",
choices=(
"Carta Topográfica 1.3",
"Carta Topográfica 1.4",
"Carta Ortoimagem 2.4",
"Carta Ortoimagem 2.5",
"Carta Ortoimagem OM 1.0",
"Carta Ortoimagem Militar 2.4",
"Carta Ortoimagem Militar 2.5",
"Carta Topográfica Militar 1.3",
"Carta Topográfica Militar 1.4",
),
type=str,
)
parser.add_argument("-j", "--json", default=[], nargs="+")
parser.add_argument("-l", "--login", dest="username", required=True)
parser.add_argument("-s", "--senha", dest="password", required=True)
parser.add_argument("-ph", "--proxyHost", type=str)
parser.add_argument("-pp", "--proxyPort", type=int)
parser.add_argument("-pu", "--proxyUser")
parser.add_argument("-ppass", "--proxyPassword")
parser.add_argument("-ef", "--exportFolder", required=True)
parser.add_argument("-et", "--exportTiff", action="store_true")
return parser.parse_args()
def getInstallationFolder() -> Path:
if sys.platform == "win32":
return next(Path("C:\\Program Files\\").glob("QGIS*"))
elif sys.platform == "linux":
pass
def startNetwork(args):
if all((args.proxyHost, args.proxyPort, args.proxyUser, args.proxyPassword)):
proxy = QNetworkProxy(
QNetworkProxy.HttpProxy,
args.proxyHost,
args.proxyPort,
args.proxyUser,
args.proxyPassword,
)
else:
proxy = QNetworkProxy(QNetworkProxy.NoProxy)
manager = QgsNetworkAccessManager().instance()
manager.setFallbackProxyAndExcludes(proxy, [], [])
if __name__ == "__main__":
args = setupArgparser()
print(f"Iniciando a exportação do produto {args.tipo} de json {args.json}")
qgs = QgsApplication([], True, profileFolder="default")
qgs.initQgis()
p = Path(args.pathQgis)
prefixPath = p / "apps/qgis"
qgs.setPrefixPath(str(prefixPath), True)
pluginsFolder = Path(
"~\\AppData\\Roaming\\QGIS\\QGIS3\\profiles\\default\\python\\plugins"
).expanduser()
qgs.setPluginPath(str(pluginsFolder))
sys.path.append(str(p / "apps/qgis/python/plugins"))
sys.path.append(str(pluginsFolder))
# para funcionar tem que ser nesse escopo, nao pode encapsular numa funcao
from ferramentas_edicao.modules.expressionFunctions.functions.createCustomGridNumbers import (
longNumber,
shortNumber,
)
from processing.core.Processing import Processing
from ferramentas_edicao.modules.processings.provider import Provider
from DsgTools.core.DSGToolsProcessingAlgs.dsgtoolsProcessingAlgorithmProvider import (
DSGToolsProcessingAlgorithmProvider,
)
Processing.initialize()
feProvider = Provider()
QgsApplication.processingRegistry().addProvider(feProvider)
dsgtoolsProvider = DSGToolsProcessingAlgorithmProvider()
QgsApplication.processingRegistry().addProvider(dsgtoolsProvider)
QgsExpression.registerFunction(longNumber)
QgsExpression.registerFunction(shortNumber)
startNetwork(args)
exportMaps(args)
qgs.exitQgis()