RasterInfo

Summary

Defines a RasterInfo object that describes a set of raster properties to facilitate the creation of a raster dataset using the Raster class.

Discussion

A RasterInfo object can be created by instantiating it from the RasterInfo class, or by calling a Raster object's getRasterInfo method. When a RasterInfo object is created through a Raster object, its properties are initialized using the Raster object's properties.

A RasterInfo object can be used as the input to the Raster class to create a raster dataset, whose cells can be iterated through and assigned values using a RasterCellIterator object.

Syntax

RasterInfo ()

Method Overview

MethodExplanation
fromJSONString (json)

Loads properties from a JSON string.

getBandCount ()

Returns the band count property of the RasterInfo object.

getBlockHeight ()

Returns the block height property of the RasterInfo object.

getBlockWidth ()

Returns the block width property of the RasterInfo object.

getCellSize ()

Returns the cell size property of the RasterInfo object.

getExtent ()

Returns the extent property of the RasterInfo object.

getNoDataValues ()

Returns the NoData value property of the RasterInfo object.

getPixelType ()

Returns the pixel type property of the RasterInfo object.

getSpatialReference ()

Returns the spatial reference property of the RasterInfo object.

setBandCount (band_count)

Sets the band count property.

setBlockHeight (block_height)

Sets the block height property.

setBlockWidth (block_width)

Sets the block width property.

setCellSize (cell_size)

Sets the cell size property.

setExtent (extent)

Sets the extent property.

setNoDataValues (nodata_values)

Sets the NoData values property.

setPixelType (pixel_type)

Sets the pixel type property.

setSpatialReference (spatial_reference)

Sets the spatial reference property.

toJSONString ()

Returns a JSON representation of the RasterInfo object.

Methods

fromJSONString (json)
ParameterExplanationData Type
json

The input JSON string that will be loaded.

An input JSON string example:

{
	"extent": {
		"xmin": 1708552.6584149038,
		"ymin": 40759.4130924825367,
		"xmax": 1710125.89027346508,
		"ymax": 42023.4400903051792,
		"spatialReference": {
			"wkid": 102663,
			"latestWkid": 3759
		}
	},
	"geodataXform": {
		"spatialReference": {
			"wkid": 102663,
			"latestWkid": 3759
		},
		"type": "IdentityXform"
	},
	"blockWidth": 128,
	"blockHeight": 128,
	"bandCount": 1,
	"pixelType": "F32",
	"noData": 3.402823E+38,
	"pixelSizeX": 10,
	"pixelSizeY": 10
}

String
getBandCount ()
Return Value
Data TypeExplanation
Integer

The band count.

getBlockHeight ()
Return Value
Data TypeExplanation
Integer

The block height.

getBlockWidth ()
Return Value
Data TypeExplanation
Integer

The block width.

getCellSize ()
Return Value
Data TypeExplanation
tuple

A tuple whose first element represents mean (average) cell width and second element represents mean cell height.

getExtent ()
Return Value
Data TypeExplanation
Extent

The raster extent.

getNoDataValues ()
Return Value
Data TypeExplanation
Variant

A number (integer or floating point) or a tuple that represents the NoData values for a raster.

If the band count is 1, getNoDataValues will return a number. If the band count is greater than 1, getNoDataValues will return a tuple, with each element representing the NoData value for the corresponding band.

getPixelType ()
Return Value
Data TypeExplanation
String

The pixel type.

getSpatialReference ()
Return Value
Data TypeExplanation
SpatialReference

A SpatialReference object representing the raster's spatial reference.

setBandCount (band_count)
ParameterExplanationData Type
band_count

The band count.

Integer
setBlockHeight (block_height)
ParameterExplanationData Type
block_height

The block height.

Integer
setBlockWidth (block_width)
ParameterExplanationData Type
block_width

The block width.

Integer
setCellSize (cell_size)
ParameterExplanationData Type
cell_size

The cell size. The first element of the tuple represents the cell width and the second element represents the cell height.

tuple
setExtent (extent)
ParameterExplanationData Type
extent

The extent.

Extent
setNoDataValues (nodata_values)
ParameterExplanationData Type
nodata_values

A number or a tuple that specifies the NoData values.

If a number is specified, it will be used as the NoData value for all bands. If a tuple is specified, each element in the tuple will be interpreted as the NoData value for the corresponding band. The number of elements in the tuple must match the band count.

Variant
setPixelType (pixel_type)
ParameterExplanationData Type
pixel_type

The pixel type, such as S32 or F32.

  • U1Unsigned 1-bit integer
  • U2Unsigned 2-bit integer
  • U4Unsigned 4-bit integer
  • S8Signed 8-bit integer
  • U8Unsigned 8-bit integer
  • S16 Signed 16-bit integer
  • U16 Unsigned 16-bit integer
  • S32Signed 32-bit integer
  • U32Unsigned 32-bit integer
  • F3232-bit floating point
  • F6464-bit double
String
setSpatialReference (spatial_reference)
ParameterExplanationData Type
spatial_reference

The spatial reference.

SpatialReference
toJSONString ()
Return Value
Data TypeExplanation
String

A JSON string that represents the RasterInfo object.

Code sample

RasterInfo example 1

Creates a RasterInfo object from the RasterInfo class, and uses it to create a raster dataset.

# Import system modules
import arcpy

# Create raster info object
rasInfo = arcpy.RasterInfo()

# Create a spatial reference object
spRef = arcpy.SpatialReference(32145)
# Create an extent object
ext = arcpy.Extent(471090.082572495, 208342.353396819, 494670.082572495, 231352.353396819, 0, 0, 0, 0, spRef)

# Initialize raster info object properties
# Set the spatial reference property
rasInfo.setSpatialReference(spRef)
# Set the extent property
rasInfo.setExtent(ext)
# Set the cell size property
rasInfo.setCellSize((30, 30))
# Set the pixel type property
rasInfo.setPixelType("S16")

# Create a new raster dataset using the raster info object
outRas = arcpy.Raster(rasInfo)
outRas.save("C:/arcpyExamples/outputs/newras01.tif")
RasterInfo example 2

Creates a RasterInfo object from a Raster object, and uses it to create a raster dataset.

# Import system modules
import arcpy

# Create a raster object
inRaster = arcpy.Raster("C:/arcpyExamples/inputs/elevation.tif")

# Get the raster info object
rasInfo = inRaster.getRasterInfo()

# Change some properties for the raster info object
# Change the cell size property
rasInfo.setCellSize((45, 45))
# Change the pixel type property
rasInfo.setPixelType("S32")

# Create a new raster dataset using the raster info object
outRas = arcpy.Raster(rasInfo)
outRas.save("C:/arcpyExamples/outputs/newras02.tif")