Skip to content
Permalink
Browse files
[FEATURE][processing] Add 'does not contain' to Extract By Attribute
  • Loading branch information
nyalldawson committed Mar 20, 2017
1 parent f60dc81 commit 954ee203891738b05e4cdf49f075cad839aef54a
@@ -53,10 +53,12 @@ class ExtractByAttribute(GeoAlgorithm):
'begins with',
'contains',
'is null',
'is not null'
'is not null',
'does not contain'
]
STRING_OPERATORS = ['begins with',
'contains']
'contains',
'does not contain']

def defineCharacteristics(self):
self.name, self.i18n_name = self.trAlgorithm('Extract by attribute')
@@ -72,7 +74,9 @@ def defineCharacteristics(self):
self.tr('begins with'),
self.tr('contains'),
self.tr('is null'),
self.tr('is not null')]
self.tr('is not null'),
self.tr('does not contain')
]

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

@@ -0,0 +1,32 @@
<GMLFeatureClassList>
<GMLFeatureClass>
<Name>extract_by_attribute_does_not_contain</Name>
<ElementPath>extract_by_attribute_does_not_contain</ElementPath>
<!--POLYGON-->
<GeometryType>3</GeometryType>
<SRSName>EPSG:4326</SRSName>
<DatasetSpecificInfo>
<FeatureCount>2</FeatureCount>
<ExtentXMin>2.00000</ExtentXMin>
<ExtentXMax>10.00000</ExtentXMax>
<ExtentYMin>-3.00000</ExtentYMin>
<ExtentYMax>2.00000</ExtentYMax>
</DatasetSpecificInfo>
<PropertyDefn>
<Name>name</Name>
<ElementPath>name</ElementPath>
<Type>String</Type>
<Width>4</Width>
</PropertyDefn>
<PropertyDefn>
<Name>intval</Name>
<ElementPath>intval</ElementPath>
<Type>Integer</Type>
</PropertyDefn>
<PropertyDefn>
<Name>floatval</Name>
<ElementPath>floatval</ElementPath>
<Type>Real</Type>
</PropertyDefn>
</GMLFeatureClass>
</GMLFeatureClassList>
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=""
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
<gml:Box>
<gml:coord><gml:X>2</gml:X><gml:Y>-3</gml:Y></gml:coord>
<gml:coord><gml:X>10</gml:X><gml:Y>2</gml:Y></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:extract_by_attribute_does_not_contain fid="polys.3">
<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>
<ogr:name>ASDF</ogr:name>
<ogr:intval>0</ogr:intval>
</ogr:extract_by_attribute_does_not_contain>
</gml:featureMember>
<gml:featureMember>
<ogr:extract_by_attribute_does_not_contain fid="polys.5">
<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>
<ogr:name>elim</ogr:name>
<ogr:intval>2</ogr:intval>
<ogr:floatval>3.33</ogr:floatval>
</ogr:extract_by_attribute_does_not_contain>
</gml:featureMember>
</ogr:FeatureCollection>
@@ -1523,6 +1523,20 @@ tests:
name: expected/extract_by_attribute_contains.gml
type: vector

- algorithm: qgis:extractbyattribute
name: Extract by attribute (does not contain)
params:
FIELD: name
INPUT:
name: polys.gml
type: vector
OPERATOR: '10'
VALUE: a
results:
OUTPUT:
name: expected/extract_by_attribute_does_not_contain.gml
type: vector

- algorithm: qgis:extractbyattribute
name: Extract by attribute (greater)
params:

0 comments on commit 954ee20

Please sign in to comment.