An overview of Spatial Analyst classes
Classes can be used to create objects, often referred to as an instance. Once the object is instantiated, its properties and methods may be used. Spatial Analyst classes, such as Neighborhood or Remap classes, are often used as shortcuts to complete geoprocessing tool parameters that would otherwise have a more complicated string equivalent.
It is much easier to create and manage parameters through classes rather than by strings. The benefits of using classes for parameters include these:
- Classes provide help and autocompletion for the varying arguments of the parameter.
- You can query the individual arguments for the parameter from the resulting object.
- You can easily modify individual arguments of the class for further analysis.
For additional information on using Spatial Analyst classes in Map Algebra, see the following:
The following are examples of applications that can easily be implemented using classes:
- Determine the class type or an individual argument value:
For example, querying the input radius type and the search distance may determine the power to apply in an inverse distance weighted (IDW) interpolation.
- Change an input value:
For example, you can easily change an input reclass value in a suitability model based on public input at a forum to explore the impact of different scenarios on the output without re-creating the remap table.
- To perform sensitivity analysis:
For example, you can iteratively change the To and From values in a remap table for a suitability model by increments of 5 percent to explore how slight changes to an input criterion will influence the output.
- To perform error analysis:
For example, you can run a model multiple times while randomly changing the arguments for the parameters to explore the potential impact of the error and uncertainty in the data.
Using Spatial Analyst classes
Some Spatial Analyst geoprocessing tool parameters use a class object as input. Typically, parameters are defined as simple strings, dataset names, paths, keywords, field names, tolerances, and domain names. Some parameters are more complex and define a series of properties or values. Instead of using long, complicated text strings to define these parameters, you can use classes (such as neighborhoods or remap tables). Understanding the input requirements to a class constructor will make it easier for you to create, query, change, and save class objects.
These are different types of input that are used as arguments to Spatial Analyst classes:
- Scalars
- Strings
- Python list or a list of lists
- Other classes
For readability, it is recommended the class be set to a variable and the variable used in the tool. For example:
Neighborhood = NbrRectangle(5, 5, "MAP")
outRas = FocalStatistics("inRas", Neighborhood, "MEAN")
However, if you prefer, the class can be defined within the tool parameter.
outRas = FocalStatistics("inRas", NbrRectangle(5, 5, "MAP"), "MEAN")
Classes created with a fixed number of inputs
Some classes are constructed with a fixed number of simple scalar or string arguments. For example, to create a create a circular neighborhood with a radius of five map units:
Neighborhood = NbrCircle(5, "MAP")
outRas = FocalStatistics("inRas", Neighborhood, "MAXIMUM")
Each of these classes has a predetermined position for the input arguments. These classes can be grouped based on the tool parameter they address:
- Fuzzy classes
(FuzzyGaussian, FuzzyLarge, FuzzyLinear, FuzzyMSLarge, FuzzyMSSmall, FuzzyNear, FuzzySmall)
- Horizontal factor classes
- KrigingModel classes
- Neighborhood classes
(NbrAnnulus, NbrCircle, NbrIrregular, NbrRectangle, NbrWedge, NbrWeight)
- Radius classes
- Time classes
(TimeWithinDay, TimeSpecialDays, TimeMultipleDays, TimeWholeYear)
- Vertical factor classes
(VfBinary, VfLinear, VfSymLinear,, VfInverseLinear, VfSymInverseLinear, VfCos, VfSec, VfCosSec, VfSecCos, VfTable)
Classes created with Python lists
Some classes are more complex, such as the TopoBoundary, TopoLake, and TopoStream classes. These require a series of inputs and are used for parameters in the Topo to Raster tool. The series of inputs are defined within a Python list, and the number of inputs into a list is dependent on the situation (in other words, the number of inputs the analysis requires).
For example, the TopoBoundary class constructors expect a list containing one or many inFeature inputs. The list, identified as inFeatures, becomes a property of the resulting object. To query or manipulate any items in the inFeatures list, you address each as an entry in the list (see Querying classes).
inBoundary = TopoBoundary(["inBound1.shp", "inBound2.shp"])
Classes created with lists within lists
With other tools, the specific situation will determine how many input entries will be entered into a parameter. This type of input parameter is generated from a class created using lists within a list. There are three groups of tools whose classes are created from lists within lists:
- Reclass tables (RemapRange, RemapValue)
- Weighted reclass tables (overlay and sum) (WOTable, WSTable)
- Topo classes (a subset) (TopoContour, TopoPointElevation, TopoSink)
For example, the Remap classes expect a table as input. The table is modeled by a list of records denoting the startValue, endValue, and newValue to be classified. A table becomes a property of the resulting object. To query or manipulate any of the table inputs, address them as entries in lists within lists (see Querying classes).
# Usage: RemapRange([[startValue, endValue, newValue],...])
myRemapRange = RemapRange([[-3, -1.75, 1], [-1.75, -0.5, 2], [-0.5, 0.75, 3],
[0.75, 2, 4], [2, 3.25, 5], [3.25, 4.5, 6],
[4.5, 5.75, 7], [5.75, 7, 8]])
outReclassRR = Reclassify("inRas", "VALUE", myRemapRange)
Classes created with a series of classes within a list
Some tools use class parameters that require a series of classes as input. The classes are composed within a list. The tools requiring a series of classes within a list, which include Extract by Points and Extract by Rectangle, generally extract data by a specified geometry.