@@ -1061,18 +1061,72 @@ def processAlgorithm(self, progress):
1061
1061
1062
1062
selectindex = layer .dataProvider ().fieldNameIndex (attribute )
1063
1063
1064
+ selectType = layer .dataProvider ().fields ()[selectindex ].type ()
1065
+ selectionError = False
1066
+
1067
+ if selectType == 2 :
1068
+ try :
1069
+ y = int (comparisonvalue )
1070
+ except ValueError :
1071
+ selectionError = True
1072
+ msg = "Cannot convert \" " + unicode (comparisonvalue ) + "\" to integer"
1073
+ elif selectType == 6 :
1074
+ try :
1075
+ y = float (comparisonvalue )
1076
+ except ValueError :
1077
+ selectionError = True
1078
+ msg = "Cannot convert \" " + unicode (comparisonvalue ) + "\" to float"
1079
+ elif selectType == 10 : # 10: string, boolean
1080
+ try :
1081
+ y = unicode (comparisonvalue )
1082
+ except ValueError :
1083
+ selectionError = True
1084
+ msg = "Cannot convert \" " + unicode (comparisonvalue ) + "\" to unicode"
1085
+ elif selectType == 14 : # date
1086
+ dateAndFormat = comparisonvalue .split (" " )
1087
+
1088
+ if len (dateAndFormat ) == 1 :
1089
+ y = QLocale .system ().toDate (dateAndFormat [0 ]) # QtCore.QDate object
1090
+
1091
+ if y .isNull ():
1092
+ msg = "Cannot convert \" " + unicode (dateAndFormat ) + "\" to date with system date format " + QLocale .system ().dateFormat ()
1093
+ elif len (dateAndFormat ) == 2 :
1094
+ y = QDate .fromString (dateAndFormat [0 ], dateAndFormat [1 ])
1095
+
1096
+ if y .isNull ():
1097
+ msg = "Cannot convert \" " + unicode (dateAndFormat [0 ]) + "\" to date with format string \" " + unicode (dateAndFormat [1 ] + "\" . " )
1098
+ else :
1099
+ y = QDate ()
1100
+ msg = ""
1101
+
1102
+ if y .isNull (): # conversion was unsuccessfull
1103
+ selectionError = True
1104
+ msg += "Enter the date and the date format, e.g. \" 07.26.2011\" \" MM.dd.yyyy\" ."
1105
+
1106
+ if ((comparison == 'begins with' ) or (comparison == 'contains' )) and selectType != 10 :
1107
+ selectionError = True
1108
+ msg = "\" " + comparison + "\" can only be used with string fields"
1109
+
1110
+ if selectionError :
1111
+ raise GeoAlgorithmExecutionException ("Error in selection input: " + msg )
1112
+
1064
1113
readcount = 0
1065
1114
selected = []
1066
1115
totalcount = layer .featureCount ()
1067
1116
for feature in layer .getFeatures ():
1068
- if (comparison == 'begins with' ) or (comparison == 'contains' ) or \
1069
- isinstance (feature .attributes ()[selectindex ], basestring ) or \
1070
- isinstance (comparisonvalue , basestring ):
1071
- x = unicode (feature .attributes ()[selectindex ])
1072
- y = unicode (comparisonvalue )
1073
- else :
1074
- x = float (feature .attributes ()[selectindex ])
1075
- y = float (comparisonvalue )
1117
+ aValue = feature [selectindex ]
1118
+
1119
+ if aValue == None :
1120
+ continue
1121
+
1122
+ if selectType == 2 :
1123
+ x = int (aValue )
1124
+ elif selectType == 6 :
1125
+ x = float (aValue )
1126
+ elif selectType == 10 : # 10: string, boolean
1127
+ x = unicode (aValue )
1128
+ elif selectType == 14 : # date
1129
+ x = aValue # should be date
1076
1130
1077
1131
match = False
1078
1132
if (comparison == '==' ):
0 commit comments