ArcGIS Explorer Component Help |
ServiceChildLayer..::.QueryFeatureCount 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 int QueryFeatureCount( string whereClause ) |
Visual Basic (Declaration) |
---|
Public Function QueryFeatureCount ( _ whereClause As String _ ) As Integer |
Parameters
- whereClause
- Type: System..::.String
The query string to execute on the ServiceChildLayer.
Return Value
An integer indicating the number of features in the ServiceChildLayer matching the criteria specified in the whereClause.Remarks
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, thereby saving transport time and providing a means to determine whether the query will exceed the maximum number of results the service will return. If QueryFeatureCount returns a value greater than the QueryFeatureLimit, the query should be modified and QueryFeatureCount re-executed and compared to the QueryFeatureLimit, repeatedly if necessary, until QueryFeatureCount is less than the QueryFeatureLimit.
If CanQuery is false this method will throw an ExplorerException.
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