サマリー
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 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.
ライセンス:
Either an ArcGIS Spatial Analyst エクステンション or an ArcGIS Image Analyst extension is necessary to run map algebra statements.
説明
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 Work 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, the object (the variable and associated dataset) is temporary by default.
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 is 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 combination 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.
構文
Raster (inRaster, {is_multidimensional})
パラメーター | 説明 | データ タイプ |
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. (デフォルト値は次のとおりです False) | Boolean |
プロパティ
プロパティ | 説明 | データ タイプ |
bandCount (読み取り専用) | The number of bands in the referenced raster dataset. | Integer |
bandNames (読み取り専用) | The band names in the referenced raster dataset. | String |
blockSize (読み取り専用) | The block size of the referenced raster dataset. | tuple |
catalogPath (読み取り専用) | The full path and the name of the referenced raster dataset. | String |
catalogPaths (読み取り専用) | The full path and the name of each item comprising a mosaic dataset. | String |
compressionType (読み取り専用) | Specifies the compression type. The following are the available types:
| String |
extent (読み取り専用) | The extent of the referenced raster dataset. | Extent |
format (読み取り専用) | Specifies the raster format.
| String |
functions (読み取り専用) | 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 (読み取り専用) | Specifies whether an associated attribute table exists: True if an attribute table exists or False if no attribute table exists. | Boolean |
hasTranspose (読み書き) | Specifies whether a transposed version of the multidimensional data is associated with the raster: True if an associated transpose exists or False if no transpose exists. | Boolean |
height (読み取り専用) | The number of rows. | Integer |
isInteger (読み取り専用) | Specifies whether the raster dataset has an integer type. It's True if the raster dataset has an integer type. | Boolean |
isMultidimensional (読み取り専用) | Specifies whether the raster dataset is multidimensional. It's True if the raster dataset is multidimensional. | Boolean |
isTemporary (読み取り専用) | Specifies whether the raster dataset is temporary (True)or permanent (False). | Boolean |
maximum (読み取り専用) | The maximum value in the referenced raster dataset. | Double |
mean (読み取り専用) | The mean value in the referenced raster dataset. | Double |
meanCellHeight (読み取り専用) | The cell size in the y direction. | Double |
meanCellWidth (読み取り専用) | The cell size in the x direction. | Double |
minimum (読み取り専用) | The minimum value in the referenced raster dataset. | Double |
mdinfo (読み取り専用) | 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 (読み取り専用) | The name of the referenced raster dataset. | String |
names (読み取り専用) | The name of each item comprising a mosaic dataset. | String |
noDataValue (読み取り専用) | The NoData value of the referenced raster dataset. | Double |
noDataValues (読み取り専用) | The NoData value for each band in the referenced multiband raster dataset. | tuple |
path (読み取り専用) | The full path of the referenced raster dataset. | String |
pixelType (読み取り専用) | Specifies the pixel type of the referenced raster dataset. The types are the following:
| String |
properties (読み取り専用) | The property name and value pairs in the referenced raster dataset. | Dictionary |
RAT (読み取り専用) | 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 (読み書き) | Specifies whether the raster cell values are writable using the [row, column] notation. When this property is True, they are not writable. If it's False, they are writable. | Boolean |
slices (読み取り専用) | 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 (読み取り専用) | Specifies the spatial reference of the exported image. Supported options include the following:
| SpatialReference |
standardDeviation (読み取り専用) | The standard deviation of the values in the referenced raster dataset. | Double |
sum (読み取り専用) | The sum of the values in the referenced raster dataset. | Double |
uncompressedSize (読み取り専用) | The size of the referenced raster dataset on disk. | Double |
variables (読み取り専用) | The variable names and their dimensions in the multidimensional raster dataset. For example, a multidimensional raster containing temperature data over 24 months will return ['temp(StdTime=24)']. | String |
variableNames (読み取り専用) | The variable names in the multidimensional raster dataset. | String |
width (読み取り専用) | The number of columns. | Integer |
方法の概要
方法 | 説明 |
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. |
fromSTACItem (stac_item, {request_params}, {context}) | Creates a Raster object from a SpatioTemporal Asset Catalog (STAC) item. |
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. |
方法
addDimension (variable, new_dimension_name, dimension_value, {dimension_attributes})
パラメーター | 説明 | データ タイプ |
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"}. (デフォルト値は次のとおりです None) | Dictionary |
データ タイプ | 説明 |
String | The list of variable names and the corresponding dimensions of the multidimensional raster. |
appendSlices (mdRaster)
パラメーター | 説明 | データ タイプ |
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 |
データ タイプ | 説明 |
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})
パラメーター | 説明 | データ タイプ |
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. (デフォルト値は次のとおりです None) | String |
dem | The DEM to be used in the GSD computation. (デフォルト値は次のとおりです None) | String |
データ タイプ | 説明 |
String | A list of the ground sample distance values. |
computeHistograms ({variable}, {aoi}, {cellsize})
パラメーター | 説明 | データ タイプ |
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 |
データ タイプ | 説明 |
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})
パラメーター | 説明 | データ タイプ |
variable | The variable name of the multidimensional dataset. If a variable is not provided and the raster is multidimensional, the histogram of all variables will be calculated. | String |
aoi [aoi,...] | The area of interest that will be used to calculate statistics. This can be provided as a 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 that will be used to calculate statistics. 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 |
データ タイプ | 説明 |
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, 'sum': 51931430.0, '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})
パラメーター | 説明 | データ タイプ |
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. (デフォルト値は次のとおりです 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. (デフォルト値は次のとおりです None) | Integer |
format | The image format of the exported data. The supported formats include JPG, PNG, and PNG32. (デフォルト値は次のとおりです 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. (デフォルト値は次のとおりです None) | Extent |
spatial_reference | The spatial reference of the exported image. Supported options include the following:
(デフォルト値は次のとおりです 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. (デフォルト値は次のとおりです None) | Dictionary |
データ タイプ | 説明 |
Object | The exported image as an IPython Image object. |
fromSTACItem (stac_item, {request_params}, {context})
パラメーター | 説明 | データ タイプ |
stac_item |
The URL of the STAC item or a pystac.Item object. The URL can be a static STAC item URL or a STAC API item URL, for example, "https://planetarycomputer.microsoft.com/api/stac/v1/collections/naip/items/tx_m_2609719_se_14_060_20201217". STAC items from the following STAC APIs are supported:
STAC items from the following static catalogs (and their underlying child catalogs) are supported:
| String |
request_params | The STAC item request parameters. These are the requests.get() method parameters and values in dictionary format. This parameter is honored when the stac_item parameter is a URL.
| Dictionary |
context | Additional properties to control the creation of the object. The dictionary supports the assetManagement and processingTemplate keys. The assetManagement key specifies how to manage and select assets for the RasterCollection object. If multiple assets are selected, the collection will be composed of multiband rasters from those selected asset types. The value can be a list, string, or dictionary. When working with individual assets, the asset key can be specified directly, for example, "B02" or {"key": "B02"}, or as a list. Each item in the list represents an asset key or identifier. Items in the list can be strings representing the asset key directly, or dictionaries providing additional details for locating the asset. If the value of the assetManagement key is a dictionary, the following keys are supported:
Examples:
The processingTemplate key specifies the processing template that will be applied to the raster. This is supported for selected collections and raster types. For more information about collections and raster types, see Satellite sensor raster types. The default for supported raster types is "Multiband"; otherwise, it's None. Example:
| Dictionary |
データ タイプ | 説明 |
Raster | A new instance of this class is returned. |
getColormap ({variable_name})
パラメーター | 説明 | データ タイプ |
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 |
データ タイプ | 説明 |
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)
パラメーター | 説明 | データ タイプ |
variable_name | The variable name of the multidimensional raster dataset. | String |
dimension_name | The dimension name of the multidimensional raster dataset. | String |
データ タイプ | 説明 |
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)
パラメーター | 説明 | データ タイプ |
variable_name | The variable name of the multidimensional raster dataset. | String |
データ タイプ | 説明 |
String | The dimension names associated with the variable. |
getDimensionValues (variable_name, dimension_name)
パラメーター | 説明 | データ タイプ |
variable_name | The variable name of the multidimensional raster dataset. | String |
dimension_name | The dimension name of the multidimensional raster dataset. | String |
データ タイプ | 説明 |
String | The dimension values of the variable. |
getHistograms ({variable_name})
パラメーター | 説明 | データ タイプ |
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 |
データ タイプ | 説明 |
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)
パラメーター | 説明 | データ タイプ |
property_name | The property name of the raster dataset. | String |
データ タイプ | 説明 |
String | The value of the property. |
getRasterBands ({band_ids_or_names})
パラメーター | 説明 | データ タイプ |
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. (デフォルト値は次のとおりです None) | String |
データ タイプ | 説明 |
Raster | The Raster object for each band specified. |
getRasterInfo ()
データ タイプ | 説明 |
Object | A RasterInfo object. |
getStatistics ({variable_name})
パラメーター | 説明 | データ タイプ |
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 |
データ タイプ | 説明 |
Dictionary | The statistics of the raster or variable. |
getVariableAttributes (variable_name)
パラメーター | 説明 | データ タイプ |
variable_name | The variable name of the multidimensional raster dataset. | String |
データ タイプ | 説明 |
String | The attribute information of the variable. |
isConstant (constantValue)
パラメーター | 説明 | データ タイプ |
constantValue | The value to evaluate for in the raster. | Double |
データ タイプ | 説明 |
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})
パラメーター | 説明 | データ タイプ |
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. (デフォルト値は次のとおりです 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. (デフォルト値は次のとおりです 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. (デフォルト値は次のとおりです 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. (デフォルト値は次のとおりです 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. (デフォルト値は次のとおりです 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. (デフォルト値は次のとおりです None) | tuple |
データ タイプ | 説明 |
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)
パラメーター | 説明 | データ タイプ |
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)
パラメーター | 説明 | データ タイプ |
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 |
データ タイプ | 説明 |
Raster | The Raster object with renamed bands. |
renameVariable (current_variable_name, new_variable_name)
パラメーター | 説明 | データ タイプ |
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})
パラメーター | 説明 | データ タイプ |
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})
パラメーター | 説明 | データ タイプ |
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})
パラメーター | 説明 | データ タイプ |
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)
パラメーター | 説明 | データ タイプ |
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})
パラメーター | 説明 | データ タイプ |
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)
パラメーター | 説明 | データ タイプ |
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 |
データ タイプ | 説明 |
String | The attribute information of the variable. |
write (array, {upper_left_corner}, {origin_coordinate}, {value_to_nodata})
パラメーター | 説明 | データ タイプ |
array |
The input NumPy array. (デフォルト値は次のとおりです 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. (デフォルト値は次のとおりです 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. (デフォルト値は次のとおりです 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. (デフォルト値は次のとおりです 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.
コードのサンプル
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)
Creates a Raster object from a STAC Item.
from arcpy.ia import *
from arcpy import AIO
# 1) Creates a raster object from NAIP data accesible through Planetary Computer STAC API
naip_ras = Raster.fromSTACItem(
stac_item="https://planetarycomputer.microsoft.com/api/stac/v1/collections/naip/items/tx_m_2609719_se_14_060_20201217"
)
# Apply grayscale raster function to the raster object
gray_ras = Grayscale(naip_ras)
# 2) Creates a raster object from Sentinel-2 L2A data accesible through Earth Search STAC API
sentinel_2_ras = Raster.fromSTACItem(
stac_item="https://earth-search.aws.element84.com/v1/collections/sentinel-2-l2a/items/S2A_45XWD_20230328_0_L2A"
)
# Retrieve raster object properties
cols, rows = sentinel_2_ras.width, sentinel_2_ras.height
# 3) Creates a raster object from Landsat C2-L2 data accesible through USGS
# LandsatLook STAC API (with custom processing template selection) - Requires acs (AIO object).
landsat_acs = AIO(r"C:\acs_files\s3_landsat_c2.acs")
qa_landsat_ras = Raster.fromSTACItem(
stac_item="https://landsatlook.usgs.gov/stac-server/collections/landsat-c2l2-sr/items/LC09_L2SP_088084_20230729_20230801_02_T2_SR",
context={
"processingTemplate": "QA",
},
)
# 4) Creates a raster object from CBERS data accesible through
# CBERS/AMAZONIA on AWS (static) STAC (with custom asset selection) - Requires acs (AIO object).
cbers_acs = AIO(r"C:\acs_files\s3_cbers_pds.acs")
cbers_ras = Raster.fromSTACItem(
stac_item="https://br-eo-stac-1-0-0.s3.amazonaws.com/CBERS4/MUX/043/076/CBERS_4_MUX_20230630_043_076_L2.json",
context={"assetManagement": ["B7", "B6", "B5"]},
)