Summary
Converts a NumPy array to a raster.
Discussion
The size and data type of the resulting raster dataset depends on the input array.
NumpyArrayToRaster supports the direct conversion of multidimensional NumPy arrays to a multiband raster.
- If the input array has two dimensions, it returns a single-band raster, where the size of the raster is defined by the dimensions (rows, columns).
- If the input array has three dimensions, it returns a multiband raster, where the number of bands equals the length of the first dimension and the size of the raster is defined by the second and third dimensions (bands, rows, columns).
- If the input array has three dimensions, and the first dimension has size 1, it returns a single-band raster.
Having the x_cell_size and the y_cell_size arguments allows support for rectangular cells.
Note:
Rectangular cell sizes are not supported for the Esri Grid format.
This function honors the following geoprocessing environment settings:
Output Coordinate System, Extent, Snap Raster, Current Workspace, Scratch Workspace
Syntax
NumPyArrayToRaster (in_array, {lower_left_corner}, {x_cell_size}, {y_cell_size}, {value_to_nodata})
Parameter | Explanation | Data Type |
in_array | The NumPy array to convert to a raster. A two- or three-dimensional NumPy array is required. | NumPyArray |
lower_left_corner | A Point object defining the lower left corner of the output raster in map units. The default will set the lower left corner to coordinate (0.0, 0.0). (The default value is None) | Point |
x_cell_size | The cell size in the x direction specified in map units. The input can be a specified cell size (type: double) value, or a raster. When a dataset is specified, the x cell size of that dataset is used for the x cell size of the output raster. If only the x_cell_size is identified and not the y_cell_size, a square cell will result with the specified size. If neither x_cell_size nor y_cell_size is specified, a default of 1.0 will be used for both the x and y cell size. (The default value is 1.0) | Double |
y_cell_size | The cell size in the y direction specified in map units. The input can be a specified cell size (type: double) value, or a raster. When a dataset is specified, the x cell size of that dataset is used for the y cell size of the output raster. If only the y_cell_size is identified and not the x_cell_size, a square cell will result with the specified size. If neither x_cell_size nor y_cell_size is specified, a default of 1.0 will be used for both the x and y cell size. (The default value is 1.0) | Double |
value_to_nodata | The value in the NumPy array to assign to NoData in the output raster. If no value is specified for value_to_nodata, there will not be any NoData values in the resulting raster. (The default value is None) | Double |
Data Type | Explanation |
Raster | The output raster. |
Code sample
A new raster is created from a randomly generated NumPy array.
Missing source code file
Block process an input multiband raster and calculate cell statistics across the bands. This script converts a multiband raster to a three-dimensional NumPy array and processes the array by dividing it into data blocks. It then calculates the mean of values across the rows of the block, converts the block numpy array to raster, and recombines the bands via mosaicking. A new multiband raster is created.
Missing source code file