ArcGIS Explorer Component Help |
ServiceChildLayer..::.Query Method |
ServiceChildLayer Class Example See Also |
Assembly: ESRI.ArcGISExplorer (in ESRI.ArcGISExplorer.dll) Version: 2.0.0.1500 (2.0.0.1500)
Syntax
C# |
---|
public FeatureLayer Query( string whereClause ) |
Visual Basic (Declaration) |
---|
Public Function Query ( _ whereClause As String _ ) As FeatureLayer |
Parameters
- whereClause
- Type: System..::.String
A string containing the SQL WHERE clause to be used in the query on this ServiceChildLayer.
Return Value
A new Mapping.FeatureLayer containing the subset of features from the ServiceChildLayer which match the criteria in the SQL WHERE Clause.Remarks
This method applies a query to the features within a ServiceChildLayer. All features matching the criteria specified in the query are returned in a new FeatureLayer. The query executed by the method follows the standard SQL structure of SELECT * FROM WHERE. It is the criteria which follow "WHERE" that must be specified in the whereClause parameter, for example "NAME = 'San Diego'".
Prior to calling the Query method of a ServiceChildLayer there are a number of other methods and properties which should be used to ensure the eventual call to the Query method will return a successful result:
- ServiceLayer.CanQuery: This value should be accessed first, prior to any members on the ServiceChildLayers which make up the ServiceLayer. If this value is false any attempt to access the query related members of a constituent ServiceChildLayer will result in an ExplorerException.
- ServiceChildLayer.CanQuery: If this value is false any attempt to access the query related members on this ServiceChildLayer will result in an ExplorerException.
- ServiceChildLayer.QueryFeatureLimit: This value should be used in conjunction with QueryFeatureCount below to ensure that the WHERE clause used in the Query method call does not produce a result set which exceeds this server-side setting.
- ServiceChildLayer.QueryFeatureCount: Informs you how many features would be returned in response to a given query without needing to return the actual result set to the client application. If this value is greater than the QueryFeatureLimit value above, the query should be modified and compared to the QueryFeatureLimit, repeatedly if necessary, until QueryFeatureCount is less than the QueryFeatureLimit.
Once a successful query has been established via the QueryFeatureLimit property and QueryFeatureCount method, that same query should be used when calling the actual Query method. The Query method will return a new FeatureLayer on which the Connect method must be called prior to any attempt to access certain members on that FeatureLayer (GeometryType, PopupProperties and Table). The DataSourceType of the layer will be InMemory.
Version Information: This member is supported from version 2.0.0.1500.
Examples
{ //Create a new ServiceConnectionProperties instance and populate with connection information ServiceConnectionProperties serviceConnProps = new ServiceConnectionProperties(ServiceType.MapServer, new Uri("http://sampleserver1.arcgisonline.com/ArcGIS/services/Demographics"), "/ESRI_Census_USA"); //Create a new ServiceLayer instance passing in the ServiceConnectionProperties ServiceLayer serviceLayer = new ServiceLayer(serviceConnProps); //Check the ServiceLayer can Connect if (!serviceLayer.Connect()) return; //Check this ServiceLayer supports queries if (!serviceLayer.CanQuery) return; //Get the "states" ServiceChildLayer on which we want to execute a query ServiceChildLayer serviceChildLayerStates = serviceLayer.FindByName("states") as ServiceChildLayer; //Check this ServiceChildlayer supports queries if (!serviceChildLayerStates.CanQuery) return; //Get the collection of columns for the ServiceChildLayer ColumnCollection columns = serviceChildLayerStates.Columns; //Create the WHERE clause string whereClause = string.Empty; //Check each column until the alias matches the intended query field foreach (Column column in columns) { //Use column members to confirm the the AliasName and data type if (column.AliasName == "POP2007" & column.Type == ColumnType.Integer) { //Populate the WHERE clause with matched column name, operator and value whereClause = column.Name + " > 10000000"; break; } } //Check the WHERE clause if (whereClause == string.Empty) return; //Get the maximum number of records returnable from the service int queryFeatureLimit = serviceChildLayerStates.QueryFeatureLimit; //Get the number of features matching the WHERE clause int queryFeatureCount = serviceChildLayerStates.QueryFeatureCount(whereClause); //IMPORTANT: Check the feature count is not greater than the feature limit if (!(queryFeatureCount <= queryFeatureLimit)) return; //Execute the Query method to get a new FeatureLayer containing the results FeatureLayer featureLayer = serviceChildLayerStates.Query(whereClause); //The FeatureLayer method must be called to access all FeatureLayer members if (!featureLayer.Connect()) return; //Implement code to work with FeatureLayer (in this case get the number of rows) int numberOfResultFeatures = featureLayer.Table.GetRows().Count; }
'Create a new ServiceConnectionProperties instance and populate with connection information Dim serviceConnProps As New ServiceConnectionProperties( _ ServiceType.MapServer, _ New Uri("http://sampleserver1.arcgisonline.com/ArcGIS/services/Demographics"), _ "/ESRI_Census_USA") 'Create a new ServiceLayer instance passing in the ServiceConnectionProperties Dim serviceLayer1 As New ServiceLayer(serviceConnProps) 'Check the ServiceLayer can Connect If Not serviceLayer1.Connect() Then Return End If 'Check this ServiceLayer supports queries If Not serviceLayer1.CanQuery Then Return End If 'Get the "states" ServiceChildLayer on which we want to execute a query Dim serviceChildLayerStates As ServiceChildLayer = TryCast(serviceLayer1.FindByName("states"), ServiceChildLayer) 'Check this ServiceChildlayer supports queries If Not serviceChildLayerStates.CanQuery Then Return End If 'Get the collection of columns for the ServiceChildLayer Dim columns As ColumnCollection = serviceChildLayerStates.Columns 'Create the WHERE clause Dim whereClause As String = String.Empty 'Check each column until the alias matches the intended query field For Each column As Column In columns 'Use column members to confirm the the AliasName and data type If column.AliasName = "POP2007" And column.Type = ColumnType.[Integer] Then 'Populate the WHERE clause with matched column name, operator and value whereClause = column.Name + " > 10000000" Exit For End If Next 'Check the WHERE clause If whereClause = String.Empty Then Return End If 'Get the maximum number of records returnable from the service Dim queryFeatureLimit As Integer = serviceChildLayerStates.QueryFeatureLimit 'Get the number of features matching the WHERE clause Dim queryFeatureCount As Integer = serviceChildLayerStates.QueryFeatureCount(whereClause) 'IMPORTANT: Check the feature count is not greater than the feature limit If Not (queryFeatureCount <= queryFeatureLimit) Then Return End If 'Execute the Query method to get a new FeatureLayer containing the results Dim featureLayer As FeatureLayer = serviceChildLayerStates.Query(whereClause) 'The FeatureLayer method must be called to access all FeatureLayer members If Not featureLayer.Connect() Then Return End If 'Implement code to work with FeatureLayer (in this case get the number of rows) Dim numberOfResultFeatures As Integer = featureLayer.Table.GetRows().Count