摘要
定义一个 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 | 将进行加载的输入 JSON 字符串。 输入 JSON 字符串示例: | String |
getBandCount ()
| 数据类型 | 说明 |
| Integer | 波段计数。 |
getBlockHeight ()
| 数据类型 | 说明 |
| Integer | 块高度。 |
getBlockWidth ()
| 数据类型 | 说明 |
| Integer | 块宽度。 |
getCellSize ()
| 数据类型 | 说明 |
| tuple | 一个元组,其第一个元素代表平均像元宽度,第二个元素代表平均像元高度。 |
getExtent ()
| 数据类型 | 说明 |
| Extent | 栅格范围。 |
getNoDataValues ()
| 数据类型 | 说明 |
| Variant | 代表栅格 NoData 值的数值(整型或浮点型)或元组。 如果波段计数为 1,则 getNoDataValues 将返回一个数值。如果波段计数大于 1,则 getNoDataValues 将返回一个元组,其中每个元素代表相应波段的 NoData 值。 |
getPixelType ()
| 数据类型 | 说明 |
| String | 像素类型。 |
getSpatialReference ()
| 数据类型 | 说明 |
| SpatialReference | 此 SpatialReference 对象代表栅格的空间参考。 |
setBandCount (band_count)
| 参数 | 说明 | 数据类型 |
band_count | 波段计数。 | Integer |
setBlockHeight (block_height)
| 参数 | 说明 | 数据类型 |
block_height | 块高度。 | Integer |
setBlockWidth (block_width)
| 参数 | 说明 | 数据类型 |
block_width | 块宽度。 | Integer |
setCellSize (cell_size)
| 参数 | 说明 | 数据类型 |
cell_size | 像元大小。元组的第一个元素表示像元宽度,第二个元素表示像元高度。 | tuple |
setExtent (extent)
| 参数 | 说明 | 数据类型 |
extent | 范围。 | Extent |
setNoDataValues (nodata_values)
| 参数 | 说明 | 数据类型 |
nodata_values | 指定 NoData 值的数字或元组。 如果已指定数字,则其将用作所有波段的 NoData 值。如果已指定元组,则该元组中的每个元素都将被视为对应波段的 NoData 值。元组中的元素数必须与波段计数相匹配。 | Variant |
setPixelType (pixel_type)
| 参数 | 说明 | 数据类型 |
pixel_type | 像素类型(例如 S32 或 F32)。
| String |
setSpatialReference (spatial_reference)
| 参数 | 说明 | 数据类型 |
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")