/  Query Builder


Applicability:

Ribbon Groups:

Home-Map/Table-Sort & Filter

Map Window:

Associated commands:


Description:

 Query Builder constructs a data query to find items in an overlay.

Note: For the fastest query responses on database overlays use the Run the query using: Database filtering option in the Query Overlay dialog. This uses the database for performing the query.

See Querying Spatial Database Spatial Overlays

Query Builder

Query Builder [Home-Map] or [Table-Sort & Filter] helps you look for items on an overlay. You can look for:

When it has found matching items, the Query Builder can either:

You can also have the query set a filter or spatial filter, so that you can use the items found by the query as the basis for further operations. See Spatial testing: Spatial Filter.

Before you start Query Builder, select an item or items if you want to look for other spatially-related items.

  1. Select Query Builder [Home-Map] or [Table-Sort & Filter].

  2. If you have not indicated the overlay, choose the overlay you wish to query in the Query Overlay dialog.

  3. The options of running the query using SIS filtering or Database filtering are given at the bottom of the dialog.
    If you use Database filtering it is necessary to add in wildcard characters in the Like query, otherwise the query will not return any output.

    See the Like query below for an example of the syntax to be used for this query using Database filtering.

    Note: If you use an overlay’s local menu, or you have only one overlay open, this dialog is not displayed. Also if Query [Table-Sort & Filter] is used the overlay is already selected, therefore this dialog will not be displayed.



    Click Next.

  4. The Query dialog will be displayed:

    Enter the details of the attribute query and/or spatial query you wish to carry out.

    Note: The Spatial Query against the currently selected item tickbox and options will only be available if items are selected on the overlay.

    Attribute Query

    Columns - This pane shows the columns in the overlay schema

    The Function keypad

    Examples of the use of the keys:


     

     Less than

    Example Query: CALCULATED_AREA_VALUE& < 1000

    Returns all areas less than 1000 in current units.


     

     Equal to

    Example Query: CALCULATED_AREA_VALUE& = 1000

    Returns all areas equal to 1000 in current units.


     

     Greater than

    Example Query: CALCULATED_AREA_VALUE& > 1000

    Returns all areas greater than 1000 in current units.


     

     Less than or equal to

    Example Query: CALCULATED_AREA_VALUE& <= 1000

    Returns all areas less than or equal to 1000 in current units.


     

     Not equal to

    Example Query: CALCULATED_AREA_VALUE& <> 1000

    Returns all areas not equal to 1000 in current units.


     

     Greater than or equal to

    Example Query: CALCULATED_AREA_VALUE& >= 1000

    Returns all areas greater than or equal to 1000 in current units.


     

    The And, Or, Like and In keys

    Using Counties.shp as an example:


     

     And

    Example Query: NAME$ = "Highland" And COUNTY_ID# = 5

    Returns Highland, providing the name (Highland) and the county id match:

     


     

     Or

    Example Query: NAME$ = "Cornwall" Or NAME$ = "Isle of Wight" Or NAME$ = "Kent"

    Returns Cornwall, Isle of Wight and Kent:


     

     Like

    Example Query: NAME$ Like ‘Isle’

    Note: If the Database filtering option has been chosen in the Query Overlay dialog it is necessary to add wildcard characters, otherwise the query will not return any output. Therefore, in this example the Like query should be ‘NAME Like ‘%Isle%’ in order to return the same output, also note the $ character is omitted due to using database data.

    Returns names containing Isle, i.e. Western Isles, Isle of Man, Isle of Anglesey, Isle of Wight.


     

     In

    The In function reduces the need to use multiple OR functions.

    Example Query: NAME$ In("Northhamptonshire","West Lothian","Isle of Man","Derby" )

    Returns Northhamptonshire, West Lothian, Isle of Man and Derby:


    Sample button

    Click the Sample button to display the first number of item(s), as selected in the drop-down in a range of 1 to 1000, for the selected column.

     

    Typical values - This pane shows the values that will scan the overlay for in the selected column.

    Query - Enter the query you want to use to find items. You can build simple queries using the block of function keys above.

    Spatial Query against the currently selected item

    The currently selected item(s) must ... - Only select items that pass a geometric test with the current item. The tests use the OGC "Relate" function. This measures the dimensions of the nine intersections formed between the Interior, Boundary and Exterior of the two items being compared. The different tests have different rules for which dimension matrices are valid.                

See the Geometry Tests topic for a further explanation of the OGC specified method for computing spatial relationships between geometries.

all... - Tick if all of the selected items have to pass the test, or untick if any one will be enough.

The following is an example of the dimensionally extended nine-intersection matrix (DE-9IM) for the case where (a) and (b) are two Polygons that overlap.


contain - The interior of the found item must be strictly inside the current item.

"T****F*"

cross - If the items are LineStrings, then they must intersect without being tangential. Otherwise, their interiors must intersect, with the current item going outside the found item.

LineStrings: "0********"

Other: "T*T******"

touch - The items interiors must be disjoint, AND their boundaries must intersect. 

"FT*******" or "F**T*****" or "F***F****"

be disjoint from - The items must be completely separate, with daylight between them. 

"FF*FF****"

be equal to - The two items' geometry must be the same. 

"TFFF*FFF*"

be within - The interior of the current item must be strictly inside the found item. 

"T*F**F***"

intersect - The items must not disjoint, so they must have a point in common. This is the fastest, and most common test. 

not "FF*FF****"

overlap - If the two items are LineStrings, then they must be tangential, and neither should contain the other. Otherwise, their interiors must intersect, with neither containing the other.

LineStrings: "1*T***T**"

Other: "T*T***T**"

be crossed by - If the items are LineStrings, then they must intersect without being tangential. Otherwise, their interiors must intersect, with the found item going outside the current item. 

LineStrings: "0********"

Other: "T*****T**"


...the... - ...of the found items

origin - This is the origin of the Items to be queried. This is normally (but not always) the approximate centre of a Polygon or the starting point of a LineString.

extents - This means the imaginary bounding box around the item’s geometry, using the minimum and maximum x/y values of the item.

geometry - This is the outline of the Item. This is the slowest, but most accurate mode.

The above example shows a query build that filters the overlay to display data that intersects the currently selected item.

 

Back to top of page

Example 1 - Attribute Query

  1. As an example enter a query to find CALCULATED_AREA_VALUES greater than 40 square metres:



    The list in the right-hand panel shows some (but not all) of the values for the column you have selected. Notice that your selection from the Columns list is converted into the correct form for the query.

You can use the function keypad directly to input an operator or type a query directly into the Query field.

If you selected an item or items before starting the query, you can create a spatial query using the selection. Check the tickbox next to The currently selected item(s) must… and then choose the test required.

Choose also whether you want to test against the origin, extents, or geometry of the found items.

The geometry of an item is:

Some of the spatial tests operate differently depending on which of the origin, extents, or geometry is used.

Check the all… tickbox if all the selected items must pass the test, or leave it blank if at least one selected item must pass.

On completion of the dialog click Next.

  1. The Query Results dialog will be displayed:

Select from the three Action - Overlay for query results options:

Filter - Use the query as the overlay filter and/or spatial filter. The query will be dynamic, so as an item's properties or geometry change, it may drop out of, or be included in the filter and/or spatial filter.

Copy - Create a new (phased) overlay using the query as the overlay filter and/or spatial filter. The data will not be copied, just drawn again in another overlay. This is known as 'phasing' an overlay.

The name of the overlay to be copied will be shown in the text box.

Replicate - Copy the query results into a new 'Internal' overlay, for further processing. The connection to the source data will be lost.

Show the first/the next xxx result(s)

Click Show for a preview of the first selected number of results. For example:

Show the next xxx result(s) will now be displayed. Select the required number of results and click Show to display the next results.

Click Finish to complete the query.

Back to top of page

Example 2 - Spatial Query

  1. Taking the Counties.shp overlay, select a county, in this example Nottinghamshire:


  2. In the Build Query dialog ignore the Attribute Query block and check the required tickboxes in the Spatial Query against the currently selected item block:


    Click Next.

  3. The Query Results dialog will be displayed:


    Select either Filter, Copy or Replicate as required.

    If Copy is selected either accept the default Name for the overlay or enter a more meaningful name in the text box.

    Click Finish.

  4. In this example the Copy of Counties.shp overlay will be created:


Top of page AComTableQuery

Send comments on this topic.