Zusammenfassung
Creates a raster object by applying a raster function or function chain to one or more input rasters.
Diskussion
Use the Apply function to process one or more raster datasets using a raster function or function chain. This function creates a raster object that is the input raster object or objects with a raster function applied.
The referenced raster dataset for the output raster object is temporary. To make it permanent, you can call the raster object's save method.
Syntax
Apply (in_raster, raster_function, {raster_function_arguments})
Parameter | Erläuterung | Datentyp |
in_raster [in_raster,...] | The input raster dataset or datasets. The input can include the following:
| Raster |
raster_function | The name of a raster function or the path to a custom raster function (.rft.xml file) to apply to the input. | String |
raster_function_arguments | The parameters and values associated with the raster function or function chain. If not specified, and if applicable, default values will be used. For example, the Tasseled Cap raster function does not require any arguments; the input is a single raster, so there is no need to specify arguments. The Arithmetic raster function, however, requires 5 input parameters: Raster, Raster2, Operation, Cellsize Type and Extent Type. To use Arithmetic with the Apply function, Raster and Raster2 are defined in the in_raster parameter, and the remaining parameters have default values, so if nothing is specified for those parameters, the default values will be used. For information about the function arguments for each raster function, see Raster function objects. | Dictionary |
Datentyp | Erläuterung |
Raster | The output raster dataset with the function applied. |
Codebeispiel
Apply NDVI, Arithmetic, and Composite Bands functions to one or more raster datasets.
# Apply NDVI, Arithmetic, and Composite Bands functions to one or more raster datasets.
import arcpy
from arcpy.ia import *
# Set input raster for NDVI
Landsat = Raster("Landsat8_1_12_18.tif")
# Apply NDVI raster function to a single raster
out_NDVI_raster = Apply(Landsat, "NDVI", {'VisibleBandID':4,'InfraredBandID':5})
# Set input rasters for Arithmetic
DEM = Raster("DEM.tif")
Buildings = Raster("BuildingHeights.tif")
# Apply Arithmetic raster function to add building height to ground elevation
out_Arithmetic_raster = Apply((DEM, Buildings),'Plus')
# Set input rasters for Composite Bands
Band1 = Raster("L8_MSB1.tif")
Band2 = Raster("L8_MSB2.tif")
Band3 = Raster("L8_MSB3.tif")
# Apply Composite Bands function to combine three bands into a single raster
out_composite_rasters = Apply([Band1, Band2, Band3], 'CompositeBand')
Apply the Heat Index function to two multidimensional raster subsets.
# Apply Heat Index function to multidimensional raster objects
import arcpy
from arcpy.ia import *
# Set input multidimensional raster dataset
in_raster = Raster("C:\\test.gdb\ClimateData", True)
# Select the relative humidity variable
RH = Subset(ClimateData, variables = 'rh')
# Select the temperature variable
Temp = Subset(ClimateData, variables = 't')
# Apply the Heat Index function to the two multidimensional raster subsets
# The output is a multidimensional raster where each slice is the heat index for the slice's time
heat_index_raster= Apply({'temperature': Temp, 'rh': RH}, 'HeatIndex', {'units':'Kelvin', 'outUnits':'Fahrenheit'})