Skip to content

Commit

Permalink
data extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
mauroalberti committed Apr 25, 2015
1 parent df2cfd6 commit 3b8d038
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 25 deletions.
93 changes: 70 additions & 23 deletions geocouche_QWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
from PyQt4.QtGui import *

from qgis.core import QgsMapLayerRegistry
from geosurf.qgs_tools import loaded_point_layers
from geosurf.qgs_tools import loaded_point_layers, get_point_data


class geocouche_QWidget( QWidget ):


input_plane_azimuth_types = ["dip dir.", "strike rhr"]
input_plane_dip_types = ["dip angle"]

Expand All @@ -29,9 +30,10 @@ def __init__( self, canvas, plugin_name ):

def setup_gui( self ):

self.dialog_layout = QVBoxLayout()
self.dialog_layout = QHBoxLayout()

self.dialog_layout.addWidget( self.setup_inputdata() )
self.dialog_layout.addWidget( self.setup_processing() )

self.setLayout(self.dialog_layout)
self.adjustSize()
Expand All @@ -51,7 +53,29 @@ def setup_inputdata(self):
input_QGroupBox.setLayout(layout)

return input_QGroupBox



def setup_processing(self):

processing_QGroupBox = QGroupBox("Processing")

layout = QGridLayout()

self.plot_stereonet_QPushButton = QPushButton(self.tr("Plot stereonet"))
self.plot_stereonet_QPushButton.clicked.connect( self.plot_stereonet )
layout.addWidget(self.plot_stereonet_QPushButton, 0, 0, 1, 1 )

self.plot_all_data_QRadioButton = QRadioButton("all data")
self.plot_all_data_QRadioButton.setChecked(True)
layout.addWidget(self.plot_all_data_QRadioButton, 0,1,1,1)

self.plot_selected_data_QRadioButton = QRadioButton("selected")
layout.addWidget(self.plot_selected_data_QRadioButton, 0,2,1,1)

processing_QGroupBox.setLayout(layout)

return processing_QGroupBox


def define_structural_input_params( self ):

Expand All @@ -65,7 +89,7 @@ def define_structural_input_params( self ):

if dialog.exec_():
try:
structural_input_params = self.get_structural_input_params( dialog )
point_layer, structural_input_params = self.get_structural_input_params( dialog )
except:
self.warn( "Incorrect definition")
return
Expand All @@ -79,17 +103,12 @@ def define_structural_input_params( self ):
else:
self.info("Input data defined")

self.point_layer = point_layer
self.structural_input_params = structural_input_params


def formally_valid_params(self, structural_input_params ):

print structural_input_params["plane_azimuth_name_field"]
print structural_input_params["plane_dip_name_field"]
print structural_input_params["line_azimuth_name_field"]
print structural_input_params["line_dip_name_field"]


if structural_input_params["plane_azimuth_name_field"] is not None and \
structural_input_params["plane_dip_name_field"] is not None:
return True
Expand All @@ -107,27 +126,26 @@ def get_structural_input_params(self, dialog ):

field_undefined_txt = dialog.field_undefined_txt

plane_azimuth_type_field = dialog.input_plane_orient_azimuth_type_QComboBox.currentText()
plane_azimuth_type = dialog.input_plane_orient_azimuth_type_QComboBox.currentText()
plane_azimuth_name_field = self.parse_field_choice(dialog.input_plane_azimuth_srcfld_QComboBox.currentText(), field_undefined_txt)

plane_dip_type_field = dialog.input_plane_orient_dip_type_QComboBox.currentText()
plane_dip_type = dialog.input_plane_orient_dip_type_QComboBox.currentText()
plane_dip_name_field = self.parse_field_choice(dialog.input_plane_dip_srcfld_QComboBox.currentText(), field_undefined_txt)

line_azimuth_type_field = dialog.input_line_orient_azimuth_type_QComboBox.currentText()
line_azimuth_type = dialog.input_line_orient_azimuth_type_QComboBox.currentText()
line_azimuth_name_field = self.parse_field_choice( dialog.input_line_azimuth_srcfld_QComboBox.currentText(), field_undefined_txt)

line_dip_type_field = dialog.input_line_orient_dip_type_QComboBox.currentText()
line_dip_type = dialog.input_line_orient_dip_type_QComboBox.currentText()
line_dip_name_field = self.parse_field_choice( dialog.input_line_dip_srcfld_QComboBox.currentText(), field_undefined_txt)

return dict(point_layer = point_layer,
plane_azimuth_type_field = plane_azimuth_type_field,
plane_azimuth_name_field = plane_azimuth_name_field,
plane_dip_type_field = plane_dip_type_field,
plane_dip_name_field = plane_dip_name_field,
line_azimuth_type_field = line_azimuth_type_field,
line_azimuth_name_field = line_azimuth_name_field,
line_dip_type_field = line_dip_type_field,
line_dip_name_field = line_dip_name_field)
return point_layer, dict(plane_azimuth_type = plane_azimuth_type,
plane_azimuth_name_field = plane_azimuth_name_field,
plane_dip_type = plane_dip_type,
plane_dip_name_field = plane_dip_name_field,
line_azimuth_type = line_azimuth_type,
line_azimuth_name_field = line_azimuth_name_field,
line_dip_type = line_dip_type,
line_dip_name_field = line_dip_name_field)


def parse_field_choice(self, val, choose_message):
Expand All @@ -136,7 +154,36 @@ def parse_field_choice(self, val, choose_message):
return None
else:
return val


def get_used_field_names(self):

used_field_names = []

usable_fields = [self.structural_input_params["plane_azimuth_name_field"],
self.structural_input_params["plane_dip_name_field"],
self.structural_input_params["line_azimuth_name_field"],
self.structural_input_params["line_dip_name_field"] ]

for usable_fld in usable_fields:
if usable_fld is not None:
used_field_names.append(usable_fld)

return used_field_names


def plot_stereonet(self):

self.used_field_names = self.get_used_field_names()
if self.plot_all_data_QRadioButton.isChecked():
selected = False
else:
selected = True
structural_data = get_point_data(self.point_layer, self.used_field_names, selected)

for rec in structural_data:
print rec


def open_help_page(self):

Expand Down
4 changes: 2 additions & 2 deletions geocouche_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ def open_geocouche_widget(self):

geocouche_DockWidget = QDockWidget( 'geocouche', self.interface.mainWindow() )
geocouche_DockWidget.setAttribute(Qt.WA_DeleteOnClose)
geocouche_DockWidget.setAllowedAreas( Qt.RightDockWidgetArea | Qt.LeftDockWidgetArea )
geocouche_DockWidget.setAllowedAreas( Qt.BottomDockWidgetArea | Qt.TopDockWidgetArea )
self.geocouche_QWidget = geocouche_QWidget( self.canvas, self.plugin_name )
geocouche_DockWidget.setWidget( self.geocouche_QWidget )
geocouche_DockWidget.destroyed.connect( self.closeEvent )
self.interface.addDockWidget( Qt.RightDockWidgetArea, geocouche_DockWidget )
self.interface.addDockWidget( Qt.BottomDockWidgetArea, geocouche_DockWidget )

self.is_geocouche_widget_open = True

Expand Down
27 changes: 27 additions & 0 deletions geosurf/qgs_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,33 @@ def pt_geoms_attrs( pt_layer, field_list = [] ):
return rec_list


def get_point_data( pt_layer, field_list = [], selected = True ):


if selected == False or pt_layer.selectedFeatureCount() == 0:
features = pt_layer.getFeatures()
else:
features = pt_layer.selectedFeatures()

provider = pt_layer.dataProvider()
field_indices = [ provider.fieldNameIndex( field_name ) for field_name in field_list ]

# retrieve selected features with their geometry and relevant attributes
rec_list = []
for feature in features:
# fetch point geometry
pt = feature.geometry().asPoint()
attrs = feature.fields().toList()
# creates feature attribute list
feat_list = [ pt.x(), pt.y() ]
for field_ndx in field_indices:
feat_list.append( str( feature.attribute( attrs[ field_ndx ].name() ) ) )
# add to result list
rec_list.append( feat_list )

return rec_list


def line_geoms_attrs( line_layer, field_list = [] ):

lines = []
Expand Down

0 comments on commit 3b8d038

Please sign in to comment.