Gets or sets a SQL based query string which serves as a filter on the FeatureLayer.

Namespace:  ESRI.ArcGISExplorer.Mapping

Assembly:  ESRI.ArcGISExplorer (in ESRI.ArcGISExplorer.dll) Version: 2.0.0.1500 (2.0.0.1500)

Syntax

C#
public string QueryDefinition { get; set; }
Visual Basic (Declaration)
Public Property QueryDefinition As String

Field Value

A string containing the current query active on the FeatureLayer.

Remarks

The Query Definition property of a FeatureLayer is a SQL based query string which acts as a filter on the data in that FeatureLayer. The first part of the query (SELECT * FROM [FeatureLayer] WHERE) is supplied for you by ArcGIS Explorer. It is the criteria which follow this command, known as the WHERE clause, that should be set as the QueryDefinition or which will be retrieved as the QueryDefinition property.

By creating queries and choosing appropriate criteria you can ensure only the data relevant to your application are displayed on the map. For example, you might programmatically add a Geodatabase layer containing cities around the world but only want the map to show cities with a population over 1 million. To achieve this you would set the QueryDefinition property to "POPULATION > 1000000" before adding the FeatureLayer to the map.

It is important to note that no change is made to the underlying data source when setting the QueryDefinition property nor is it necessary to programmatically refresh the map after the QueryDefinition property is set. Depending on the intended workflow of your application, instead of applying a query to the existing FeatureLayer in the map you could also consider using the Clone()()() method to retrieve a new FeatureLayer then set the QueryDefinition on the new layer and add it to the map. This would allow the user to visually compare the two layers in the map. Both FeatureLayers will be referencing the same underlying datasource.

Version Information: This property is supported from version 2.0.0.1500.

Examples

The code below demonstrates two approaches to setting the QueryDefinition property of a FeatureLayer. The first approach simply sets the property of an existing FeatureLayer in the map, immediately affecting the type and amount of data visible in that layer. The second approach uses the Clone method to obtain a duplicate FeatureLayer on which the QueryDefinition property is set then that new layer is added to the map allowing the user to make a visual comparison between the two layers.
CopyC#
{
  //Get the ActiveMapDisplay
  MapDisplay mapDisplay = ESRI.ArcGISExplorer.Application.Application.ActiveMapDisplay;

  /*
   * Example 1: Set the QueryDefinition on an existing layer
   */

  //Find the mountains FeatureLayer in the map
  FeatureLayer fl = mapDisplay.Map.FindByName("E.G. 1: Mountains") as FeatureLayer;

  //Get the current row count from the FeatureLayer Table
  int currentRowCount = fl.Table.GetRows().Count; //(562)

  //Set the QueryDefinition property of the 
  fl.QueryDefinition = "Type = 'Munro'";

  //Get the new row count of the FeatureLayer Table
  int newRowCount = fl.Table.GetRows().Count; //(285)

  /*
   * Example 2: Use the Clone method to obtain a duplicate FeatureLayer then
   * set the QueryDefinition of the new layer and add it to the map.
   */

  //Find the mountains FeatureLayer in the map
  FeatureLayer flOriginal = mapDisplay.Map.FindByName("E.G. 2: Mountains") as FeatureLayer;

  //Clone the mountains FeatureLayer
  FeatureLayer flNew = flOriginal.Clone();

  //Exit if the new FeatureLayer cannot connect to the datasource
  if (!flNew.Connect())
    return;

  //Set the QueryDefinition property of the new FeatureLayer
  flNew.QueryDefinition = "Type = 'Munro'";

  //Append the query to the new FeatureLayer
  flNew.Name = flOriginal.Name + " (Type = 'Munro')";

  //Add the new FeatureLayer to the map
  mapDisplay.Map.ChildItems.Add(flNew);
}
CopyVB.NET
'Get the ActiveMapDisplay
Dim mapDisplay As MapDisplay = ESRI.ArcGISExplorer.Application.Application.ActiveMapDisplay

'
' * Example 1: Set the QueryDefinition on an existing layer
' 


'Find the mountains FeatureLayer in the map
Dim fl As FeatureLayer = TryCast(mapDisplay.Map.FindByName("E.G. 1: Mountains"), FeatureLayer)

'Get the current row count from the FeatureLayer Table
Dim currentRowCount As Integer = fl.Table.GetRows().Count '(562)


'Set the QueryDefinition property of the 
fl.QueryDefinition = "Type = 'Munro'"

'Get the new row count of the FeatureLayer Table
Dim newRowCount As Integer = fl.Table.GetRows().Count '(285)


'
' * Example 2: Use the Clone method to obtain a duplicate FeatureLayer then
' * set the QueryDefinition of the new layer and add it to the map.
'         


'Find the mountains FeatureLayer in the map
Dim flOriginal As FeatureLayer = TryCast(mapDisplay.Map.FindByName("E.G. 2: Mountains"), FeatureLayer)

'Clone the mountains FeatureLayer
Dim flNew As FeatureLayer = flOriginal.Clone()

'Exit if the new FeatureLayer cannot connect to the datasource
If Not flNew.Connect() Then
  Return
End If

'Set the QueryDefinition property of the new FeatureLayer
flNew.QueryDefinition = "Type = 'Munro'"

'Append the query to the new FeatureLayer
flNew.Name = flOriginal.Name + " (Type = 'Munro')"

'Add the new FeatureLayer to the map
mapDisplay.Map.ChildItems.Add(flNew)

See Also