gws.base.search.filter

OGC Filter Encoding 2.0 parser and matcher.

Source code: gws.base.search.filter

Module Contents

exception gws.base.search.filter.Error

Bases: gws.Error

Invalid or unsupported filter.

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 Filter root element with exactly one predicate, a logical operator (And, Or, Not) or a supported comparison or BBOX predicate. And and Or with a single operand are reduced to that operand. A comparison requires a ValueReference or PropertyName and a Literal, BBOX requires a property name and a GML Envelope.

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 shape attribute. Subclasses can override get_property and get_shape to 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:

True if the comparison succeeds, False if the property value is None.

get_property(obj, prop)

Return a property value of an object.

Parameters:
  • obj – Object to match.

  • prop – Property name.

Returns:

The attribute value, or None if the object has no such attribute.

get_shape(obj)

Return the geometry of an object.

Parameters:

obj – Object to match.

Returns:

The shape attribute, or None if the object has none.

match_and(flt, obj)

Check if an object matches all sub-filters.

Parameters:
  • flt – Search filter with the And operator.

  • obj – Object to match.

Returns:

True if all sub-filters match.

match_bbox(flt, obj)

Check if the object geometry intersects the filter box.

Parameters:
  • flt – Search filter with the BBOX operator.

  • obj – Object to match.

Returns:

True if the geometry intersects the box, False if 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 Not operator.

  • obj – Object to match.

Returns:

True if 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 Or operator.

  • obj – Object to match.

Returns:

True if 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 PropertyIsEqualTo operator.

  • obj – Object to match.

Returns:

True if the property matches.

match_propertyisgreaterthan(flt, obj)

Check if a property is greater than the filter value.

Parameters:
  • flt – Search filter with the PropertyIsGreaterThan operator.

  • obj – Object to match.

Returns:

True if 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 PropertyIsGreaterThanOrEqualTo operator.

  • obj – Object to match.

Returns:

True if the property matches.

match_propertyislessthan(flt, obj)

Check if a property is less than the filter value.

Parameters:
  • flt – Search filter with the PropertyIsLessThan operator.

  • obj – Object to match.

Returns:

True if 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 PropertyIsLessThanOrEqualTo operator.

  • obj – Object to match.

Returns:

True if the property matches.

match_propertyisnotequalto(flt, obj)

Check if a property is not equal to the filter value.

Parameters:
  • flt – Search filter with the PropertyIsNotEqualTo operator.

  • obj – Object to match.

Returns:

True if 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:

True if the object matches the filter.

Raises:

AttributeError – If the filter operator is not supported.