Creating selections with SQL
Various methods of selecting network objects have been covered so far. Further selections can be made using SQL queries, which allow you to create lists of objects that satisfy specified conditions. The conditions can be as simple or as complex as you like. For example, you can create a list of nodes of a particular type or links for which particular fields lie within specified ranges.
This stage assumes that you have started InfoWorks WS Pro and that the Model Group window is open, showing the Newtown icon.
The tutorial dataset uses InfoWorks WS Pro native units (metric units). To import the tutorial data correctly, set the user units to metric by selecting Options from the Tools menu and clicking the Metric (Native) button on the Units tab.
The following steps create a number of selection lists using SQL. You can use the provided 'Newtown Network' network.
- Create a list of all reservoirs:
- Click the tool. The SQL dialog is displayed.
- In the box, select 'Reservoir'.
- Select 'node_id' from the drop-down list.
- Click the button. The dialog is expanded to show the operations that can be included when building the SQL query.
- Click the '>' button.
- Click the box, type '0' (zero) and click the small button immediately below. The query is now complete.
- Click the button. Open the Tutorial and Newtown model groups. Click the Stored Query Group and enter 'Select Reservoirs'. Click to add the query to the group. The dialog is closed.
- In the SQL dialog, click . The dialog is closed and all objects matching the query condition are selected (that is, those reservoirs that have a node ID). If required, right-click an empty area of the GeoPlan, and select to maximise the display.
- Right-click the Selection List Group and choose . Give the list a name of 'Reservoirs (SQL)' and click .
- Another task can be to select all nodes above 140 mAD (the tool cannot be used in this case):
- Clear the current selection.
- Click the tool.
- Select 'Node' as the .
- Select 'z (Elevation)' as the .
- In the main query box, type '> 140'.
- Click . The dialog shows the number of objects satisfying the criteria. Click
- Save the query in the Stored Query Group, giving it a name of 'Nodes Above 140 mAD'.
- Click . The selected nodes are highlighted.
- Use to maximise the display.
- Save the selection in the Selection List Group as 'Nodes Above 140 mAD'.
- Open the Nodes grid view (refer to the Working with grids and property sheets topic for more information about grids) and sort the records in descending order of elevation. The selected nodes are listed at the top. This confirms that the list is accurate and provides an alternative method for generating the selection. Close the grid view.
- You can use any of the data fields in a query. For example, you can create a list of pipes that are greater than 175 mm wide:
- Clear the current selection.
- Click , set the to 'Pipe' and enter the condition: 'diameter > 175'.
- Test the query. The number of items selected is shown. Click .
- Save the query as 'Pipes > 175 mm'.
- Run the query and find the selection.
- Save the selection in the Selection List Group as 'Pipes > 175 mm'.
- The GeoPlan tools and grids can achieve the same effects as simple SQL queries. However, more complex SQL queries can be designed to select objects according to a combination of criteria:
- Start by making a copy of the last query. Right-click the 'Pipes > 175 mm' query (in the Stored Query Group) and choose . Right-click the Stored Query Group and select . Right-click the new query ('Pipes > 175 mm!') and choose . Change the name to 'Minor Pipes' and click .
- Clear the current selection.
- Drag the Minor Pipes query onto the InfoWorks WS Pro background (not the GeoPlan). The query is reloaded.
- Click the button.
- Extend the condition, either by using the buttons on the dialog or by typing the condition directly: 'diameter < 175 OR length < 1'.
- When entering expressions (either directly or using the Builder options), make sure you leave a space either side of the operators (Arithmetic, Text, Comparison and Logic).
- Click . There are now more matching objects, which have either a diameter less than 75 mm or length less than 1 metre. Click .
- Click to re-save the query.
- Run the query and save the selection in the Selection List Group as 'Minor Pipes'.
- It is possible to view the results of a query as a grid (refer to the Working with grids and property sheets topic for more information about grids):
- Clear the current selection.
- Drag the Minor Pipes query onto the InfoWorks WS Pro background.
- Click the Grid tab.
- Hold down Ctrl and click the us_node_id, link_suffix, length and diameter fields. Click .
- Click . The query is run and the Pipe grid view is loaded. Close the SQL dialog. The grid shows only the matching records and the selected columns.
- Close all the windows, including the GeoPlan window.