Feature info

The feature info displays attributes for picked objects.

The following options are available for displaying feature info:

You can configure the identify tool by setting identifyTool in config.json (or per-theme in themesConfig.json).

By default, it is triggered when clicking on a feature in the map. You can also configure the feature info as an explicit viewer tool by setting identifyTool: null and adding a menuItems or toolbarItems entry.

Identify plugin

The identify plugin allows displaying feature attributes queried over WMS GetFeatureInfo or, by using the qwc-feature-info-service, from a custom SQL query.

To use it as default identify-tool, set identifyTool: "Identify" in config.json.

By default, results are displayed in a table. You can also display the results using a custom HTML template by using the qwc-feature-info-service.

You can also omit empty attributes by setting skipEmptyFeatureAttributes: true in the theme configuration entry in themesConfig.json.

Note: Use of the qwc-feature-info-service is also recommended if the qwc-data-service is used for editing, to ensure attribute values containing paths to uploaded files are properly converted to clickable hyperlinks.

Querying features via WMS GetFeatureInfo

Set whether a layer is identifyable in QGIS → Project Properties → Data sources.

To highlight the geometry, make sure QGIS → Project Properties → QGIS Server → Add geometry to feature response is checked.

You can suppress attributes globally by selecting "Do not expose via WMS" in QGIS → Layer properties → Fields.

Alternatively, you can selectively restrict attributes using the qwc-admin-gui and assigning Attribute resource permissions as desired, see Permissions.

If you use the qwc-feature-info-service, you can filter empty attributes service-side by setting skip_empty_attributes: true in the featureInfo service configuration in tenantConfig.json.

Querying features via custom SQL queries

With the qwc-feature-info-service, you can query features directly from a database instead of over WMS GetFeatureInfo, by providing the featureInfo service configuration as described in HTML templates, but specifying a db_url and sql, for example

"info_template": {
  "type": "sql",
  "db_url": "postgresql:///?service=qwc_geodb",
  "sql": "SELECT ogc_fid as _fid_, name, formal_en, pop_est, subregion, ST_AsText(wkb_geometry) as wkt_geom FROM qwc_geodb.ne_10m_admin_0_countries WHERE ST_Intersects(wkb_geometry, ST_GeomFromText(:geom, :srid)) LIMIT :feature_count;",
  "template": "<div><h2>Demo Template</h2>Pos: {{ x }}, {{ y }}<br>Name: {{ feature.Name }}</div>"
}

Note: x, y and geom are passed as parameters to the SQL query. If a GetFeatureInfo request is being processed with a filter_geom parameter, geom will correspond to that parameter. Otherwise geom will be POINT(x y).

In general, HTML markup in attribute values is preserved.

For displaying interactive hyperlinks, the following options are supported:

  • URLs in attribute text values with no HTML markup are automatically converted to an interactive hyperlink.
  • Alternatively, you can enclose the URL in a HTML <a> tag in the attribute value. To open the linked page in an inline dialog within QWC, you can set the anchor target to :iframedialog:<dialogname>:<optkey>=<optval>:<optkey>=<optval>:... where the supported options are:
  • w: Dialog width in pixels, default: 640.
  • h: Dialog height in pixels, default: 480.
  • title: Dialog window title, by default the translation string windows.<dialogname>.
  • print: Whether to add a print icon for printing the dialog contents, default: true.
  • dockable: Whether the dialog can be docked, default false.
  • docked: Whether the dialog is initially docked, default false. Example:
<a href="https://example.com" target=":iframedialog:w=1024:h=768:title=Example">Link text</a>

For displaying images, the following options are supported:

  • If replaceImageUrls: true is set in the Identify plugin configuration in config.json, attribute text values which contain exactly an URL to an image are converted to inline images. If you use the qwc-feature-info-service, you need to set transform_image_urls in the featureInfo service configuration in tenantConfig.json.
  • Alternatively, you can add a <img> tag directly in the attribute value.

This applies in particular to <a /> anchor and <img /> tags for displaying links an images in an attribute value.

Client side attributes

To compute derived attributes client-side, you can register an attribute calculator via window.qwc2.addIdentifyAttributeCalculator, exposed by the API plugin.

Custom export

By default, the identify dialog in QWC allows you to export the results to json (QWC feature storage format), geojson (standard GeoJSON without QWC specific fields), csv (single CSV with all layers) or csv+zip (ZIP with one CSV per layer). You can define additional export functions registering an exporter via window.qwc2.addIdentifyExporter, exposed by the API plugin.

Custom HTML templates

With the qwc-feature-info-service, you can specify a custom HTML template for displaying the feature rather than the default table view.

Mount the info templates folder into the qwc-feature-info-service container, i.e.:

  qwc-feature-info-service:
    image: sourcepole/qwc-feature-info-service:vYYYY.MM.DD
    volumes:
      ...
      - ./volumes/info_templates:/info_templates

Note: If mounting to another location than /info_templates, set the info_templates_path in the featureInfo service configuration in tenantConfig.json:

{
  "name": "featureInfo",
  "config": {
    "info_templates_path": "/<path>/"
  }
}

Then, info templates will be searched by name as <info_templates_path>/<service_name>/<layername>.html.

Alternatively, you can specify the template in the featureInfo service configuration in tenantConfig.json, either inline or as a path:

{
  "name": "featureInfo",
  "config": ...,
  "resources": {
    "wms_services": [
      {
        "name": "<service_name>",
        "root_layer": {
          "name": "<root_layer_name>",
          "layers": [
            {
              "name": "<layer_name>",
              "info_template": {
                <See below>
              }
            }
          ]
        }
      }
    ]
  }
}

Example info_template with inline template:

"info_template": {
  "type": "wms",
  "template": "<div><h2>Demo Template</h2>Pos: {{ x }}, {{ y }}<br>Name: {{ feature.Name }}</div>"
}

Example info_template with template path:

"info_template": {
  "type": "wms",
  "template_path": "/info_templates/template.html"
}

Note:

  • x and y are the info query coordinates. feature.<attr> renders the attr attribute value of the feature.
  • The templates must be HTML fragments without html or body tags.
  • The templates folder needs to be mounted into the qwc-feature-info-service container, i.e.:
  qwc-feature-info-service:
    image: sourcepole/qwc-feature-info-service:vYYYY.MM.DD
    volumes:
      ...
      - ./volumes/info-templates:/info_templates:ro

Localization

The qwc-feature-info-service supports switching the runtime locale by setting the LOCALE environment variable, i.e.:

  qwc-feature-info-service:
    image: docker.io/sourcepole/qwc-feature-info-service:vXXXX.XX.XX
    environment:
      <<: *qwc-service-variables
      SERVICE_MOUNTPOINT: '/api/v1/featureinfo'
      LOCALE: 'de_DE'

In addition, the locale object is available in templates. This is particularly helpful for rendering locale-formatted numbers, i.e.

<div>Area: {{ locale.format_string("%.2f", area, True) }}</div>

Permissions

If permissions_default_allow is set to true in tenantConfig.json, layers and attributes are queryable by default.

  • To restrict the display of single layer attributes to specific roles, create a Layer and Attribute resource (latter as child of the created Layer resource) and create permissions assigning the desired roles to the Attribute resources.
  • To restrict whether a layer can be queried, create a FeatureInfo service and FeatureInfo layer resource (latter as child of the created FeatureInfo service resource), and create permissions assigning the desired roles to the FeatureInfo layer resources.

Feature form plugin

The FeatureForm plugin displays picked features in a feature form as configured in QGIS → Layer properties → Attributes form. It queries the features via qwc-data-service, and hence only works for layers with postgresql data source.

See Designing the edit forms for more information on designing edit forms.

To use it as default identify-tool, set identifyTool: "FeatureForm" in config.json.

A layer is only identifyable with the FeatureForm plugin if corresponding Data resources and permissions are configured for the layer data source in the qwc-admin-gui. If a write permission is configured, the feature will be editable.

Permissions

The FeatureForm plugin relies on the qwc-data-service and the Data resource permissions, see Editing.