-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
76 lines (70 loc) · 3.04 KB
/
__init__.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
# -*- coding: utf-8 -*-
"""
/***************************************************************************
Stereonet
A QGIS plugin
Displays a geologic stereonet of selected data
-------------------
begin : 2016-11-29
copyright : (C) 2016 by Daniel Childs
email : [email protected]
git sha : $Format:%H$
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
This script initializes the plugin, making it known to QGIS.
"""
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
import mplstereonet
from qgis.core import *
from qgis.gui import *
import qgis.utils
import os
def classFactory(iface):
return Stereonet(iface)
class Stereonet:
def __init__(self, iface):
self.iface = iface
def initGui(self):
dir_path = os.path.dirname(os.path.realpath(__file__))
self.contourAction = QAction(QIcon(str(dir_path)+"/icon.png"), u'Stereonet', self.iface.mainWindow())
self.contourAction.triggered.connect(self.contourPlot)
self.iface.addToolBarIcon(self.contourAction)
def unload(self):
self.iface.removeToolBarIcon(self.contourAction)
del self.contourAction
def contourPlot(self):
fig, ax = mplstereonet.subplots()
strikes = list()
dips = list()
layers = self.iface.legendInterface().layers()
for layer in layers:
if layer.type() == QgsMapLayer.VectorLayer:
iter = layer.selectedFeatures()
strikeExists = layer.fieldNameIndex('strike')
ddrExists = layer.fieldNameIndex('ddr')
dipExists = layer.fieldNameIndex('dip')
for feature in iter:
if strikeExists != -1 and dipExists != -1:
strikes.append(feature['strike'])
dips.append(feature['dip'])
elif ddrExists != -1 and dipExists != -1:
strikes.append(feature['ddr']-90)
dips.append(feature['dip'])
else:
continue
cax = ax.density_contourf(strikes, dips, measurement='poles',cmap=cm.coolwarm)
ax.pole(strikes, dips, 'k+', markersize=7)
ax.grid(True)
# fig.colorbar(cax)
plt.show()