About working with field and selection
You might not want to perform a Spatial Analyst operation on the entire input dataset, but rather on a subset of the data. You might also want an operation to use values from a certain field in the data's attribute table instead of the default field. Examples of this include a pH field in a soil raster, a string field of road type in a roads feature class, or a numeric field of measured elevation in a point feature class.
Any numeric field in your input data can be specified as the analysis field for most operations and many operations also support analysis on string fields. Furthermore, almost all Spatial Analyst operations allow analysis to be performed on a subset of the input data. This subset can be specified using a logical query on any numeric or string field in the input data.
To create an attribute selection or subset of the cells of an input raster dataset, create a Raster object first, then create a RasterDescriptor using the Raster and the logical query.
Similarly, the same thing can be done with feature data inputs by creating a FeatureClassDescriptor from a FeatureClass. You can also create a RasterDescriptor or FeatureClassDescriptor using any desired field.
The following code example shows how to create a RasterDescriptor:
[C#] The following code example shows how to create a RasterDescriptor:
public IRasterDescriptor UsingRasterDescriptor(IRaster inRaster, string sFieldName,
string sValue)
{
// Creates a RasterDescriptor from an input raster and applies a Where clause.
// Create the RasterDecriptor.
IRasterDescriptor rasterDescriptor=new RasterDescriptorClass();
try
{
// Creates the query.
IQueryFilter queryFilter=new QueryFilterClass();
queryFilter.WhereClause=sFieldName + "=" + sValue;
// Performs the selection.
rasterDescriptor.Create(inRaster, queryFilter, sFieldName);
}
catch (Exception ex)
{
rasterDescriptor=null;
}
return rasterDescriptor;
}
[VB.NET] Public Function UsingRasterDescriptor(ByVal inRaster As IRaster, ByVal sFieldName As String, ByVal sValue As String) As IRasterDescriptor
' Creates a RasterDescriptor from an input raster and applies a Where clause.
' Create the RasterDecriptor.
Dim rasterDescriptor As IRasterDescriptor=New RasterDescriptorClass
Try
' Creates the query.
Dim queryFilter As IQueryFilter=New QueryFilterClass
queryFilter.WhereClause=sFieldName + "=" + sValue
' Performs the selection.
rasterDescriptor.Create(inRaster, queryFilter, sFieldName)
Catch ex As Exception
rasterDescriptor=Nothing
End Try
Return rasterDescriptor
End Function
Development licensing | Deployment licensing |
---|---|
ArcGIS for Desktop Basic | |
ArcGIS for Desktop Standard | |
ArcGIS for Desktop Advanced |