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:

For additional information on using Spatial Analyst classes in Map Algebra, see the following:

Creating classesQuerying classesChanging arguments within classesHow to use classes in Python

The following are examples of applications that can easily be implemented using classes:

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:

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:

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:

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.

相关主题


7/10/2012