gws.base.search.filter¶
OGC Filter Encoding 2.0 parser and matcher.
Source code: gws.base.search.filter
Module Contents¶
- gws.base.search.filter.from_fes_element(el: gws.XmlElement) gws.SearchFilter¶
Parse an FES filter from an XML element.
The element can be a
Filterroot element with exactly one predicate, a logical operator (And,Or,Not) or a supported comparison orBBOXpredicate.AndandOrwith a single operand are reduced to that operand. A comparison requires aValueReferenceorPropertyNameand aLiteral,BBOXrequires a property name and a GMLEnvelope.- Parameters:
el – XML element.
- Returns:
A search filter.
- Raises:
Error – If the filter is invalid or not supported.
- gws.base.search.filter.from_fes_string(src: str) gws.SearchFilter¶
Parse an FES filter from an XML string.
Namespaces are removed before parsing.
- Parameters:
src – XML string with a filter element.
- Returns:
A search filter.
- Raises:
Error – If the XML is invalid or the filter is invalid or not supported.
- class gws.base.search.filter.Matcher¶
Evaluates a search filter against Python objects.
By default, properties are object attributes and the geometry is the
shapeattribute. Subclasses can overrideget_propertyandget_shapeto match other kinds of objects.- compare(a, b, op)¶
Compare a property value with a filter value.
If the property value is a list, it matches if any of its elements matches.
- Parameters:
a – Property value.
b – Filter value.
op – Comparison function, like
operator.eq.
- Returns:
Trueif the comparison succeeds,Falseif the property value isNone.
- get_property(obj, prop)¶
Return a property value of an object.
- Parameters:
obj – Object to match.
prop – Property name.
- Returns:
The attribute value, or
Noneif the object has no such attribute.
- get_shape(obj)¶
Return the geometry of an object.
- Parameters:
obj – Object to match.
- Returns:
The
shapeattribute, orNoneif the object has none.
- match_and(flt, obj)¶
Check if an object matches all sub-filters.
- Parameters:
flt – Search filter with the
Andoperator.obj – Object to match.
- Returns:
Trueif all sub-filters match.
- match_bbox(flt, obj)¶
Check if the object geometry intersects the filter box.
- Parameters:
flt – Search filter with the
BBOXoperator.obj – Object to match.
- Returns:
Trueif the geometry intersects the box,Falseif the object has no geometry.
- match_not(flt, obj)¶
Check if an object does not match the first sub-filter.
- Parameters:
flt – Search filter with the
Notoperator.obj – Object to match.
- Returns:
Trueif the first sub-filter does not match.
- match_or(flt, obj)¶
Check if an object matches any sub-filter.
- Parameters:
flt – Search filter with the
Oroperator.obj – Object to match.
- Returns:
Trueif at least one sub-filter matches.
- match_propertyisequalto(flt, obj)¶
Check if a property is equal to the filter value.
- Parameters:
flt – Search filter with the
PropertyIsEqualTooperator.obj – Object to match.
- Returns:
Trueif the property matches.
- match_propertyisgreaterthan(flt, obj)¶
Check if a property is greater than the filter value.
- Parameters:
flt – Search filter with the
PropertyIsGreaterThanoperator.obj – Object to match.
- Returns:
Trueif the property matches.
- match_propertyisgreaterthanorequalto(flt, obj)¶
Check if a property is greater than or equal to the filter value.
- Parameters:
flt – Search filter with the
PropertyIsGreaterThanOrEqualTooperator.obj – Object to match.
- Returns:
Trueif the property matches.
- match_propertyislessthan(flt, obj)¶
Check if a property is less than the filter value.
- Parameters:
flt – Search filter with the
PropertyIsLessThanoperator.obj – Object to match.
- Returns:
Trueif the property matches.
- match_propertyislessthanorequalto(flt, obj)¶
Check if a property is less than or equal to the filter value.
- Parameters:
flt – Search filter with the
PropertyIsLessThanOrEqualTooperator.obj – Object to match.
- Returns:
Trueif the property matches.
- match_propertyisnotequalto(flt, obj)¶
Check if a property is not equal to the filter value.
- Parameters:
flt – Search filter with the
PropertyIsNotEqualTooperator.obj – Object to match.
- Returns:
Trueif the property matches.
- matches(flt: gws.SearchFilter, obj)¶
Check if an object matches a filter.
Calls the
match_<operator>method for the filter operator.- Parameters:
flt – Search filter.
obj – Object to match.
- Returns:
Trueif the object matches the filter.- Raises:
AttributeError – If the filter operator is not supported.