Skip To Content

Raster

Zusammenfassung

Creates a raster object that can be used in Python scripting or in a Map Algebra expression. A raster object is a variable that references a raster dataset.

A raster object can be created in two ways, by supplying the path to an existing raster on disk, or it can be the result of any Map Algebra statement that results in a raster output.

Lizenz:

Either an Erweiterung "ArcGIS Spatial Analyst" or an ArcGIS Image Analyst extension is necessary to execute Map Algebra statements.

Auswertung

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 with the following mechanisms:

  1. By calling the save method on the raster object.
  2. Call Make Permanent by right-clicking the layer with an associated raster object in the TOC and specifying an output name.
  3. Saving the map project (.mxd, .3dd, and so on) that contains any layers with associated raster objects.

    In case 3, the dataset referenced by the raster object will automatically be permanently saved to disk with a default name.

If the referenced raster is not made permanent by any of the three cases above, the variable and the referenced raster dataset will be deleted when the variable goes out of scope, such as when a stand-alone script is completed 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 rasters (as opposed to scalars), 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 creating 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 None. The affected properties are catalogPath, compressionType, format, hasRAT, name, and path.

Once permanent, the referenced raster dataset cannot return to the temporary state.

Syntax

 Raster (inRaster, {is_multidimensional})
ParameterErklärungDatentyp
inRaster

The input raster dataset.

Raster
is_multidimensional

Determines whether the input raster will be treated as multidimensional. Use True if the input is multidimensional and should be processed as multidimensional, where processing occurs for every slice in the dataset. Use False if the input is not multidimensional, or if it is multidimensional and should not be processed as multidimensional.

(Der Standardwert ist False)

Boolean

Eigenschaften

EigenschaftErklärungDatentyp
bandCount
(Nur lesen)

The number of bands in the referenced raster dataset.

Integer
catalogPath
(Nur lesen)

The full path and the name of the referenced raster dataset.

String
compressionType
(Nur lesen)

The compression type. The following are the available types:

  • LZ77
  • JPEG
  • JPEG 2000
  • PACKBITS
  • LZW
  • RLE
  • CCITT GROUP 3
  • CCITT GROUP 4
  • CCITT (1D)
  • None

String
extent
(Nur lesen)

The extent of the referenced raster dataset.

Extent
format
(Nur lesen)

The raster format

  • BIL—Esri Band Interleaved by Line file
  • BIP—Esri Band Interleaved by Pixel file
  • BMP—Bitmap graphic raster dataset format
  • BSQ—Esri Band Sequential file
  • DAT—ENVI DAT file
  • GIF—Graphic Interchange Format for raster datasets
  • Grid—Esri Grid raster dataset format
  • IMAGINE Image—ERDAS IMAGINE raster data format
  • JP2000—JPEG 2000 raster dataset format
  • JPEG—Joint Photographic Experts Group raster dataset format
  • PNG—Portable Network Graphic raster dataset format
  • TIFF—Tag Image File Format for raster datasets

String
hasRAT
(Lesen und schreiben)

Identifies if there is an associated attribute table: True if an attribute table exists, or False if no attribute table exists.

Boolean
height
(Nur lesen)

The number of rows.

Integer
isInteger
(Nur lesen)

True if the raster dataset has integer type.

Boolean
isMultidimensional
(Nur lesen)

True if the raster dataset is multidimensional.

Boolean
isTemporary
(Nur lesen)

True if the raster dataset is temporary, or False if it is permanent.

Boolean
maximum
(Nur lesen)

The maximum value in the referenced raster dataset.

Double
mean
(Nur lesen)

The mean value in the referenced raster dataset.

Double
meanCellHeight
(Nur lesen)

The cell size in the y direction.

Double
meanCellWidth
(Nur lesen)

The cell size in the x direction.

Double
minimum
(Nur lesen)

The minimum value in the referenced raster dataset.

Double
mdinfo
(Nur lesen)

The multidimensional information of the raster dataset, including variable names, descriptions and units, and dimension names, units, intervals, units, and ranges. For example, a multidimensional raster containing monthly temperature data over 10 months would 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
(Nur lesen)

The name of the referenced raster dataset.

String
noDataValue
(Nur lesen)

The NoData value of the referenced raster dataset.

Double
path
(Nur lesen)

The full path and name of the referenced raster dataset.

String
pixelType
(Nur lesen)

The pixel type of the referenced raster dataset. The types are the following:

  • U1—1 bit
  • U2—2 bits
  • U4—4 bits
  • U8—Unsigned 8 bit integers
  • S8—8 bit integers
  • U16—Unsigned 16 bit integers
  • S16—16 bit integers
  • U32—Unsigned 32 bit integers
  • S32—32 bit integers
  • F32—Single precision floating point
  • F64—Double precision floating point

String
slices
(Nur lesen)

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 would return the following: [{'variable': 'temp', 'StdTime': '2017-1-15'}, {'variable': 'temp', 'StdTime': '2017-2-15'}, .....{'variable': 'temp', 'StdTime': '2018-12-15'}]

String
spatialReference
(Nur lesen)

The spatial reference of the referenced raster dataset.

SpatialReference
standardDeviation
(Nur lesen)

The standard deviation of the values in the referenced raster dataset.

Double
uncompressedSize
(Nur lesen)

The size of the referenced raster dataset on disk.

Double
variables
(Nur lesen)

The variable names and their dimensions in the multidimensional raster dataset. For example, a multidimensional raster containing temperature data over 24 months would return the following: ['temp(StdTime=24)']

String
variableNames
(Nur lesen)

The variable names in the multidimensional raster dataset.

String
width
(Nur lesen)

The number of columns.

Integer

Methodenübersicht

MethodeErklärung
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.

getVariableAttributes (variable_name)

Returns the attribute information of a variable in a multidimensional raster dataset (for example, description, unit, and so on).

save ({name})

Permanently saves the dataset referenced by the raster object.

Methoden

getDimensionAttributes (variable_name, dimension_name)
ParameterErklärungDatentyp
variable_name

The variable name of the multidimensional raster dataset.

String
dimension_name

The dimension name of the multidimensional raster dataset.

String
Rückgabewert
DatentypErklärung
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)
ParameterErklärungDatentyp
variable_name

The variable name of the multidimensional raster dataset.

String
Rückgabewert
DatentypErklärung
String

The dimension names associated with the variable.

getDimensionValues (variable_name, dimension_name)
ParameterErklärungDatentyp
variable_name

The variable name of the multidimensional raster dataset.

String
dimension_name

The dimension name of the multidimensional raster dataset.

String
Rückgabewert
DatentypErklärung
String

The dimension values of the variable.

getVariableAttributes (variable_name)
ParameterErklärungDatentyp
variable_name

The variable name of the multidimensional raster dataset.

String
Rückgabewert
DatentypErklärung
String

The attribute information of the variable.

save ({name})
ParameterErklärungDatentyp
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

Codebeispiel

Raster example 1

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
Raster example 2

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")
Raster example 3

Creates a Raster object from a multidimensional raster dataset, 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")