gisserver.features module

The main configuration for exposing model data in the WFS server.

The “feature type” definitions define what models and attributes are exposed in the WFS server. When a model attribute is mentioned in the feature type, it can be exposed and queried against. Any field that is not mentioned in a definition, will therefore not be available, nor queryable. This metadata is used in the GetCapabilities call to advertise all available feature types.

The “feature type” definitions ares translated internally into an internal XML Schema Definition (made from gisserver.types). That schema maps all model attributes to a specific XML layout, and includes all XSD Complex Types, elements and attributes linked to the Django model metadata.

The feature type classes (and field types) offer a flexible translation from attribute listings into a schema definition. For example, model relationships can be modelled to a different XML layout.

The FeatureType class

class gisserver.features.FeatureType(queryset: QuerySet, *, fields: list[str | FeatureField] | Literal['__all__'] | None = None, display_field_name: str | None = None, geometry_field_name: str | None = None, name: str | None = None, title: str | None = None, abstract: str | None = None, keywords: list[str] | None = None, crs: CRS | None = None, other_crs: list[CRS] | None = None, metadata_url: str | None = None, show_name_field: bool = True, xml_namespace: str | None = None)

Declare a feature that is exposed on the map.

All WFS operations use this class to read the feature type. You may subclass this class to provide extensions, such as redefining get_queryset().

This corresponds with a single Django model.

__init__(queryset: QuerySet, *, fields: list[str | FeatureField] | Literal['__all__'] | None = None, display_field_name: str | None = None, geometry_field_name: str | None = None, name: str | None = None, title: str | None = None, abstract: str | None = None, keywords: list[str] | None = None, crs: CRS | None = None, other_crs: list[CRS] | None = None, metadata_url: str | None = None, show_name_field: bool = True, xml_namespace: str | None = None)
Parameters:
  • queryset – The queryset to retrieve the data.

  • fields – Define which fields to show in the WFS data. This can be a list of field names, or FeatureField objects.

  • display_field_name – Name of the field that’s used as general string representation.

  • geometry_field_name – Name of the geometry field to expose (default = auto-detect).

  • name – Name, also used as XML tag name.

  • title – Used in WFS metadata.

  • abstract – Used in WFS metadata.

  • keywords – Used in WFS metadata.

  • crs – Used in WFS metadata.

  • other_crs – Used in WFS metadata.

  • metadata_url – Used in WFS metadata.

  • show_name_field – Whether to show the gml:name or the GeoJSON geometry_name field. Default is to show a field when name_field is given.

  • xml_namespace – The XML namespace to use, will be set by bind_namespace() otherwise.

property all_geometry_elements: list[GeometryXsdElement]

Provide access to all geometry elements from all nested levels.

bind_namespace(default_xml_namespace: str)

Make sure the feature type receives the settings from the parent view.

check_permissions(request: HttpRequest)

Hook that allows subclasses to reject access for datasets. It may raise a Django PermissionDenied error.

This can check for example whether request.user may access this feature.

The parsed WFS request is available as request.ows_request. Currently, this can be a GetFeature or GetPropertyValue instance.

property crs: CRS

Tell which projection the data should be presented at.

property display_field: Field | None

Give access to the field that holds the string-representation.

property fields: list[FeatureField]

Define which fields to render.

When a related object returns a queryset, this hook allows extra filtering.

get_bounding_box() WGS84BoundingBox | None

Returns a WGS84 BoundingBox for the complete feature.

This is used by the GetCapabilities request. It may return None when the database table is empty, or the custom queryset doesn’t return any results.

Note that the <ows:WGS84BoundingBox> element always uses longitude/latitude, as it doesn’t describe a CRS.

get_display_value(instance: Model) str

Generate the display name value

get_queryset() QuerySet

Return the queryset that is used as basis for this feature.

Return the queryset that is used for prefetching related data.

property main_geometry_element: GeometryXsdElement

Give access to the main geometry element.

resolve_crs(crs: CRS, locator='') CRS

Check a parsed CRS against the list of supported types.

resolve_element(xpath: str, ns_aliases: dict[str, str]) XPathMatch

Resolve the element, and the matching object.

This is used to convert XPath references in requests to the actual elements and model attributes for queries.

Internally, this method caches results.

property supported_crs: list[CRS]

Return all spatial reference system ID’s that this feature supports.

property xml_name: str

Return the feature tag as XML Full Qualified name

property xsd_base_type: XsdAnyType

Return the base class for the xsd_type.

This builds an XsdComplexType element that represents the contents of XsdTypes.gmlAbstractFeatureType. By providing this as Complex Type, the filters can also resolve the attributes of @gml:id, <gml:name> and <gml:boundedBy> nodes.

property xsd_type: XsdComplexType

Return the definition of this feature as an XSD Complex Type.

xsd_type_class

Allow to override the XSD complex type that this feature will generate.

alias of XsdComplexType

The FeatureField classes

gisserver.features.field(name: str, *, model_attribute=None, abstract: str | None = None, fields: list[str | FeatureField] | Literal['__all__'] | None = None, xsd_class: type[XsdElement] | None = None) FeatureField

Shortcut to define a WFS field.

This automatically selects the proper field class, so little knowledge is needed about the internal working.

Parameters:
  • name – Name of the model field.

  • model_attribute – Which model attribute to access. This can be a dotted field path.

  • abstract – The “help text” or short abstract/description for this field.

  • fields – If the field exposes a foreign key, provide its child element names. This can be a list of field() elements, or plain field names. Using __all__ also works but is not recommended outside testing.

  • xsd_class – Override which class is used to construct the internal XsdElement. This controls the schema rendering, value retrieval and rendering of the element.

class gisserver.features.FeatureField(name, model_attribute=None, model=None, parent: ComplexFeatureField | None = None, feature_type: FeatureType | None = None, abstract=None, xsd_class: type[XsdElement] | None = None)

Bases: object

The configuration for a field inside a WFS Feature.

This defines how a Django model field is mapped into an XSD definition that the remaining application uses.

__init__(name, model_attribute=None, model=None, parent: ComplexFeatureField | None = None, feature_type: FeatureType | None = None, abstract=None, xsd_class: type[XsdElement] | None = None)

Initialize a single field of the feature.

Parameters:
  • name – Name of the model field.

  • model_attribute – Which model attribute to access. This can be a dotted field path.

  • model – Which model is accessed. Usually this is passed via bind().

  • parent – The parent field of this element. Usually this is passed via bind().

  • feature_type – The feature this field is a part of. Usually this is passed via bind().

  • abstract – The “help text” or short abstract/description for this field.

  • xsd_class – Override which class is used to construct the internal XsdElement. This controls the schema rendering, value retrieval and rendering of the element.

property absolute_model_attribute: str

Determine the full attribute of the field.

bind(model: type[Model], parent: ComplexFeatureField | None = None, feature_type: FeatureType | None = None)

Late-binding for the model.

This resolves the model field object from the provided model. This method is called internally when the field definition wasn’t linked to a model yet. This allows the fields to be defined first, in external code, and then become part of the FeatureType fields list.

Parameters:
  • model – The model is field is linked to.

  • parent – When this element is part of a complex feature, this links to the parent field.

  • feature_type – The original feature type that his element was mentioned in.

property xsd_element: XsdElement

Define the XMLSchema definition for a model field.

This definition is used by the remaining application to access the data. It’s the basis for DescribeFeatureType, and it’s get_value() method is read to access the model field data.

xsd_element_class: type[XsdElement] = None

Allow to override the XSD element type that this field will generate.

class gisserver.features.ComplexFeatureField(name: str, fields: list[str | FeatureField] | Literal['__all__'], model_attribute=None, model=None, abstract=None, xsd_class=None, xsd_base_type=None)

Bases: FeatureField

The configuration for an embedded relation field.

This field type is suitable for any relational object, including foreign keys, reverse relations and M2M fields. The internal logic translates the relation into an embedded XSD complex type.

__init__(name: str, fields: list[str | FeatureField] | Literal['__all__'], model_attribute=None, model=None, abstract=None, xsd_class=None, xsd_base_type=None)
Parameters:
  • name – Name of the model field.

  • fields – If the field exposes a foreign key, provide its child element names. This can be a list of field() elements, or plain field names. Using __all__ also works but is not recommended outside testing.

  • model_attribute – Which model attribute to access. This can be a dotted field path.

  • abstract – The “help text” or short abstract/description for this field.

  • xsd_class – Override which class is used to construct the internal XsdElement. This controls the schema rendering, value retrieval and rendering of the element.

  • xsd_base_type – Override which class is the base class for the element.

property fields: list[FeatureField]

Provide all fields that will be rendered as part of this complex field.

property target_model: type[Model]

Detect which model the relation points to.

The ServiceDescription class

class gisserver.features.ServiceDescription(title: str, abstract: str | None = None, keywords: list[str] | None = None, provider_name: str | None = None, provider_site: str | None = None, contact_person: str | None = None)

Basic metadata for an exposed GIS service.

__init__(title: str, abstract: str | None = None, keywords: list[str] | None = None, provider_name: str | None = None, provider_site: str | None = None, contact_person: str | None = None) None