Attribute Queries

Attribute queries are used to find and select elements of a map layer using their attribute values or a database associated with the layer.

In JMap Admin, JMap administrators create the queries and their associated forms. Then, users of JMap applications use those forms to enter attribute values to search for. All elements whose attribute values match the values entered are then selected or listed in an elements explorer.

The Queries tab of a project's configuration interface allows you to configure the project's queries.

The Queries tab appears when the project contains at least one layer.

This tab presents a table that displays the query groups. The table shows the number of queries each group contains. The Organizing attribute queries section provides details about the groups.

Creating a new attribute query

To create a new query you must position yourself in a group of the Queries tab. The Create a query button is displayed and you can therefore open the query configuration interface.

Parameters will vary depending on the type of query selected.

Title

Enter a title for the query. Users will see this title in a list of queries.

Layer

Select the layer on which the query will be executed. A search field is provided to simplify layer selection.

Maximum scale

Specify the maximum scale used to present the results on the map. This is used to avoid zooming in too closely on the results.

Max. returned values

Specify the maximum number of elements this query can return. The query will refuse to execute if the return size is higher than this limit. This is used to avoid very long queries that could slow down the system.

Query templates

Basic: With this type of query, the search is only performed on the layer attributes. This is the simplest type of query. External database: With this type of query, the search is performed in an external database that has a field linking to an attribute of the layer. Setting up this type of query is more complex but offers more searching flexibility.

Layer queries

WHERE

WHERE clause of the SQL query used to run the search. Here is where all the search criteria will be defined. Typically, this clause contains numbered parameters ($param1, $param2, etc.) that will be replaced by the values the user enters in the form.

Examples

COUNTRY='$param1'

Selects the layer elements for which the attribute value COUNTRY is equal to the value entered by the user.

The attribute value must perfectly match the value entered ($param1).

lower(COUNTRY) like lower('$param1%')

Selects the layer elements for which the attribute value COUNTRY is similar to the value entered by the user. The attribute value must begin with the value entered ($param1). Since the lower operator is used, the search is not case sensitive.

POP2000>=$param1 and POP2000<$param2

Selects layer elements that have the POP2000 attribute value within the range defined by the two values that were entered ($param1 and $param2).

Form layout

Press this button to configure the query form. See Forms for more information.

External queries

This type of query is used when the search must be conducted within the data of an external database. The external database must contain a field that links to a layer attribute. A select SQL query is executed in the external database and the values returned are then associated with the layer elements using the link field.

Database

Select the database in which you would like to perform your query.

SQL query

Enter the SQL query that will be executed in the database to search for elements.

Example

select * from cities where CITY_LANGUAGE='$param1'

Searches the database selected above, in the cities table. Retrieves all fields of records for which the value of the CITY_LANGUAGE field is equal to the value entered by the user ($param1).

Layer attribute

Among the layer attributes, indicate which one is used to link with the database.

Field

Among the fields returned by the SQL query, indicate which one is used to link with the layer.

Form layout

Click on this button to configure the query form. Refer to the Forms section for more information on this topic.

Required and optional parameters

Although search forms are designed to mark fields as required or optional, the where clause of the query must be adjusted to support this option. To accomplish this, any part of the query that is associated with optional parameters must be included between braces ( { } ).

Example of WHERE clause:

CITY = '$param1' and { COUNTRY = '$param2' }

This example searches for cities for which the attribute value CITY is equal to the value of parameter 1 ($param1) entered by the user and who optionally have their value for the COUNTRY attribute equal to the value of parameter 2 ($param2) entered by the user. If parameter 2 is left blank , the entire block { COUNTRY = '$param2' } is removed from the query, along with the and operator, which is now an orphan. Note that the administrator must absolutely define $param2 as optional when designing the form. Refer to the Forms section for more information on designing forms.

Multiple values for the same parameter

Multiple values can be entered with a List (multiple choices) type field in the forms. The values are separated by the delimiter character ; (semicolon). This option can be activated in the WHERE clause of the query. The syntax is as follows:

$multiple{true|false} {$delimiter{;}}

Example:

CITY = '$param1{$multiple{true} $delimiter{;}}'

Searches for cities whose CITY attribute value is equal to one of the values entered in parameter 1. The values are separated by semicolons.

Managing attribute queries

Attribute queries can be modified by administrators. In JMap Dakar and later versions, when a project’s queries are modified, the applications that disseminate the project do not need to be redeployed because the changes are reflected directly.

Organizing attribute queries

Attribute queries can be organized into groups. This is particularly useful for projects that have a large number of queries.

To create a new group, click on the Create group buttonon the Queries tab.

To delete a group, select it in the list and click on Delete.

Deleting attribute queries

Deleting an attribute query permanently deletes the query and its associated form. To delete a query, select it in the list and click on Delete.

Publishing queries

Once a query has been created, it is automatically published. However, you can disable this publication, which will make your query unavailable in applications, but its configuration will still be saved. If you do not want your query to be published, clear the Published checkbox of your query in the query management interface.

Queries on referenced layers

When a project contains referenced layers, the queries configured on these layers are automatically available in the project. The project “inherits” these queries.

You cannot modify these queries from the project; they can only be modified in the project that contains the original layer.

If you wish to make changes to a query on a referenced layer, create a copy of the query by clicking on Clone. The configuration interface shows the search parameters that you can modify.

Once the new query has been configured, you can clear the Published check box of the query that was “inherited” from the referenced layer if you no longer want it to be available in JMap applications. If the Published check box is cleared for an attribute query on a layer, that query will no longer be available in the projects that use the referenced layer.

You can also create a new query on a referenced layer as described in the section Creating a new attribute query.

Dernière mise à jour

K2 Geospatial 2024