mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
[FEATURE][processing] Add 'does not contain' to Extract By Attribute
This commit is contained in:
parent
f60dc81102
commit
954ee20389
12
python/plugins/processing/algs/qgis/ExtractByAttribute.py
Normal file → Executable file
12
python/plugins/processing/algs/qgis/ExtractByAttribute.py
Normal file → Executable file
@ -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 @@ class ExtractByAttribute(GeoAlgorithm):
|
||||
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 @@ class ExtractByAttribute(GeoAlgorithm):
|
||||
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)
|
||||
|
||||
|
32
python/plugins/processing/tests/testdata/expected/extract_by_attribute_does_not_contain.gfs
vendored
Normal file
32
python/plugins/processing/tests/testdata/expected/extract_by_attribute_does_not_contain.gfs
vendored
Normal file
@ -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>
|
29
python/plugins/processing/tests/testdata/expected/extract_by_attribute_does_not_contain.gml
vendored
Normal file
29
python/plugins/processing/tests/testdata/expected/extract_by_attribute_does_not_contain.gml
vendored
Normal file
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user