Creating classes
To use classes for input parameters for geoprocessing tools, you must first create them. Once instantiated, you can access their properties and query or modify the objects. The easiest way to learn how to create the various class objects is to see examples of them being created using different input types.
Tip:
The documentation for each class contains a scripting example of how each can be defined and used in a tool parameter.
Classes created with a fixed number of inputs
- The following are examples of creating a variety of classes from a fixed number of input:
# Creating a neighborhood class and assigning it to a variable neighborhood = NbrRectangle(10, 10, "CELL") outFocalStats = FocalStatistics(inRas, neighborhood, "MINORITY")
# Creating the Kriging model to be used kModelOrdinary = KrigingModelOrdinary("CIRCULAR", 2000, 2.6, 542, 0) # Creating a radius class and assigning it to a variable kRadius = RadiusFixed(20000, 1) outKriging = Kriging(inFeatures, field, kModelOrdinary, cellSize, kRadius, outVarRaster)
Classes created with Python lists or list of lists
- Below is an example of creating a class from a list for use in the Topo to Raster tool:
# Create classes as input for TopoToRaster myTopoPtElev = TopoPointElevation([["spots.shp", "spot_meter"], ["spots2.shp", "elev"]]) myTopoContour = TopoContour([["contours.shp", "spot_meter"]]) myTopoBoundary = TopoBoundary(["boundary.shp"]) myTopoLake = TopoLake(["lakes.shp"]) myTopoSink = TopoSink([["sink1.shp", "elevation"], ["sink2.shp", "NONE"]]) myTopoStream = TopoStream(["streams.shp"]) # Applying the tool outTopoToRaster = TopoToRaster([myTopoPtElev, myTopoContour, myTopoBoundary, myTopoLake, myTopoSink, myTopoStream])
- Below is an example of creating a class from a list for use in the Reclassify tool:
# The RemapValue class has a usage of: # RemapRange(startValue, endValue, newValue) RemapTable = RemapValue([[1, 5], [2, 8], [3, 1], [4, 10]]) # Run the tool outReclass = Reclassify("inRas", RemapTable)
Classes created from a series of classes within a list
- Below is an example of creating classes from a series of Point classes within a list, for use in the a raster cell extraction:
# Identify the points to be extracted by creating a list # of Point objects. PointsToExtract = [Point(0, 5), Point(15, 175), Point(225, 450)] # Run the tool Outraster = ExtractByPoints(PointsToExtract)
Default arguments
- Certain arguments are optional and are defined by {} (brace or curly brackets) in the usage. For example, the syntax for the wedge neighbourhood class is as follows:
NbrWedge({radius}, {startAngle}, {endAngle}, {units})
- If an optional argument is not specified, a default value will be used.
# The circle neighborhood will default to # a radius of 3 and units of CELL circle = NbrCircle()
- Optional arguments can be specified using either an empty quote, "" or "#", denoting the value is to be skipped and the default value is desired.
Related Topics
6/28/2013