Spatial Query Example

This article uses the road, lake, and administrative division layers from the sample data China100.udbx data source as examples to query:

  • Which lakes are contained within Hunan Province;
  • Which roads pass through Hunan Province and have a road code of G320.

The sample data used requires the installation of a separate sample data package. For details, please refer to the Get Sample Data Package document.

The specific steps are as follows:

  1. In the current workspace, open the sample data China100.udbx data source.
  2. Create a new map and add the Provinces_R, Lake_R, and ProvinceRoad_L datasets to the new map.
  3. In the map, select the administrative division polygon of Hunan Province in the Provinces_R layer. This polygon is the search object for the spatial query.
  4. Click the Spatial Query button in the Spatial Analysis tab > Query group to open the "Spatial Query" dialog box.
  5. In the searched layer list, set the spatial query condition and attribute query condition for the search.
    • In the Road_L layer list, click the "Spatial Query Condition" drop-down button and set the spatial query tool to "Intersect_Polyline," i.e., query which roads pass through Hunan Province;
    • In the Road_L layer list, click the "..." button in the "Attribute Query Condition" column to open the SQL Expression dialog box. In the dialog box, set the attribute condition that the searched roads must meet: Road_L.CODE = "G320".
    • In the Lake_R layer list, click the "Spatial Query Condition" drop-down button and set the spatial query tool to "Within_Polygon," i.e., query which lakes are contained within the boundaries of Hunan Province.
  6. Select the Road_L and Lake_R layers, and check the "Browse in Attribute Table" and "Highlight in Map" checkboxes in the "Show Results" area.
  7. Select the Road_L layer, check the "Save Results" checkbox, and set the search results for the Road_L layer to be saved to the China.udb data source. Rename the resulting dataset to: Hunan_Roads_G320.

    Similarly, name the query result dataset for the Lake_R layer: Hunan_Lakes.

  8. Click the "Query" button to perform the spatial query operation.
  9. Browse the search results simultaneously in the attribute table and the map. Select any record in the query result table, and the corresponding object will be automatically located in the map, achieving linked views.
    Figure: Browsing Spatial Query Results