-
Notifications
You must be signed in to change notification settings - Fork 1
/
errorhandling.py
346 lines (159 loc) · 8.87 KB
/
errorhandling.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
# -*- coding: utf-8 -*-
"""
/***************************************************************************
profileAARDialog
A QGIS plugin
profileAAR des
-------------------
begin : 2019-02-06
git sha : $Format:%H$
copyright : (C) 2019 by Moritz Mennenga / Kay Schmuetz
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* '
' A QGIS-Plugin by members of '
' ISAAK (https://isaakiel.github.io/) '
' Lower Saxony Institute for Historical Coastal Research '
' University of Kiel '
' 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. *
* *
***************************************************************************/
"""
from __future__ import absolute_import
from builtins import chr
from builtins import str
from builtins import range
from builtins import object
from qgis.core import *
#from numpy import std, mean, cross
import numpy
from numpy import *
import sys
from math import pi, fabs, atan
import scipy
from .messageWrapper import criticalMessageToBar, printLogMessage
#columreader in a "table" (list of lists)
def columnreader(list_in_list_object, columnindex):
columnvalues = []
for i in range(len(list_in_list_object)):
columnvalues.append(list_in_list_object[i][columnindex])
return columnvalues
class ErrorHandler(object):
def __init__(self, qgisInterface):
self.qgisInterface = qgisInterface
#Checks that have to do on every single Profile
def singleprofile(self, coord_proc, view_check, profile_name, selection_check):
# TODO: check for consistency before calculation
# TODO: check for spatial consistency (no points should be more than x meters apart)
errorCheck = False
# check if actual profile has less then 4 points
if len(coord_proc) <= 3:
#if it is less, print error message
criticalMessageToBar(self, 'Error','A profile needs min. 4 points. Error on profile: '+str(profile_name))
printLogMessage(self,'A profile needs min. 4 points. Error on profile: '+str(profile_name), 'Error_LOG')
#cancel execution of the script
errorCheck = True
# check if the view value is the same in all features
if len(view_check) != 1:
# if it is not the same, print error message
criticalMessageToBar(self, 'Error', 'The view column of your data is inconsistant (either non or two different views are present). Error on profile: ' + str(profile_name))
printLogMessage(self,'The view column of your data is inconsistant (either non or two different views are present). Error on profile: ' + str(profile_name), 'Error_LOG')
# cancel execution of the script
errorCheck = True
# check if the view is one of the four cardinal directions
if view_check[0].upper() not in ["N", "E", "S", "W"]:
# if it is not the same, print error message
criticalMessageToBar(self, 'Error', 'The view value is not one of the four cardinal directions. Error on profile: ' + str(profile_name))
printLogMessage(self,'The view value is not one of the four cardinal directions. Error on profile: ' + str(profile_name), 'Error_LOG')
# cancel execution of the script
errorCheck = True
#CHANGE1 check if the selection/use is 0 or 1
for i in range(len(selection_check)):
if str(selection_check[i]) not in ["1", "0"]:
# if it is not the same, print error message
criticalMessageToBar(self, 'Error', 'Only 0 or 1 are allowed in the selection/use. Error on profile: ' + str(profile_name))
printLogMessage(self,
'Only 0 or 1 are allowed in the selection/use. Error on profile: : ' + str(profile_name), 'Error_LOG')
# cancel execution of the script
errorCheck = True
# check if the coordinates x, y, z fall into 2 sigma range
#instance a table like list of lists with i rows and j columns
warning_message = []
for i in range(3):
xyz = []
xyz_lower = []
xyz_upper = []
xyz = columnreader(coord_proc, i)
xyz_lower = mean(xyz) - (2 * std(xyz))
xyz_upper = mean(xyz) + (2 * std(xyz))
for j in range(len(xyz)):
if xyz[j] < xyz_lower or xyz[j] > xyz_upper:
#warning_message.append("Warning: Profile " )+ str(profile_name) + chr(120+i) + str(j) + 'excedes th 2 std interval of ' + chr(120+i))
criticalMessageToBar(self, 'Warning',
'Warning: Profile ' + str(profile_name) +': '+ chr(120+i) + 'Pt ' + str(j+1) + ' exceeds the 2std interval of ' + chr(120+i))
printLogMessage(self,
'Warning: Profile ' + str(profile_name) +': '+ chr(120+i) + 'Pt ' + str(j+1) + ' exceeds the 2std interval of ' + chr(120+i), 'Error_LOG')
return errorCheck
#self.qgisInterface.messageBar().pushMessage('\n'.join(warning_message), level=QgsMessageBar.INFO)
#general checks for the fields of the layer after the import
def field_check (self, layer, z_field):
errorCheck = False
#Check if the vectorlayer is projected
if layer.crs().isGeographic() == True:
criticalMessageToBar(self, 'Error',
"Layer "+layer.name()+ " is not projected. Please choose an projected reference system.")
printLogMessage(self,"Layer "+layer.name()+ " is not projected. Please choose an projected reference system.", 'Error_LOG')
# cancel execution of the script
errorCheck = True
#check the z-field
for field in layer.fields():
#Take a look for the z Field
if str(field.name()) == str(z_field):
# if the z value is not a float
if field.typeName() != "Real" and field.typeName() != "double":
#Give a message
criticalMessageToBar(self, 'Error',
'The z-Value needs to be a float. Check the field type of the z-Value')
printLogMessage(self,
'The z-Value needs to be a float. Check the field type of the z-Value', 'Error_LOG')
# cancel execution of the script
errorCheck = True
return errorCheck
#checks if the inputfields are filled correct
def input_check(self, value):
errorCheck = False
if str(value) == "":
criticalMessageToBar(self, 'Error',
'Please choose an output file!')
# cancel execution of the script
errorCheck = True
return errorCheck
def calculateError(self, linegress, xw, yw, prnumber):
intercept = linegress[1]
slope = linegress[0]
xwpl =numpy.array(xw)
ywpl = numpy.array(yw)
#predict points on line
for i in range(len(xw)):
#Predict the value for the minmal x
if xw[i] == min(xw):
x1pred = xw[i]
y1pred = intercept + slope*xw[i]
p1= numpy.array([x1pred ,y1pred])
#Predict the value for the maximal x
if xw[i] == max(xw):
x2pred = xw[i]
y2pred = intercept + slope*xw[i]
p2 = numpy.array([x2pred ,y2pred])
#Calculate the distance from every point to the line.
distance = []
#Export this value to every point, and give a sum of all distances indicator: sum = 0, fine; sum = max point (this is the bad one) ; sum > max point (maybe more than one are bad)
for i in range(len(xw)):
p3 = numpy.array([xw[i],yw[i]])
distance.append(linalg.norm(cross(p2-p1, p1-p3))/linalg.norm(p2-p1))
return distance