Create Constant Raster (Spatial Analyst)

Summary

Creates a raster of a constant value within the extent and cell size of the analysis window.

Illustration

Create Constant raster illustration
OutRas = CreateConstantRaster(2)

Usage

Syntax

CreateConstantRaster (constant_value, {data_type}, {cell_size}, {extent})
ParameterExplanationData Type
constant_value

The constant value from which to create an output raster dataset.

Double
data_type
(Optional)

Data type of the output raster dataset.

  • INTEGER—An integer raster will be created.
  • FLOAT—A floating-point raster will be created.

If the specified data type is FLOAT, the input constant value is only accurate to 7 decimal places (single precision).

String
cell_size
(Optional)

The cell size for the output raster dataset.

This is the value in the environment if specifically set. If not specifically set, it is the shorter of the width or height of the environment extent in the output spatial reference, divided by 250.

Analysis Cell Size
extent
(Optional)

The extent for the output raster dataset.

The Extent is a Python class.

In this tool it is in the form of: Extent(XMin, YMin, XMax, YMax)

  • where XMin and YMin define the lower-left coordinate of the extent, with XMax and YMax defining the upper-right coordinate.

The coordinates are specified in the same map units as the in_raster.

The extent will be the value in the environment if specifically set. If not specifically set, the default is 0, 0, 250, 250.

Extent

Return Value

NameExplanationData Type
out_raster

The output raster for which each cell will have specified constant value.

Raster

Code Sample

CreateConstantRaster example 1 (Python window)

This sample creates a float raster of a particular value at the defined cell size and extent.

import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
outConstRaster = CreateConstantRaster(12.7, "FLOAT", 2, Extent(0, 0, 250, 250))
outConstRaster.save("C:/sapyexamples/output/outconst2")
CreateConstantRaster example 2 (stand-alone script)

This sample creates an integer raster of a particular value at the defined cell size and extent.

# Name: CreateConstantRaster_Ex_02.py
# Description: Creates a raster from a constant value
# Requirements: Spatial Analyst Extension
# Author: ESRI

# Import system modules
import arcpy
from arcpy.sa import *

# Set local variables
constantValue = 12
cellSize = 2
outExtent = Extent(0, 0, 250, 250)

# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")

# Execute CreateConstantRaster
outConstRaster = CreateConstantRaster(constantValue, "FLOAT", cellSize,
                                      outExtent)

# Save the output 
outConstRaster.save("C:/sapyexamples/output/outconst")

Environments

Related Topics

Licensing Information

ArcView: Requires Spatial Analyst
ArcEditor: Requires Spatial Analyst
ArcInfo: Requires Spatial Analyst

6/29/2011