-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathferramentas_experimentais.py
164 lines (136 loc) · 5.71 KB
/
ferramentas_experimentais.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# -*- coding: utf-8 -*-
"""
/***************************************************************************
PluginTeste
A QGIS plugin
Plugin para add procssings teste
Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/
-------------------
begin : 2021-03-02
copyright : (C) 2021 by Pedro Martins
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
__author__ = 'Pedro Martins'
__date__ = '2021-03-02'
__copyright__ = '(C) 2021 by Pedro Martins'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
import os
import sys
import inspect
from qgis.core import(QgsProcessing,
QgsFeatureSink,
QgsProcessingException,
QgsProcessingAlgorithm,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterFeatureSink,
QgsProject,
QgsMapLayer,
QgsCoordinateReferenceSystem,
QgsCoordinateTransform,
QgsProject,
QgsPointXY,
QgsAbstractFeatureSource,
QgsExpression,
QgsVectorLayer,
QgsField,
QgsExpressionContext,
QgsExpressionContextScope,
QgsAuxiliaryStorage,
QgsPropertyDefinition,
QgsFeature
)
from .plugin_teste_provider import PluginTesteProvider
from PyQt5.QtWidgets import *
from PyQt5 import QtCore, QtGui
from PyQt5.QtGui import *
from PyQt5.QtCore import *
#from qgis import processing
from qgis.utils import iface
#cmd_folder = os.path.split(inspect.getfile(inspect.currentframe()))[0]
'''
if cmd_folder not in sys.path:
sys.path.insert(0, cmd_folder)
from pathlib import Path
'''
class PluginTestePlugin(object):
def __init__(self):
self.provider = None
def initProcessing(self):
"""Init Processing provider for QGIS >= 3.8."""
self.provider = PluginTesteProvider()
QgsApplication.processingRegistry().addProvider(self.provider)
def initGui(self):
self.initProcessing()
def unload(self):
QgsApplication.processingRegistry().removeProvider(self.provider)
class AzimButton:
def __init__(self, iface):
self.iface = iface
def initGui(self):
'''Start configurations'''
self.action = QAction(QIcon("C:/Users/pedromartins/AppData/Roaming/QGIS/QGIS3/profiles/default/python/plugins/plugin_teste/azim.png"), "Calcula Azimute", self.iface.mainWindow())
self.action.setWhatsThis("Configuration for test plugin")
self.action.setStatusTip("This is status tip")
# self.toolbar = self.iface.addToolBar(u"Proxy settings")
self.AbsButton = QPushButton()
self.iface.addToolBarWidget(self.AbsButton)
self.action.triggered.connect(self.calazim)
# self.comboBox.activated[str].connect(self.modifyProxy)
# create action that will start plugin configuration
#QObject.connect(self.action, SIGNAL("triggered()"), self.run)
# add toolbar button and menu item
self.iface.addToolBarIcon(self.action)
self.iface.addPluginToMenu("&Plugin teste", self.action)
# iconPath = ':/plugins/proxySetter/proxy.png'
# self.actionCBox = QAction(QIcon(iconPath), u"Setting proxy", self.iface.mainWindow())
# self.actionCBox.setStatusTip(None)
# self.actionCBox.setWhatsThis(None)
# self.actionCBox.setCheckable(True)
# self.toolbar.addAction(self.actionCBox)
def initSignals(self):
pass
def calazim(self):
layer=iface.activeLayer()
field = QgsField( 'id', QVariant.Double )
cal=QgsAuxiliaryStorage()
auxlyr=cal.createAuxiliaryLayer(field,layer)
layer.setAuxiliaryLayer(auxlyr)
auxLayer = layer.auxiliaryLayer()
vdef=QgsPropertyDefinition("azim",
1,
"azimute",
"calcula angulo azimute",
"angulo")
auxLayer.addAuxiliaryField(vdef)
auxFields = auxLayer.fields()
features=layer.getFeatures()
for feature in features:
geom=feature.geometry()
ombb=geom.orientedMinimumBoundingBox()
auxFeature = QgsFeature(auxFields)
auxFeature['ASPK']= feature['id']
angazim=ombb[2]
if ombb[4]<ombb[3]:
angazim=ombb[2]-90
if angazim<0:
angazim=ombb[2]+90
auxFeature['angulo_azim'] = angazim
'''
auxFeature['lado_lar'] = ombb[3]*1000
auxFeature['lado_alt'] = ombb[4]*1000
auxFeature['ver_boll'] = invertido
'''
auxLayer.addFeature(auxFeature)
print("testeaqui")
def unload(self):
pass