Raster

摘要

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

A raster object can be created in two ways, from any Spatial Analyst Map Agebra statement that results in a raster output or by supplying an existing raster on disk.

讨论

Any Spatial Analyst Map Algebra tool or operator (see Working with operators) that produces an output raster to the left of the equal sign creates a raster object. For example, in the following expression, outRas is a raster object.

outRas = 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:

  1. By calling the save method on the raster object.
  2. Call Make Permanent by right-clicking on the layer with an associated raster object in the TOC and specifying an output name.
  3. Saving the the map project (.MXD, 3DD, etc) 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 permanant 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 permanant data on disk, the data is not deleted.

The raster object created from existing data can be used in subsequent Spatial Analyst Map Algebra expressions and will have all the associated properties and methods.

# outRas is a resultant raster object
outRas = Raster("C:/Data/inraster") 

Certain operators exist in both Spatial Analyst 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 Spatial Analyst plus operator is used on the input rasters creating
# an output raster object
outRas = Raster("input1") + Raster("input2") 
																																												
# The Python plus operator is used on numbers creating a scalar variable
outVar = 4 + 7 

# When there is a mix of rasters with numbers the Spatial Analyst
# operator is used creating an output raster object
outRas = 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.

语法

Raster (inRaster)
参数说明数据类型
inRaster

The input raster dataset.

Raster

属性

属性说明数据类型
bandCount
(只读)

The number of bands in the referenced raster dataset.

Integer
catalogPath
(只读)

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

String
compressionType
(只读)

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
(只读)

The extent of the referenced raster dataset.

Extent
format
(只读)

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
(可读写)

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

Boolean
height
(只读)

The number of rows.

Integer
isInteger
(只读)

The integer state: True if the raster dataset has integer type.

Boolean
isTemporary
(只读)

The state of the referenced raster dataset: True if the raster dataset is temporary or False if permanent.

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
name
(只读)

The name of the referenced raster dataset.

String
noDataValue
(只读)

The NoData value of the referenced raster dataset.

Double
path
(只读)

The full path and name of the referenced raster dataset.

String
pixelType
(只读)

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

  • 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
spatialReference
(只读)

The spatial reference of the referenced raster dataset.

SpatialReference
standardDeviation
(只读)

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

Double
uncompressedSize
(只读)

The size of the referenced raster dataset on disk.

Double
width
(只读)

The number of columns.

Integer

方法概述

方法说明
save ({name})

Permanently saves the dataset the raster object references.

方法

save ({name})
参数说明数据类型
name

The name to assign to the raster dataset on disk.

String

代码示例

Raster example 1

Creates a Raster object from a raster dataset and gets properties for analysis.

import arcpy
myRaster = arcpy.Raster('elevation')
myMin = myRaster.minimum
myMax = myRaster.maximum
myArea = (myRaster.width * myRaster.height) * myRaster.meanCellWidth
Raster example 2

Creates a Raster object, gets properties, creates a random error raster (+/- 3 feet), adds it to an elevation raster, and convert its units from feet to meters.

import arcpy
from arcpy.sa import *
elevRaster = Raster('C:/data/elevation')
myExtent = elevRaster.extent
myCellsize = (elevRaster.meanCellHeight + elevRaster.meanCellWidth) / 2
res01 = arcpy.CreateRandomRaster_management("","error3","UNIFORM 0.0 3.0",myExtent, myCellsize)
elev_meters = (elevRaster + Raster(res01)) * 0.3048
elev_meters.save("C:/output/fgdb.gdb/elevM_err")

7/10/2012