ArcGIS Runtime SDK for WPF - Library Reference
QueryDataSource Class
Members  Example  See Also 
ESRI.ArcGIS.Client Namespace : QueryDataSource Class

A type of DataSource object that allows querying data directly from a Workspace Type of Database using SQL select statements to construct a Dynamic Layer.

Object Model

QueryDataSource ClassSpatialReference Class

Syntax

Visual Basic (Declaration) 
Public NotInheritable Class QueryDataSource 
   Inherits DataSource
C# 
public sealed class QueryDataSource : DataSource 

Remarks

Dynamic Layers allow the execution of various ArcGIS Server requests from a client application. An in-depth discussion about Dynamic Layers is in the ArcGISDynamicMapServiceLayer Class documentation. The client side requests that can be issued to ArcGIS Server include the ability to:

Dynamic Layers are new in ArcGIS Server v10.1 and require the ArcGIS Runtime SDK 1.0 for WPF and higher.

When enabling Dynamic Layer web service capabilities via ArcGIS Server, there are four types of Workspace Type connections that can be made, they are: Database, Shapefile, File GDB, and Raster. See the following screen shot:

The 'Add Dynamic Workspace' dialog.

Only the Database type of Workspace Type is supported for the QueryDataSource. The other Workspace Types of Shapefile, File GDB, and Raster are not for use with the QueryDataSource. Additionally, when the Manager/Administrator of the ArcGISDynamicMapServiceLayer that has Dynamic Layers enabled selects the Database by click on the "…" button, it must be a "direct connection". In other words, if they make a new connection at ArcGIS Server 10.1 it would always work. If the Manager/Administrator uses a pre-existing SDE connection then they have to make sure it is a "direct connection". QueryDataSource does not work for “application server” connections.

The QueryDataSource is more flexible than the TableDataSource in that developers can make use of a Where Clause via the QueryDataSource.Query Property. The TableDataSource returns all records for the Workspace Type. Note: developers could use the ArcGISDynamicMapServiceLayer.LayerDefinitions to restrict the data returned if using a TableDataSource; see the example code in the ArcGISDynamicMapServiceLayer.DynamicLayerInfos Property.

Developers must supply all of the QueryDataSource Properties correctly in order to successfully create a Dynamic Layer, they are:

The key to discovering what all of the correct QueryDataSource Property values are can be found in the ArcGIS REST Services Directory pages.

Example: Assume that a fictitious ArcGISDynamicMapServiceLayer service had Dynamic Layer capabilities enabled when it was published using ArcGIS Server. The LayerDataSource made use of the Workspace Type of 'Database' (specifically and ArcSDE type of Database). The Manager/Administrator shared with the developer the following key pieces of information: of Database).

  • Url="http://DK-RED2A:6080/arcgis/rest/services/DKRED2A_TEST_NODATA/MapServer"
  • WorkspaceID = “MyDatabaseWorkspaceID”
  • DataSourceName = “RedlandsTest.DBO.EP_Block_01A”

Using this key information, the developer could specify the correct Layer Parameter syntax for the Url in the address bar of a web browser to obtain all of the necessary information needed to construct a QueryDataSource object. See the following screen shot:

The 'Obtaining the QueryDataSource Parameter information from the 'ArcGIS REST Services Directory' pages.

Given this information for the fictitious example, an example of XAML code for constructing the Dynamic Layer using a QueryDataSource could look like the following:

            <esri:ArcGISDynamicMapServiceLayer Url="http://dk-red2a:6080/arcgis/rest/services/DKRED2A_TEST_NODATA/MapServer" 
                                                DisableClientCaching="True">
              <esri:ArcGISDynamicMapServiceLayer.DynamicLayerInfos>
                <esri:DynamicLayerInfoCollection>
                  <esri:DynamicLayerInfo ID="102">
                    <esri:DynamicLayerInfo.Source>
                      <esri:LayerDataSource>
                        <esri:LayerDataSource.DataSource>
                          <esri:QueryDataSource OIDFields="OBJECTID"
                                                Query="SELECT * FROM RedlandsTest.DBO.EP_Block_01A WHERE UNIT = '01A'"
                                                WorkspaceID="MyDatabaseWorkspaceID" 
                                                GeometryType="Polygon" >
                            <esri:QueryDataSource.SpatialReference>
                              <esri:SpatialReference WKID="4326" />
                            </esri:QueryDataSource.SpatialReference>
                          </esri:QueryDataSource>
                        </esri:LayerDataSource.DataSource>
                      </esri:LayerDataSource>
                    </esri:DynamicLayerInfo.Source>
                  </esri:DynamicLayerInfo>
                </esri:DynamicLayerInfoCollection>
              </esri:ArcGISDynamicMapServiceLayer.DynamicLayerInfos>
              <esri:ArcGISDynamicMapServiceLayer.LayerDrawingOptions>
                <esri:LayerDrawingOptionsCollection>
                  <esri:LayerDrawingOptions LayerID="102" >
                    <esri:LayerDrawingOptions.Renderer>
                      <esri:SimpleRenderer>
                        <esri:SimpleFillSymbol Fill="Green" BorderBrush="Black" BorderThickness="2" />
                      </esri:SimpleRenderer>
                    </esri:LayerDrawingOptions.Renderer>
                  </esri:LayerDrawingOptions>
                </esri:LayerDrawingOptionsCollection>
              </esri:ArcGISDynamicMapServiceLayer.LayerDrawingOptions>
            </esri:ArcGISDynamicMapServiceLayer>
            

Example

How to use:

Click the button to add a Dynamic Layer (the state of Kentucky) via code-behind using a QueryDataSource. The 'WorkspaceID' and 'DataSourceName' for each Dynamic Layer must be provided to the developer by Manager/Adminstrator of the ArcGISDynamicMapServiceLayer. Examples of the 'WorkspaceID' and 'DataSourceName' are provided as comments in code-behind for a public ArcGIS Server that has Dynamic Layers enabled via the LayerDataSource object.

The XAML code in this example is used in conjunction with the code-behind (C# or VB.NET) to demonstrate the functionality.

The following screen shot corresponds to the code example in this page.

Adding a Dynamic Layer using a QueryDataSource.

XAMLCopy Code
<Grid x:Name="LayoutRoot">
  
  <!-- Add a Map Control. Zoom to the East-Central United States. -->
  <esri:Map Background="White" HorizontalAlignment="Left" Margin="0,204,0,0" Name="Map1" 
          VerticalAlignment="Top" Height="350" Width="500" Extent="-10349730,3871622,-8642421,5066738">
  
    <!--Add an ArcGISTiledMapServiceLayer as a backdrop. It has uses SpatialReference WKID=102100 (3857). -->
    <esri:ArcGISTiledMapServiceLayer ID="myArcGISTiledMapServiceLayer" 
      Url="http://services.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer" />
  
  </esri:Map>
  
  <!-- Button to add a Dynamic Layer (using QueryDataSource) via code-behind. -->
  <Button Content="Add a QueryDataSource based Dynamic Layer" Height="23" 
          HorizontalAlignment="Left" Margin="0,175,0,0" Name="Button1" VerticalAlignment="Top" Width="500" 
          Click="Button1_Click"/>
  
  <!-- Provide the instructions on how to use the sample code. -->
  <TextBlock Height="145" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" Width="788" 
    TextWrapping="Wrap" Text="Click the button to add a Dynamic Layer (the state of Kentucky) via code-behind using 
    a QueryDataSource. The 'WorkspaceID' and 'DataSourceName' for each Dynamic Layer must be provided to the 
    developer by Manager/Adminstrator of the ArcGISDynamicMapServiceLayer. Examples of the 'WorkspaceID' and 
    'DataSourceName' are provided as comments in code-behind for a public ArcGIS Server that has Dynamic Layers 
    enabled via the LayerDataSource object."/>
  
</Grid>
C#Copy Code
private void Button1_Click(object sender, System.Windows.RoutedEventArgs e)
{
  // Add a Layer on-the-fly based on an ArcGISDynamicMapServiceLayer that has Dynamic Layer capabalities enabled.
  // The Dynamic Layer is being generated uses the 'Workspace Type' of 'Database' via the LayerDataSource object. Review the
  // ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer Class documentation in the API reference for a full discussion.
  // In order to create this Dynamic Layer, information was shared between the Manager/Admininstrator of the
  // ArcGISDynamicMapServiceLayer ArcGIS Server service and the application developer.
  //
  // The Url for the ArcGISDynamicMapServiceLayer is: "http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer".
  //
  // The WorkspaceID used in the LayerDataSource for the Dynamic Layer is: "MyDatabaseWorkspaceIDSSR2"
  //
  // There are several DataSourceName types associated with the WorkspaceID that could be used to create the Rendering 
  // of a Dynamic Layer. Think of the DataSourceName as the string name of the layer that will be drawn dynamically.
  // A listing of the available DataSourceNames (and their geometry type) are:
  // "ss6.gdb.states" <== Polygons
  // "ss6.gdb.cities" <== Points
  // "ss6.gdb.counties" <== Polygons
  // "ss6.gdb.highways" <== Polylines
  // "ss6.gdb.lakes" <== Polygons
  
  // Create a QueryDataSource object and set all of it's Properties to valid values.
  ESRI.ArcGIS.Client.QueryDataSource myQueryDataSource = new ESRI.ArcGIS.Client.QueryDataSource();
  myQueryDataSource.GeometryType = ESRI.ArcGIS.Client.Tasks.GeometryType.Polygon;
  string[] myOIDFields = {"OBJECTID"};
  myQueryDataSource.OIDFields = myOIDFields;
  myQueryDataSource.Query = "SELECT * FROM ss6.gdb.states where state_name = 'Kentucky'";
  ESRI.ArcGIS.Client.Geometry.SpatialReference mySpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(4326);
  myQueryDataSource.SpatialReference = mySpatialReference;
  myQueryDataSource.WorkspaceID = "MyDatabaseWorkspaceIDSSR2";
  
  // Create a new LayerDataSource and set its DataSource Property to the QueryDataSource.
  ESRI.ArcGIS.Client.LayerDataSource myLayerDataSource = new ESRI.ArcGIS.Client.LayerDataSource();
  myLayerDataSource.DataSource = myQueryDataSource;
  
  // Create a new DynamicLayerInfo object and set its ID and Source Properties.
  ESRI.ArcGIS.Client.DynamicLayerInfo myDynamicLayerInfo = new ESRI.ArcGIS.Client.DynamicLayerInfo();
  myDynamicLayerInfo.ID = 102; // Must be the same as the LayerDrawingOptions.LayerID
  myDynamicLayerInfo.Source = myLayerDataSource;
  
  // Create a new DynamicLayerInfoCollection and add the DynamicLayerInfo object into it.
  ESRI.ArcGIS.Client.DynamicLayerInfoCollection myDynamicLayerInfoCollection = new ESRI.ArcGIS.Client.DynamicLayerInfoCollection();
  myDynamicLayerInfoCollection.Add(myDynamicLayerInfo);
  
  // Create a SimpleFillSymbol (Green Fill, with Black Border, and BorderThickness of 2).
  ESRI.ArcGIS.Client.Symbols.SimpleFillSymbol mySimpleFillSymbol = new ESRI.ArcGIS.Client.Symbols.SimpleFillSymbol();
  mySimpleFillSymbol.Fill = new System.Windows.Media.SolidColorBrush(Colors.Green);
  mySimpleFillSymbol.BorderThickness = 2;
  mySimpleFillSymbol.BorderBrush = new System.Windows.Media.SolidColorBrush(Colors.Black);
  
  // Create a new SimpleRenderer based upon the SimpleFillSymbol.
  ESRI.ArcGIS.Client.SimpleRenderer mySimpleRenderer = new ESRI.ArcGIS.Client.SimpleRenderer();
  mySimpleRenderer.Symbol = mySimpleFillSymbol;
  
  // Create a new LayerDrawingOptions object which is key to applying our custom Rendering of the Dynamic Layer.
  // It is imperative that the LayerDrawingOptions.LayerID = DynamicLayerInfo.ID so that the Dynamic Layer draws
  // using the new symbology.
  ESRI.ArcGIS.Client.LayerDrawingOptions myLayerDrawingOptions = new ESRI.ArcGIS.Client.LayerDrawingOptions();
  myLayerDrawingOptions.LayerID = 102; // Must be the same as the DynammicLayerInfo.ID
  myLayerDrawingOptions.Renderer = mySimpleRenderer;
  
  // Create a new LayerDrawinOptionsCollection and add the LayerDraingOptions object into it.
  ESRI.ArcGIS.Client.LayerDrawingOptionsCollection myLayerDrawingOptionsCollection = new ESRI.ArcGIS.Client.LayerDrawingOptionsCollection();
  myLayerDrawingOptionsCollection.Add(myLayerDrawingOptions);
  
  // Create a new Dynamic Layer that is based upon on a LayerDataSource of an ArcGISDynamicMapServiceLayer
  // and apply it's custom rendering.
  ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer myArcGISDynamicMapServiceLayer = new ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer();
  myArcGISDynamicMapServiceLayer.Url = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer";
  myArcGISDynamicMapServiceLayer.DisableClientCaching = true;
  myArcGISDynamicMapServiceLayer.DynamicLayerInfos = myDynamicLayerInfoCollection;
  myArcGISDynamicMapServiceLayer.LayerDrawingOptions = myLayerDrawingOptionsCollection;
  
  // Add the Dynamic Layer to the Map Control. This causes the round trip server request to occur.
  Map1.Layers.Add(myArcGISDynamicMapServiceLayer);
}
VB.NETCopy Code
Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
  
  ' Add a Layer on-the-fly based on an ArcGISDynamicMapServiceLayer that has Dynamic Layer capabalities enabled.
  ' The Dynamic Layer is being generated uses the 'Workspace Type' of 'Database' via the LayerDataSource object. Review the
  ' ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer Class documentation in the API reference for a full discussion.
  ' In order to create this Dynamic Layer, information was shared between the Manager/Admininstrator of the
  ' ArcGISDynamicMapServiceLayer ArcGIS Server service and the application developer.
  '
  ' The Url for the ArcGISDynamicMapServiceLayer is: "http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer".
  '
  ' The WorkspaceID used in the LayerDataSource for the Dynamic Layer is: "MyDatabaseWorkspaceIDSSR2"
  '
  ' There are several DataSourceName types associated with the WorkspaceID that could be used to create the Rendering 
  ' of a Dynamic Layer. Think of the DataSourceName as the string name of the layer that will be drawn dynamically.
  ' A listing of the available DataSourceNames (and their geometry type) are:
  ' "ss6.gdb.states" <== Polygons
  ' "ss6.gdb.cities" <== Points
  ' "ss6.gdb.counties" <== Polygons
  ' "ss6.gdb.highways" <== Polylines
  ' "ss6.gdb.lakes" <== Polygons
  
  ' Create a QueryDataSource object and set all of it's Properties to valid values.
  Dim myQueryDataSource As New ESRI.ArcGIS.Client.QueryDataSource
  myQueryDataSource.GeometryType = ESRI.ArcGIS.Client.Tasks.GeometryType.Polygon
  Dim myOIDFields As String() = {"OBJECTID"}
  myQueryDataSource.OIDFields = myOIDFields
  myQueryDataSource.Query = "SELECT * FROM ss6.gdb.states where state_name = 'Kentucky'"
  Dim mySpatialReference As New ESRI.ArcGIS.Client.Geometry.SpatialReference(4326)
  myQueryDataSource.SpatialReference = mySpatialReference
  myQueryDataSource.WorkspaceID = "MyDatabaseWorkspaceIDSSR2"
  
  ' Create a new LayerDataSource and set its DataSource Property to the QueryDataSource.
  Dim myLayerDataSource As New ESRI.ArcGIS.Client.LayerDataSource
  myLayerDataSource.DataSource = myQueryDataSource
  
  ' Create a new DynamicLayerInfo object and set its ID and Source Properties.
  Dim myDynamicLayerInfo As New ESRI.ArcGIS.Client.DynamicLayerInfo
  myDynamicLayerInfo.ID = 102 ' Must be the same as the LayerDrawingOptions.LayerID 
  myDynamicLayerInfo.Source = myLayerDataSource
  
  ' Create a new DynamicLayerInfoCollection and add the DynamicLayerInfo object into it.
  Dim myDynamicLayerInfoCollection As New ESRI.ArcGIS.Client.DynamicLayerInfoCollection
  myDynamicLayerInfoCollection.Add(myDynamicLayerInfo)
  
  ' Create a SimpleFillSymbol (Green Fill, with Black Border, and BorderThickness of 2).
  Dim mySimpleFillSymbol As New ESRI.ArcGIS.Client.Symbols.SimpleFillSymbol
  mySimpleFillSymbol.Fill = New System.Windows.Media.SolidColorBrush(Colors.Green)
  mySimpleFillSymbol.BorderThickness = 2
  mySimpleFillSymbol.BorderBrush = New System.Windows.Media.SolidColorBrush(Colors.Black)
  
  ' Create a new SimpleRenderer based upon the SimpleFillSymbol.
  Dim mySimpleRenderer As New ESRI.ArcGIS.Client.SimpleRenderer
  mySimpleRenderer.Symbol = mySimpleFillSymbol
  
  ' Create a new LayerDrawingOptions object which is key to applying our custom Rendering of the Dynamic Layer.
  ' It is imperative that the LayerDrawingOptions.LayerID = DynamicLayerInfo.ID so that the Dynamic Layer draws
  ' using the new symbology.
  Dim myLayerDrawingOptions As New ESRI.ArcGIS.Client.LayerDrawingOptions
  myLayerDrawingOptions.LayerID = 102 ' Must be the same as the DynammicLayerInfo.ID
  myLayerDrawingOptions.Renderer = mySimpleRenderer
  
  ' Create a new LayerDrawinOptionsCollection and add the LayerDraingOptions object into it.
  Dim myLayerDrawingOptionsCollection As New ESRI.ArcGIS.Client.LayerDrawingOptionsCollection
  myLayerDrawingOptionsCollection.Add(myLayerDrawingOptions)
  
  ' Create a new Dynamic Layer that is based upon on a LayerDataSource of an ArcGISDynamicMapServiceLayer
  ' and apply it's custom rendering.
  Dim myArcGISDynamicMapServiceLayer As New ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer
  myArcGISDynamicMapServiceLayer.Url = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer"
  myArcGISDynamicMapServiceLayer.DisableClientCaching = True
  myArcGISDynamicMapServiceLayer.DynamicLayerInfos = myDynamicLayerInfoCollection
  myArcGISDynamicMapServiceLayer.LayerDrawingOptions = myLayerDrawingOptionsCollection
  
  ' Add the Dynamic Layer to the Map Control. This causes the round trip server request to occur.
  Map1.Layers.Add(myArcGISDynamicMapServiceLayer)
  
End Sub

Inheritance Hierarchy

System.Object
   ESRI.ArcGIS.Client.DataSource
      ESRI.ArcGIS.Client.QueryDataSource

Requirements

Target Platforms: Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family, Windows 7, Windows 8

See Also

© ESRI, Inc. All Rights Reserved.