摘要
定义一个 RasterInfo 对象,该对象将描述一组栅格属性,以利于使用 Raster 类创建栅格数据集。
说明
RasterInfo 对象可以通过从 RasterInfo 类中进行实例化,或调用 Raster 对象的 getRasterInfo 方法来创建。 当 RasterInfo 对象通过 Raster 对象创建时,其属性使用 Raster 对象的属性进行初始化。
RasterInfo 对象可用作 Raster 类的输入以创建栅格数据集,该栅格数据集的像元可以迭代且可使用 RasterCellIterator 对象分配值。
语法
RasterInfo ()
方法概述
| 方法 | 说明 |
| fromJSONString (json) | 从 JSON 字符串加载属性。 |
| getBandCount () | 将返回 RasterInfo 对象的波段计数属性。 |
| getBlockHeight () | 将返回 RasterInfo 对象的块高度属性。 |
| getBlockWidth () | 将返回 RasterInfo 对象的块宽度属性。 |
| getCellSize () | 返回 RasterInfo 对象的像元大小属性。 |
| getExtent () | 将返回 RasterInfo 对象的范围属性。 |
| getNoDataValues () | 将返回 RasterInfo 对象的 NoData 值属性。 |
| getPixelType () | 将返回 RasterInfo 对象的像素类型属性。 |
| getSpatialReference () | 返回 RasterInfo 对象的空间参考信息。 |
| setBandCount (band_count) | 设置波段计数属性。 |
| setBlockHeight (block_height) | 设置块高度属性。 |
| setBlockWidth (block_width) | 设置块宽度属性。 |
| setCellSize (cell_size) | 设置像元大小属性。 |
| setExtent (extent) | 设置范围属性。 |
| setNoDataValues (nodata_values) | 设置 NoData 值属性。 |
| setPixelType (pixel_type) | 设置像素类型属性。 |
| setSpatialReference (spatial_reference) | 设置空间参考属性。 |
| toJSONString () | 返回 RasterInfo 对象的 JSON 表达。 |
方法
fromJSONString (json)
| 参数 | 说明 | 数据类型 |
json | The input JSON string that will be loaded. An input JSON string example: | String |
getBandCount ()
| 数据类型 | 说明 |
| Integer | 波段计数。 |
getBlockHeight ()
| 数据类型 | 说明 |
| Integer | 块高度。 |
getBlockWidth ()
| 数据类型 | 说明 |
| Integer | 块宽度。 |
getCellSize ()
| 数据类型 | 说明 |
| tuple | 一个元组,其第一个元素代表平均像元宽度,第二个元素代表平均像元高度。 |
getExtent ()
| 数据类型 | 说明 |
| Extent | 栅格范围。 |
getNoDataValues ()
| 数据类型 | 说明 |
| Variant | 代表栅格 NoData 值的数值(整型或浮点型)或元组。 如果波段计数为 1,则将返回一个数字。 如果波段计数大于 1,则将返回一个元组,其中每个元素代表相应波段的 NoData 值。 |
getPixelType ()
| 数据类型 | 说明 |
| String | 像素类型。 |
getSpatialReference ()
| 数据类型 | 说明 |
| 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_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.
| String |
setSpatialReference (spatial_reference)
| 参数 | 说明 | 数据类型 |
spatial_reference | The spatial reference. | SpatialReference |
toJSONString ()
| 数据类型 | 说明 |
| String | 表示 RasterInfo 对象的 JSON 字符串。 |
代码示例
从 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")从 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")