Skip to main content

RasterInfo

汇总

定义一个 RasterInfo 对象,该对象将描述一组栅格属性,以利于使用 Raster 类创建栅格数据集。

讨论

RasterInfo 对象可以通过从 RasterInfo 类中进行实例化,或调用 Raster 对象的 getRasterInfo 方法来创建。 当 RasterInfo 对象通过 Raster 对象创建时,其属性使用 Raster 对象的属性进行初始化。

RasterInfo 对象可用作 Raster 类的输入以创建栅格数据集,该栅格数据集的像元可以迭代且可使用 RasterCellIterator 对象分配值。

语法

RasterInfo()

方法

fromJSONString(json)

从 JSON 字符串加载属性。

名称 说明 数据类型

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

将返回 RasterInfo 对象的波段计数属性。

返回值

数据类型 说明

Integer

波段计数。

getBlockHeight()

将返回 RasterInfo 对象的块高度属性。

返回值

数据类型 说明

Integer

块高度。

getBlockWidth()

将返回 RasterInfo 对象的块宽度属性。

返回值

数据类型 说明

Integer

块宽度。

getCellSize()

返回 RasterInfo 对象的像元大小属性。

返回值

数据类型 说明

tuple

一个元组,其第一个元素代表平均像元宽度,第二个元素代表平均像元高度。

getExtent()

将返回 RasterInfo 对象的范围属性。

返回值

数据类型 说明

Extent

栅格范围。

getNoDataValues()

将返回 RasterInfo 对象的 NoData 值属性。

返回值

数据类型 说明

Variant

代表栅格 NoData 值的数值(整型或浮点型)或元组。

如果波段计数为 1,则将返回一个数字。 如果波段计数大于 1,则将返回一个元组,其中每个元素代表相应波段的 NoData 值。

getPixelType()

将返回 RasterInfo 对象的像素类型属性。

返回值

数据类型 说明

String

像素类型。

getSpatialReference()

返回 RasterInfo 对象的空间参考信息。

返回值

数据类型 说明

SpatialReference

SpatialReference 对象表示栅格的空间参考。

setBandCount(band_count)

设置波段计数属性。

名称 说明 数据类型

band_count

The band count.

Integer

setBlockHeight(block_height)

设置块高度属性。

名称 说明 数据类型

block_height

The block height.

Integer

setBlockWidth(block_width)

设置块宽度属性。

名称 说明 数据类型

block_width

The block width.

Integer

setCellSize(cell_size)

设置像元大小属性。

名称 说明 数据类型

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)

设置范围属性。

名称 说明 数据类型

extent

The extent.

Extent

setNoDataValues(nodata_values)

设置 NoData 值属性。

名称 说明 数据类型

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)

设置像素类型属性。

名称 说明 数据类型

pixel_type

Specifies the pixel type.

  • U1—The pixel type is unsigned 1-bit integer.

  • U2—The pixel type is unsigned 2-bit integer.

  • U4—The pixel type is unsigned 4-bit integer.

  • S8—The pixel type is signed 8-bit integer.

  • U8—The pixel type is unsigned 8-bit integer.

  • S16— The pixel type is signed 16-bit integer.

  • U16— The pixel type is unsigned 16-bit integer.

  • S32—The pixel type is signed 32-bit integer.

  • U32—The pixel type is unsigned 32-bit integer.

  • F32—The pixel type is 32-bit floating point.

  • F64—The pixel type is 64-bit double.

String

setSpatialReference(spatial_reference)

设置空间参考属性。

名称 说明 数据类型

spatial_reference

The spatial reference.

SpatialReference

toJSONString()

返回 RasterInfo 对象的 JSON 表达。

返回值

数据类型 说明

String

表示 RasterInfo 对象的 JSON 字符串。

代码示例

栅格信息示例 1

RasterInfo 类创建 RasterInfo 对象,并用它来创建栅格数据集。

# 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")
栅格信息示例 2

Raster 对象创建 RasterInfo 对象,并用它来创建栅格数据集。

# 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")