Skip to content

Commit a6f9b18

Browse files
committed
parsing of geodata
1 parent 3b8d038 commit a6f9b18

File tree

2 files changed

+92
-19
lines changed

2 files changed

+92
-19
lines changed

geocouche_QWidget.py

Lines changed: 84 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ def setup_processing(self):
6262
layout = QGridLayout()
6363

6464
self.plot_stereonet_QPushButton = QPushButton(self.tr("Plot stereonet"))
65-
self.plot_stereonet_QPushButton.clicked.connect( self.plot_stereonet )
65+
self.plot_stereonet_QPushButton.clicked.connect( self.process_geodata )
6666
layout.addWidget(self.plot_stereonet_QPushButton, 0, 0, 1, 1 )
6767

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

72-
self.plot_selected_data_QRadioButton = QRadioButton("selected")
72+
self.plot_selected_data_QRadioButton = QRadioButton("selection")
7373
layout.addWidget(self.plot_selected_data_QRadioButton, 0,2,1,1)
7474

7575
processing_QGroupBox.setLayout(layout)
@@ -156,9 +156,9 @@ def parse_field_choice(self, val, choose_message):
156156
return val
157157

158158

159-
def get_used_field_names(self):
159+
def get_actual_field_names(self):
160160

161-
used_field_names = []
161+
actual_field_names = []
162162

163163
usable_fields = [self.structural_input_params["plane_azimuth_name_field"],
164164
self.structural_input_params["plane_dip_name_field"],
@@ -167,24 +167,96 @@ def get_used_field_names(self):
167167

168168
for usable_fld in usable_fields:
169169
if usable_fld is not None:
170-
used_field_names.append(usable_fld)
170+
actual_field_names.append(usable_fld)
171171

172-
return used_field_names
172+
return actual_field_names
173+
174+
175+
def get_actual_data_type(self):
176+
177+
# define type for planar data
178+
if self.structural_input_params["plane_azimuth_name_field"] is not None and \
179+
self.structural_input_params["plane_dip_name_field"] is not None:
180+
planar_data = True
181+
if self.structural_input_params["plane_azimuth_type"] == "dip dir.":
182+
planar_az_type = "dip_dir"
183+
elif self.structural_input_params["plane_azimuth_type"] == "strike rhr":
184+
planar_az_type = "strike_rhr"
185+
planar_dip_type = "dip"
186+
else:
187+
planar_data = False
188+
planar_az_type = None
189+
planar_dip_type = None
190+
191+
# define type for linear data
192+
if self.structural_input_params["line_azimuth_name_field"] is not None and \
193+
self.structural_input_params["line_dip_name_field"] is not None:
194+
linear_data = True
195+
linear_az_type = "trend"
196+
linear_dip_type = "plunge"
197+
else:
198+
linear_data = False
199+
linear_az_type = None
200+
linear_dip_type = None
201+
202+
203+
return dict(planar_data = planar_data,
204+
planar_az_type = planar_az_type,
205+
planar_dip_type = planar_dip_type,
206+
linear_data = linear_data,
207+
linear_az_type = linear_az_type,
208+
linear_dip_type = linear_dip_type)
209+
173210

211+
def process_geodata(self):
174212

175-
def plot_stereonet(self):
213+
# get used field names in the point attribute table
214+
self.actual_field_names = self.get_actual_field_names()
176215

177-
self.used_field_names = self.get_used_field_names()
216+
# get input data presence and type
217+
self.actual_data_type = self.get_actual_data_type()
218+
219+
# decide if using all data or just selected ones
178220
if self.plot_all_data_QRadioButton.isChecked():
179221
selected = False
180222
else:
181-
selected = True
182-
structural_data = get_point_data(self.point_layer, self.used_field_names, selected)
223+
selected = True
224+
225+
_, structural_data = get_point_data(self.point_layer, self.actual_field_names, selected)
183226

184-
for rec in structural_data:
185-
print rec
227+
input_data_types = self.get_actual_data_type()
228+
229+
xy_vals, plane_orientations, lineament_orientations = self.parse_geodata(input_data_types, structural_data)
186230

231+
for rec in lineament_orientations:
232+
print rec
187233

234+
235+
def parse_geodata(self, input_data_types, structural_data):
236+
237+
xy_vals = [ (float(rec[0]), float(rec[1]) ) for rec in structural_data]
238+
239+
if input_data_types["planar_data"]:
240+
if input_data_types["planar_az_type"] == "dip_dir":
241+
dipdir_vals = [ float(rec[2]) for rec in structural_data]
242+
elif input_data_types["planar_az_type"] == "strike_rhr":
243+
dipdir_raw_vals = [ float(rec[2]) + 90.0 for rec in structural_data]
244+
dipdir_vals = [ val if val < 360.0 else val - 360.0 for val in dipdir_raw_vals ]
245+
dipangle_vals = [ float(rec[3]) for rec in structural_data]
246+
plane_vals = zip(dipdir_vals, dipangle_vals)
247+
line_data_ndx_start = 4
248+
else:
249+
plane_vals = None
250+
line_data_ndx_start = 2
251+
252+
if input_data_types["linear_data"]:
253+
line_vals = [ (float(rec[line_data_ndx_start]), float(rec[line_data_ndx_start + 1])) for rec in structural_data]
254+
else:
255+
line_vals = None
256+
257+
return xy_vals, plane_vals, line_vals
258+
259+
188260
def open_help_page(self):
189261

190262
import webbrowser

geosurf/qgs_tools.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,18 @@ def pt_geoms_attrs( pt_layer, field_list = [] ):
111111
return rec_list
112112

113113

114-
def get_point_data( pt_layer, field_list = [], selected = True ):
115-
114+
def get_point_data( pt_layer, fields = [], selected = True ):
116115

117116
if selected == False or pt_layer.selectedFeatureCount() == 0:
118117
features = pt_layer.getFeatures()
119118
else:
120119
features = pt_layer.selectedFeatures()
121120

122121
provider = pt_layer.dataProvider()
123-
field_indices = [ provider.fieldNameIndex( field_name ) for field_name in field_list ]
122+
field_indices = [ provider.fieldNameIndex( field_name ) for field_name in fields ]
124123

125124
# retrieve selected features with their geometry and relevant attributes
126-
rec_list = []
125+
rec_values = []
127126
for feature in features:
128127
# fetch point geometry
129128
pt = feature.geometry().asPoint()
@@ -133,9 +132,11 @@ def get_point_data( pt_layer, field_list = [], selected = True ):
133132
for field_ndx in field_indices:
134133
feat_list.append( str( feature.attribute( attrs[ field_ndx ].name() ) ) )
135134
# add to result list
136-
rec_list.append( feat_list )
137-
138-
return rec_list
135+
rec_values.append( feat_list )
136+
137+
field_names = ["x","y"] + fields
138+
139+
return field_names, rec_values
139140

140141

141142
def line_geoms_attrs( line_layer, field_list = [] ):

0 commit comments

Comments
 (0)