Synthèse
Creates a raster object that can be used in Python or in a Map Algebra expression. A raster object is a variable that references a raster dataset.
A raster object can be created in three ways: by supplying the path to an existing raster on disk, by supplying a RasterInfo object, or it can be the result of any Map Algebra statement that results in a raster output.
Licence :
Either an ArcGIS Spatial Analyst extension or an ArcGIS Image Analyst extension is necessary to execute Map Algebra statements.
Discussion
The raster object created from existing data can be used in subsequent Map Algebra expressions and will have all the associated raster properties and methods.
# out_raster is a resultant raster object
out_raster = Raster("c:/data/inraster")
Any tool or operator (see Working with operators in Map Algebra) that produces an output raster to the left of the equal sign creates a raster object. For example, in the following expression, out_raster is a raster object.
out_raster = Slope("inelevation")
When a Raster object is returned from a Map Algebra expression, by default, the object (the variable and associated dataset) is temporary.
The temporary dataset associated with a raster object can become permanent by calling the raster object's save method.
If the referenced raster is not made permanent, the variable and the referenced raster dataset will be deleted when the variable goes out of scope, such as when a stand-alone script completes or ArcGIS is closed. When a raster object references permanent data on disk, the data is not deleted.
Certain operators exist in both Map Algebra and in Python. If you want an operator to work on a raster (as opposed to a scalar), the input rasters must be cast as a raster object by calling the Raster class constructor: Raster("inRaster").
# The plus operator (available with Spatial Analyst or Image Analyst) is
# used on the input rasters to create an output raster object
out_raster = Raster("input1") + Raster("input2")
# The Python plus operator is used on numbers, creating a scalar variable
out_var = 4 + 7
# When there is a mix of rasters with numbers, the Spatial Analyst
# operator is used, creating an output raster object
out_raster = Raster("input") + 10
Certain properties associated with the raster object are only available if the referenced raster dataset is permanent. When the referenced raster dataset is temporary, these properties will be assigned a value of None. The affected properties are catalogPath, compressionType, format, hasRAT, name, and path.
Once permanent, the referenced raster dataset cannot return to the temporary state.
When a raster object is created by supplying the path to an existing raster on disk, its readOnly property is True by default and its cell values can be read using the [row, column] index notation.
in_raster = Raster('c:/data/inraster')
# Read the cell value at the second row and third column
v = in_raster[1, 2]
When a raster object is created by supplying a RasterInfo object as input, it will create a temporary raster in the ArcGIS temp directory. The readOnly property of such a raster object is False by default and its cell values can be modified using the [row, column] index notation.
in_raster = Raster('c:/data/inraster')
raster_info = in_raster.getRasterInfo()
new_raster = Raster(raster_info) # Create a new raster
# Modify the cell value at the second row and third column
new_raster[1, 2] = 3
new_raster.save('c:/output/outraster1')
In a RasterCellIterator loop, Raster objects are used to read and write data at cell level using the [row, column] index notation.
Syntaxe
Raster (inRaster, {is_multidimensional})
Paramètre | Explication | Type de données |
inRaster [inRaster,...] | The input raster dataset or list of raster datasets. When multiple multidimensional raster datasets are provided, the files will be interpreted as a single multidimensional dataset, with variables and dimensions unioned together. If two files contain the same variable with the same dimension values, the slices in the output raster will come from the first multidimensional raster in the list. You can also specify a RasterInfo object as the input inRaster, which will create a new raster dataset on disk. In this case, the is_multidimensional input parameter will be ignored. | Raster |
is_multidimensional | Determines whether the input raster will be treated as multidimensional. Specify True if the input is multidimensional and should be processed as multidimensional, where processing occurs for every slice in the dataset. Specify False if the input is not multidimensional, or if it is multidimensional and should not be processed as multidimensional. (La valeur par défaut est False) | Boolean |
Propriétés
Propriété | Explication | Type de données |
bandCount (Lecture seule) | The number of bands in the referenced raster dataset. | Integer |
bandNames (Lecture seule) | The band names in the referenced raster dataset. | String |
blockSize (Lecture seule) | The block size of the referenced raster dataset. | tuple |
catalogPath (Lecture seule) | The full path and the name of the referenced raster dataset. | String |
catalogPaths (Lecture seule) | The full path and the name of each item comprising a mosaic dataset. | String |
compressionType (Lecture seule) | The compression type. The following are the available types:
| String |
extent (Lecture seule) | The extent of the referenced raster dataset. | Extent |
format (Lecture seule) | The raster format.
| String |
functions (Lecture seule) | Retrieves a raster function template using the path to the rft.xml file. Rasters can be processed with the retrieved template using the Apply function. | String |
hasRAT (Lecture seule) | Identifies whether there is an associated attribute table: True if an attribute table exists, or False if no attribute table exists. | Boolean |
hasTranspose (Lecture et écriture) | Identifies whether there is a transposed version of the multidimensional data associated with the raster: True if there is an associated transpose or False if no transpose exists. | Boolean |
height (Lecture seule) | The number of rows. | Integer |
isInteger (Lecture seule) | True if the raster dataset has an integer type. | Boolean |
isMultidimensional (Lecture seule) | True if the raster dataset is multidimensional. | Boolean |
isTemporary (Lecture seule) | True if the raster dataset is temporary or False if it is permanent. | Boolean |
maximum (Lecture seule) | The maximum value in the referenced raster dataset. | Double |
mean (Lecture seule) | The mean value in the referenced raster dataset. | Double |
meanCellHeight (Lecture seule) | The cell size in the y direction. | Double |
meanCellWidth (Lecture seule) | The cell size in the x direction. | Double |
minimum (Lecture seule) | The minimum value in the referenced raster dataset. | Double |
mdinfo (Lecture seule) | The multidimensional information of the raster dataset, including variable names; descriptions and units; and dimension names, units, intervals, and ranges. For example, a multidimensional raster containing monthly temperature data over 10 months will return the following: {"variables": [{"name":"Temp", "dimensions":[{"name":"StdTime", "field":"StdTime", "hasRegularIntervals":true, "interval":1, "intervalUnit":"Months", "extent":["1982-01-15T00:00:00", "1982-10-15T00:00:00"], "hasRanges":false,"values":["1982-01-15T00:00:00", "1982-02-15T00:00:00, ... "1982-10-15T00:00:00"]}]}], "layout":1} If the raster is not a multidimensional raster, this property returns None. | String |
name (Lecture seule) | The name of the referenced raster dataset. | String |
names (Lecture seule) | The name of each item comprising a mosaic dataset. | String |
noDataValue (Lecture seule) | The NoData value of the referenced raster dataset. | Double |
noDataValues (Lecture seule) | The NoData value for each band in the referenced multiband raster dataset. | tuple |
path (Lecture seule) | The full path of the referenced raster dataset. | String |
pixelType (Lecture seule) | The pixel type of the referenced raster dataset. The types are the following:
| String |
properties (Lecture seule) | The property name and value pairs in the referenced raster dataset. | Dictionary |
RAT (Lecture seule) | The attribute table of the referenced raster dataset. For example, the attribute table for a raster dataset with two classes will return {'OID': [0, 1], 'Value': [10, 20], 'ClassName': ['Low', 'High'], 'Red': [178, 56], 'Green': [178, 168], 'Blue': [178, 0], 'Alpha': [255, 255], 'Count': [887412.0, 962159.0]}. If the raster is multidimensional, there will be a Count field for each slice in the dataset. If no attribute table exists, None is returned. | Dictionary |
readOnly (Lecture et écriture) | Specifies whether the raster cell values are writable using the [row, column] notation. When this property is True, they are not writable. Otherwise, they are writable. | Boolean |
slices (Lecture seule) | The attribute information of each slice, including its variable name, dimension names, and dimension values returned as a list of dictionaries. For example, a multidimensional raster containing temperature data over 24 months will return the following: [{'variable': 'temp', 'StdTime': '2017-1-15'}, {'variable': 'temp', 'StdTime': '2017-2-15'}, .....{'variable': 'temp', 'StdTime': '2018-12-15'}] | String |
spatialReference (Lecture seule) | The spatial reference of the exported image. Supported options include the following:
| SpatialReference |
standardDeviation (Lecture seule) | The standard deviation of the values in the referenced raster dataset. | Double |
uncompressedSize (Lecture seule) | The size of the referenced raster dataset on disk. | Double |
variables (Lecture seule) | The variable names and their dimensions in the multidimensional raster dataset. For example, a multidimensional raster containing temperature data over 24 months will return the following: ['temp(StdTime=24)']. | String |
variableNames (Lecture seule) | The variable names in the multidimensional raster dataset. | String |
width (Lecture seule) | The number of columns. | Integer |
Vue d’ensemble des méthodes
Méthode | Explication |
addDimension (variable, new_dimension_name, dimension_value, {dimension_attributes}) | Adds a new dimension to a variable in a multidimensional raster object so that the multidimensional raster can be compatible with other multidimensional datasets. |
appendSlices (mdRaster) | Appends the slices from another multidimensional raster. |
computeGSD (locations, spatial_reference, {dem}) | Returns the ground sample distance (GSD) x- and y-values for an input image. |
computeHistograms ({variable}, {aoi}, {cellsize}) | Returns the histogram of the raster. If the raster is multidimensional, it returns the histogram of a variable. |
computeStatistics ({variable}, {aoi}, {cellsize}) | Returns the statistics of the raster. If the raster is multidimensional, it returns the statistics of a variable. |
exportImage ({width}, {height}, {format}, {extent}, {spatial_reference}, {mosaic_rule}) | Exports the raster object as an IPython Image object to be used for visualization in Jupyter Notebook. |
getColormap ({variable_name}) | Returns the color map of the raster. If the raster is multidimensional, returns the color map of a variable. |
getDimensionAttributes (variable_name, dimension_name) | Returns the attribute information of a dimension for a specific variable in a multidimensional raster dataset, for example, description, unit, and so on. |
getDimensionNames (variable_name) | Returns the dimension names associated with a variable in a multidimensional raster dataset. |
getDimensionValues (variable_name, dimension_name) | Returns the values of a dimension associated with a variable in a multidimensional raster dataset. |
getHistograms ({variable_name}) | Returns the histograms of the raster. If the raster is multidimensional, it returns the histogram of a variable. If the raster is multiband, it returns the histogram of each band. |
getProperty (property_name) | Returns the value of the given property. |
getRasterBands ({band_ids_or_names}) | Returns a Raster object for each band specified in a multiband raster dataset. |
getRasterInfo () | Returns a RasterInfo object whose properties are initialized using the raster object properties. |
getStatistics ({variable_name}) | Returns the statistics of the raster. If the raster is multidimensional, returns the statistics of a variable. |
getVariableAttributes (variable_name) | Returns the attribute information of a variable in a multidimensional raster dataset (for example, description, unit, and so on). |
isConstant (constantValue) | Identifies whether a raster only contains a constant value. |
read ({upper_left_corner}, {origin_coordinate}, {ncols}, {nrows}, {nodata_to_value}, {cell_size}) | Reads a raster and converts the raster to a NumPy array. |
removeVariables (variable_names) | Removes a variable or a list of variables from a Cloud Raster Format (CRF) multidimensional raster dataset. |
renameBand (current_band_name_or_index, new_band_name) | Renames a band in a multiband raster dataset. |
renameVariable (current_variable_name, new_variable_name) | Renames a variable in a Cloud Raster Format (CRF) multidimensional raster dataset. |
save ({name}) | Permanently saves the dataset referenced by the raster object. |
setColormap (color_map, {variable_name}) | Sets the color map for the raster. If the raster is multidimensional, it sets the color map for a variable. |
setHistograms (histogram_obj, {variable_name}) | Sets the histograms of the raster. If the raster is multidimensional, sets the histogram of a variable. |
setProperty (property_name, property_value) | Add a customized property to the raster dataset. If the property name exists, the existing property value will be overwritten. |
setStatistics (statistics_obj, {variable_name}) | Sets the statistics for the raster. If the raster is multiband, it sets the statistics for each band. If the raster is multidimensional, it sets the statistics for a variable. |
setVariableAttributes (variable_name, variable_attributes) | Sets the attribute information of a variable in a multidimensional raster (for example, description, unit, and so on). |
write (array, {upper_left_corner}, {origin_coordinate}, {value_to_nodata}) | Converts a three- or four-dimensional NumPy array to a raster. |
Méthodes
addDimension (variable, new_dimension_name, dimension_value, {dimension_attributes})
Paramètre | Explication | Type de données |
variable | The name of the variable to which the dimension will be added. Only multidimensional rasters in Cloud Raster Format (.crf) are supported. | String |
new_dimension_name | The name of the new dimension. | String |
dimension_value | The value to assign to the new dimension. Only one value can be added, as more values (for example, multiple depths) would require new slices to be added to the dataset. To add more than one dimension value along with the new slices, use the addDimension method, then use the Merge function to merge existing data with the raster object. | Double |
dimension_attributes | A Python dictionary that contains attribute information to be added to the new dimension, such as description or unit. For example, to add a unit attribute, use {"unit": "meters"}. (La valeur par défaut est None) | Dictionary |
Type de données | Explication |
String | The list of variable names and the corresponding dimensions of the multidimensional raster. |
appendSlices (mdRaster)
Paramètre | Explication | Type de données |
mdRaster | The multidimensional raster containing the slices to be appended. This raster must have the same variables, with the same dimension names, as the target raster. The cell sizes, extents, and spatial reference systems must also match. The slices in this raster must be for dimension values that follow the dimension values of the slices in the target raster. If a variable has two dimensions, slices will be appended along one dimension. The other dimension must have the same number of slices as the dimension in the target raster. For example, if a salinity variable contains slices over time and depth dimensions, time slices can be appended to another salinity multidimensional raster but only if the same number of depth slices exist in both rasters. | Raster |
Type de données | Explication |
String | A string containing the variable names and the associated dimensions in the multidimensional raster. For example, if the resulting raster has 10 time slices with precipitation data, it will return 'prcp(StdTime=10)'. |
computeGSD (locations, spatial_reference, {dem})
Paramètre | Explication | Type de données |
locations [locations,...] | A list of x,y-coordinates. | List |
spatial_reference | The spatial reference of the input locations. For example, the spatial reference can be specified using the following format: WGS_1984_UTM_Zone_11N. (La valeur par défaut est None) | String |
dem | The DEM to be used in the GSD computation. (La valeur par défaut est None) | String |
Type de données | Explication |
String | A list of the ground sample distance values. |
computeHistograms ({variable}, {aoi}, {cellsize})
Paramètre | Explication | Type de données |
variable | The variable name for the multidimensional dataset. If a variable is not specified and the raster is multidimensional, the histogram of all variables will be calculated. | String |
aoi [aoi,...] | The area of interest to calculate statistics for. This can be provided as Polygon object or a list of coordinates in the raster's spatial reference system in the form of [min_x, min_y, max_x, max_y]. | List |
cellsize | The cell size to calculate statistics from. The raster will be resampled to the specified cell size before statistics are calculated. If no value is specified, the cell size of the raster will be used. | Double |
Type de données | Explication |
Dictionary | A list of dictionaries containing the histogram of the raster or variable. For example, if the histogram is computed for a single band or variable, the output will be returned in the following format: [{'size': 251, 'min': -0.5, 'max': 250.5, 'counts': [814.0, 894.0, 836.0, 902.0, 1317.0, 1263.0, 1360.0]}]. |
computeStatistics ({variable}, {aoi}, {cellsize})
Paramètre | Explication | Type de données |
variable | The variable name for the multidimensional dataset. If a variable is not specified and the raster is multidimensional, the histogram of all variables will be calculated. | String |
aoi [aoi,...] | The area of interest to calculate statistics for. This can be provided as Polygon object or a list of coordinates in the raster's spatial reference system in the form of [min_x, min_y, max_x, max_y]. | List |
cellsize | The cell size to calculate statistics from. The raster will be resampled to the specified cell size before statistics are calculated. If no value is specified, the cell size of the raster will be used. | Double |
Type de données | Explication |
Dictionary | A list of dictionaries containing the statistics of the raster or variable. For example, if statistic are computed for a single band or variable, the output will be returned in the following format: [{'min': 0.0, 'max': 250.0, 'mean': 114.60855843925984, 'standardDeviation': 97.18526137567137, 'median': 78.0, 'mode': 250.0, 'skipX': 1, 'skipY': 1, 'count': 453120.0, 'covariances': '0.000000'}]. |
exportImage ({width}, {height}, {format}, {extent}, {spatial_reference}, {mosaic_rule})
Paramètre | Explication | Type de données |
width | The width of the output image in pixels. If a value is not specified, but the height is provided, the aspect ratio of the original raster will be maintained. If neither width nor height are specified, the width of the original raster dataset is used. (La valeur par défaut est None) | Integer |
height | The height of the output image in pixels. If a value is not specified, but the width is provided, the aspect ratio of the original raster will be maintained. If neither width nor height are specified, the height of the original raster dataset is used. (La valeur par défaut est None) | Integer |
format | The image format of the exported data. The supported formats include JPG, PNG, and PNG32. (La valeur par défaut est PNG32) | String |
extent | The extent or bounding box of the exported image. If a value is not specified, the extent of the raster dataset is used. (La valeur par défaut est None) | Extent |
spatial_reference | The spatial reference of the exported image. Supported options include the following:
(La valeur par défaut est None) | SpatialReference |
mosaic_rule | Specifies how the input raster data should be mosaicked. This is applicable when the input raster dataset is a mosaic dataset. For information on how to format the mosaic rule, see Mosaic rule objects. (La valeur par défaut est None) | Dictionary |
Type de données | Explication |
Object | The exported image as an IPython Image object. |
getColormap ({variable_name})
Paramètre | Explication | Type de données |
variable_name | The variable name of the multidimensional raster dataset. If a variable is not specified and the raster is multidimensional, the color map of the first variable will be returned. | String |
Type de données | Explication |
Dictionary | A Python dictionary containing the color map of the raster or variable. Pixel values are listed first, followed by the corresponding color map values in HEX color codes—for example, {'type': 'RasterColormap', 'values': [10, 20, 30], 'colors': ['#66FF33', '#0033CC', '#FF00FF']}. |
getDimensionAttributes (variable_name, dimension_name)
Paramètre | Explication | Type de données |
variable_name | The variable name of the multidimensional raster dataset. | String |
dimension_name | The dimension name of the multidimensional raster dataset. | String |
Type de données | Explication |
String | The attribute information of the dimension, for example, the minimum and maximum dimension values, the time step interval, and the interval units. |
getDimensionNames (variable_name)
Paramètre | Explication | Type de données |
variable_name | The variable name of the multidimensional raster dataset. | String |
Type de données | Explication |
String | The dimension names associated with the variable. |
getDimensionValues (variable_name, dimension_name)
Paramètre | Explication | Type de données |
variable_name | The variable name of the multidimensional raster dataset. | String |
dimension_name | The dimension name of the multidimensional raster dataset. | String |
Type de données | Explication |
String | The dimension values of the variable. |
getHistograms ({variable_name})
Paramètre | Explication | Type de données |
variable_name | The variable name of the multidimensional raster dataset. If a variable is not specified and the raster is multidimensional, the histogram of the first variable will be returned. | String |
Type de données | Explication |
Dictionary | The histogram values of the raster or variable—for example, [{'size': 10, 'min': 0.0, 'max': 364.0, 'counts': [882.0, 18.0, 9.0, 0.0, 9.0, 0.0, 18.0, 9.0, 18.0, 0.0]}]. |
getProperty (property_name)
Paramètre | Explication | Type de données |
property_name | The property name of the raster dataset. | String |
Type de données | Explication |
String | The value of the property. |
getRasterBands ({band_ids_or_names})
Paramètre | Explication | Type de données |
band_ids_or_names [band_ids_or_names,...] | The index number or names of the bands to return as Raster objects. If not specified, all bands will be extracted. (La valeur par défaut est None) | String |
Type de données | Explication |
Raster | The Raster object for each band specified. |
getRasterInfo ()
Type de données | Explication |
Object | A RasterInfo object. |
getStatistics ({variable_name})
Paramètre | Explication | Type de données |
variable_name | The variable name of the multidimensional raster dataset. If a variable is not specified and the raster is multidimensional, the statistics of the first variable will be returned. | String |
Type de données | Explication |
Dictionary | The statistics of the raster or variable. |
getVariableAttributes (variable_name)
Paramètre | Explication | Type de données |
variable_name | The variable name of the multidimensional raster dataset. | String |
Type de données | Explication |
String | The attribute information of the variable. |
isConstant (constantValue)
Paramètre | Explication | Type de données |
constantValue | The value to evaluate for in the raster. | Double |
Type de données | Explication |
Boolean | A Boolean that indicates whether the raster only contains the constant value. |
read ({upper_left_corner}, {origin_coordinate}, {ncols}, {nrows}, {nodata_to_value}, {cell_size})
Paramètre | Explication | Type de données |
upper_left_corner |
The coordinates relative to the origin_coordinate from which to extract the processing block to convert to an array. This should be formatted as a tuple with two values indicating the direction to move in the x- and y-direction, respectively. For example, a value of (2,0) indicates that the array should be extracted starting at the pixel that is two pixels away, in the x-direction, from the origin_coordinate. If no value is specified, (0,0) is used. (La valeur par défaut est None) | tuple |
origin_coordinate |
The point of origin within the Raster object from which to extract the processing block to convert to an array. The coordinates must be in the units of the raster. If no value is specified, the origin of the raster will be used. (La valeur par défaut est None) | Point |
ncols |
The number of columns from the upper_left_corner in the Raster object to convert to the NumPy array. If no value is specified, the number of columns of the raster will be used. (La valeur par défaut est None) | Integer |
nrows |
The number of rows from the upper_left_corner in the Raster object to convert to the NumPy array. If no value is specified, the number of rows of the raster will be used. (La valeur par défaut est None) | Integer |
nodata_to_value |
The pixel value to assign in the NumPy array for those pixels labeled as NoData in the Raster object. If no value is specified, the NoData value of the raster will be used. (La valeur par défaut est None) | Variant |
cell_size |
The cell size to use in the NumPy array. This should be formatted as a tuple with two values indicating the cell size in the x- and y-direction, respectively, and units should match those used by the raster. For example, a value of (2, 1) indicates the output cell size should be 2 units in the x-direction and 1 unit in the y-direction. If the cell size is different from the data source, the cell values are resampled using bilinear interpolation. If no value is specified, the cell size of the raster will be used. (La valeur par défaut est None) | tuple |
Type de données | Explication |
NumPyArray | The output NumPy array. |
If the raster is a single- or multiband raster, the dimensions of the array will be rows, columns, and number of bands.
If the raster is a multidimensional raster, the dimensions of the array will be number of slices, rows, columns, and number of bands.
removeVariables (variable_names)
Paramètre | Explication | Type de données |
variable_names [variable_names,...] | The variable name or a list of variable names to be removed from the multidimensional raster dataset. | String |
renameBand (current_band_name_or_index, new_band_name)
Paramètre | Explication | Type de données |
current_band_name_or_index | The name or the index of the band to be renamed. The band indexing begins at 1. This argument can be a string or integer value. | String |
new_band_name | The new band name. | String |
Type de données | Explication |
Raster | The Raster object with renamed bands. |
renameVariable (current_variable_name, new_variable_name)
Paramètre | Explication | Type de données |
current_variable_name | The current name of the variable in a multidimensional raster dataset. | String |
new_variable_name | The new name of the variable in a multidimensional raster dataset. | String |
save ({name})
Paramètre | Explication | Type de données |
name | The name to assign to the raster dataset on disk. This method supports persisting a multidimensional raster dataset as Cloud Raster Format (CRF). | String |
setColormap (color_map, {variable_name})
Paramètre | Explication | Type de données |
color_map | The color map to apply to the raster. This can be a string indicating the name of the color map or color ramp to use, for example, NDVI or Yellow To Red, respectively. This can also be a Python dictionary with a custom color map or color ramp object—for example, a custom color map {'values': [0, 1, 2, 3, 4, 5], 'colors': ['#000000', '#DCFFDF', '#B8FFBE', '#85FF90', '#50FF60','#00AB10']} or a custom color ramp {"type": "algorithmic", "fromColor": [115, 76, 0, 255],"toColor": [255, 25, 86, 255], "algorithm": "esriHSVAlgorithm"}. | String |
variable_name | The variable name of the multidimensional raster dataset. If a variable is not specified and the raster is multidimensional, the color map of the first variable will be set. | String |
setHistograms (histogram_obj, {variable_name})
Paramètre | Explication | Type de données |
histogram_obj [histogram_obj,...] | A list of Python dictionaries containing histogram information to be set—for example, [{'size': 5, 'min': 19.0, 'max': 42.0, 'counts': [275, 17, 3065, 4, 22]}]. If the raster is multiband, the histogram for each band will be set with each dictionary in the list. The first band will use the histogram in the first dictionary. The second band will use the histogram in the second dictionary, and so on.
| Dictionary |
variable_name | The variable name of the multidimensional raster dataset. If a variable is not specified and the raster is multidimensional, the histogram will be set for the first variable. | String |
setProperty (property_name, property_value)
Paramètre | Explication | Type de données |
property_name | The property name of the raster dataset. | String |
property_value | The value to assign to the property. | String |
setStatistics (statistics_obj, {variable_name})
Paramètre | Explication | Type de données |
statistics_obj [statistics_obj,...] |
A list of Python dictionaries containing statistics and corresponding values to set. For example, [{'min': 10, 'max': 20}] sets the minimum and maximum pixel values. If the raster is multiband, the statistics for each band will be set with each dictionary in the list. The first band will use the statistics in the first dictionary. The second band will use the statistics in the second dictionary, and so on.
| List |
variable_name | The variable name of the multidimensional raster dataset. If a variable is not specified and the raster is multidimensional, the statistics of the first variable will be set. | String |
setVariableAttributes (variable_name, variable_attributes)
Paramètre | Explication | Type de données |
variable_name | The variable name of the multidimensional raster dataset. | String |
variable_attributes | A Python dictionary that contains attribute information to replace the current attribute information of the variable—for example, {'Description': 'Daily total precipitation', 'Unit': 'mm/day'}. | Dictionary |
Type de données | Explication |
String | The attribute information of the variable. |
write (array, {upper_left_corner}, {origin_coordinate}, {value_to_nodata})
Paramètre | Explication | Type de données |
array |
The input NumPy array. (La valeur par défaut est None) | NumPyArray |
upper_left_corner |
The coordinates relative to the origin_coordinate from which to extract the processing block to convert to a raster. This should be formatted as a tuple with two values indicating the number of pixels to move along the x- and y- direction, respectively. For example, (2,0), indicates that the position from which the NumPy array will be written into the raster is 2 pixels away, in the x-direction, from the origin_coordinate. If no value is specified, (0,0) is used. (La valeur par défaut est None) | tuple |
origin_coordinate |
A Point object defining the origin, from which the numpy array will be written into the Raster. The x- and y-values are in th units of the raster. If no value is specified, the upper left corner of the raster, will be used. If no value is specified, the origin of the raster will be used. This is the default. (La valeur par défaut est None) | Point |
value_to_nodata |
A value in the NumPy array to be used as the NoData value in the Raster. The value can be an integer or a float. If no value is specified, the NoData value of the Raster will be used. The default value is None. (La valeur par défaut est None) | Double |
If the raster is a single-band raster, the dimensions of the array must be rows, columns, 1.
If the raster is a multiband raster, the dimensions of the array must be rows, columns, band count.
If the raster is a multidimensional raster, in which each slice is single band, the dimensions of the array must be number of slices, rows, columns, 1.
If the raster is a multidimensional raster, in which each slice is multiband, the dimensions of the array must be number of slices, rows, columns, band count.
Exemple de code
Creates a Raster object from a raster dataset and gets properties for analysis.
import arcpy
my_raster = arcpy.Raster('elevation')
my_min = my_raster.minimum
my_max = my_raster.maximum
my_area = (my_raster.width * my_raster.height) * my_raster.meanCellWidth
Creates a Raster object, retrieves the raster function templates from the raster dataset, and applies the processing templates.
import arcpy
#Create raster object
ras = arcpy.Raster(r"D:\Data\ndfd.crf")
#Define two raster function templates from the input CRF
ras.functions =[r"C:\weather.rft.xml", r"C:\heatindex.rft.xml"]
#Retrieve the first rft and process the raster object using the Apply function
rft = ras.functions
processed_raster = arcpy.ia.Apply(ras, json.dumps(rft[1]))
Creates a Raster object, gets properties, creates a random error raster (+/- 3 feet), adds it to an elevation raster, and converts its units from feet to meters.
import arcpy
from arcpy.sa import *
elev_raster = Raster('c:/data/elevation')
my_extent = elev_raster.extent
my_cellsize = (elev_raster.meanCellHeight + elev_raster.meanCellWidth) / 2
res01 = arcpy.CreateRandomRaster_management("", "error3", "UNIFORM 0.0 3.0",
my_extent, my_cellsize)
elev_meters = (elev_raster + Raster(res01)) * 0.3048
elev_meters.save("c:/output/fgdb.gdb/elevM_err")
Creates a Raster object from a multidimensional raster dataset and gets multidimensional information including variables and dimension values.
import arcpy
## Load a netCDF file as a multidimensional raster
mdim_raster = Raster("Precip_2000_2018.nc", True)
## Check if it is multidimensional raster
is_multidimensional = mdim_raster.isMultidimensional
## Return the multidimensional information
my_mdinfo = mdim_raster.mdinfo
## Return the list of variable names and their dimensions
my_variables = mdim_raster.variables
## Get the time dimension values for the precipitation variable
my_dimensionValues = mdim_raster.getDimensionValues("precip", "StdTime")
# save as a mdim crf
mdim_raster.save("c:/output/Precip_18_yr.crf")
Creates a Raster object from a multidimensional raster dataset and computes the statistics for a variable.
import arcpy
#Load a netCDF file as a multidimensional raster
mdim_raster = Raster("Precip_2000_2018.nc", True)
#Create an array that contains the corner coordinates for a bounding box
array = arcpy.Array([arcpy.Point(-119.8082436, 38.2177764), arcpy.Point(-119.7794812, 38.2038911), arcpy.Point(-119.7432803, 38.2232313), arcpy.Point(-119.7928706, 38.2425716)])
#Specify a spatial reference
spatial_reference = arcpy.SpatialReference(4326)
#Create a polygon object that will be used to specify the aoi
aoi= arcpy.Polygon(array, spatial_reference)
#return the statistics
stats = mdim_raster.computeStatistics('precip', aoi, cellsize = 463)
Vous avez un commentaire à formuler concernant cette rubrique ?