Skip to content

Commit 954ee20

Browse files
committedMar 20, 2017
[FEATURE][processing] Add 'does not contain' to Extract By Attribute
1 parent f60dc81 commit 954ee20

File tree

4 files changed

+84
-3
lines changed

4 files changed

+84
-3
lines changed
 

‎python/plugins/processing/algs/qgis/ExtractByAttribute.py

100644100755
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@ class ExtractByAttribute(GeoAlgorithm):
5353
'begins with',
5454
'contains',
5555
'is null',
56-
'is not null'
56+
'is not null',
57+
'does not contain'
5758
]
5859
STRING_OPERATORS = ['begins with',
59-
'contains']
60+
'contains',
61+
'does not contain']
6062

6163
def defineCharacteristics(self):
6264
self.name, self.i18n_name = self.trAlgorithm('Extract by attribute')
@@ -72,7 +74,9 @@ def defineCharacteristics(self):
7274
self.tr('begins with'),
7375
self.tr('contains'),
7476
self.tr('is null'),
75-
self.tr('is not null')]
77+
self.tr('is not null'),
78+
self.tr('does not contain')
79+
]
7680

7781
self.addParameter(ParameterVector(self.INPUT,
7882
self.tr('Input Layer')))
@@ -112,6 +116,8 @@ def processAlgorithm(self, feedback):
112116
expr = """%s LIKE '%s%%'""" % (field_ref, value)
113117
elif operator == 'contains':
114118
expr = """%s LIKE '%%%s%%'""" % (field_ref, value)
119+
elif operator == 'does not contain':
120+
expr = """%s NOT LIKE '%%%s%%'""" % (field_ref, value)
115121
else:
116122
expr = '{} {} {}'.format(field_ref, operator, quoted_val)
117123

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<GMLFeatureClassList>
2+
<GMLFeatureClass>
3+
<Name>extract_by_attribute_does_not_contain</Name>
4+
<ElementPath>extract_by_attribute_does_not_contain</ElementPath>
5+
<!--POLYGON-->
6+
<GeometryType>3</GeometryType>
7+
<SRSName>EPSG:4326</SRSName>
8+
<DatasetSpecificInfo>
9+
<FeatureCount>2</FeatureCount>
10+
<ExtentXMin>2.00000</ExtentXMin>
11+
<ExtentXMax>10.00000</ExtentXMax>
12+
<ExtentYMin>-3.00000</ExtentYMin>
13+
<ExtentYMax>2.00000</ExtentYMax>
14+
</DatasetSpecificInfo>
15+
<PropertyDefn>
16+
<Name>name</Name>
17+
<ElementPath>name</ElementPath>
18+
<Type>String</Type>
19+
<Width>4</Width>
20+
</PropertyDefn>
21+
<PropertyDefn>
22+
<Name>intval</Name>
23+
<ElementPath>intval</ElementPath>
24+
<Type>Integer</Type>
25+
</PropertyDefn>
26+
<PropertyDefn>
27+
<Name>floatval</Name>
28+
<ElementPath>floatval</ElementPath>
29+
<Type>Real</Type>
30+
</PropertyDefn>
31+
</GMLFeatureClass>
32+
</GMLFeatureClassList>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ogr:FeatureCollection
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation=""
5+
xmlns:ogr="http://ogr.maptools.org/"
6+
xmlns:gml="http://www.opengis.net/gml">
7+
<gml:boundedBy>
8+
<gml:Box>
9+
<gml:coord><gml:X>2</gml:X><gml:Y>-3</gml:Y></gml:coord>
10+
<gml:coord><gml:X>10</gml:X><gml:Y>2</gml:Y></gml:coord>
11+
</gml:Box>
12+
</gml:boundedBy>
13+
14+
<gml:featureMember>
15+
<ogr:extract_by_attribute_does_not_contain fid="polys.3">
16+
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>6,1 10,1 10,-3 6,-3 6,1</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs><gml:innerBoundaryIs><gml:LinearRing><gml:coordinates>7,0 7,-2 9,-2 9,0 7,0</gml:coordinates></gml:LinearRing></gml:innerBoundaryIs></gml:Polygon></ogr:geometryProperty>
17+
<ogr:name>ASDF</ogr:name>
18+
<ogr:intval>0</ogr:intval>
19+
</ogr:extract_by_attribute_does_not_contain>
20+
</gml:featureMember>
21+
<gml:featureMember>
22+
<ogr:extract_by_attribute_does_not_contain fid="polys.5">
23+
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>3,2 6,1 6,-3 2,-1 2,2 3,2</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
24+
<ogr:name>elim</ogr:name>
25+
<ogr:intval>2</ogr:intval>
26+
<ogr:floatval>3.33</ogr:floatval>
27+
</ogr:extract_by_attribute_does_not_contain>
28+
</gml:featureMember>
29+
</ogr:FeatureCollection>

‎python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,6 +1523,20 @@ tests:
15231523
name: expected/extract_by_attribute_contains.gml
15241524
type: vector
15251525

1526+
- algorithm: qgis:extractbyattribute
1527+
name: Extract by attribute (does not contain)
1528+
params:
1529+
FIELD: name
1530+
INPUT:
1531+
name: polys.gml
1532+
type: vector
1533+
OPERATOR: '10'
1534+
VALUE: a
1535+
results:
1536+
OUTPUT:
1537+
name: expected/extract_by_attribute_does_not_contain.gml
1538+
type: vector
1539+
15261540
- algorithm: qgis:extractbyattribute
15271541
name: Extract by attribute (greater)
15281542
params:

0 commit comments

Comments
 (0)
Please sign in to comment.