Raster

摘要

创建可在 Python地图代数表达式中使用的栅格对象。 栅格对象是一个引用栅格数据集的变量。

通过提供指向磁盘上某一现有栅格的路径或提供 RasterInfo 对象,可以创建栅格对象,此外,栅格也可以是任意可生成栅格输出的地图代数语句的结果。

许可:

运行地图代数语句需要 ArcGIS Spatial Analyst 扩展模块ArcGIS Image Analyst 扩展模块。

说明

根据现有数据创建的栅格对象可用于后续的地图代数表达式中,并且将拥有所有关联的栅格属性和方法。

# out_raster is a resultant raster object
out_raster = Raster("c:/data/inraster")

任何在等号左侧生成输出栅格的工具或运算符(请参阅在地图代数中使用运算符)均可创建栅格对象。 例如,在以下表达式中,out_raster 是一个栅格对象。

out_raster = Slope("inelevation")

默认情况下,通过地图代数表达式返回的 Raster 对象(变量和相关数据集)是临时对象。

通过调用栅格对象的 save 方法,可将与栅格对象关联的临时数据集转变为永久数据集。

如果未对引用的栅格做永久化处理,则当变量超出范围时(如独立脚本完成或 ArcGIS 关闭时),将删除该变量和引用的栅格数据集。 当栅格对象引用磁盘上的永久数据时,则不会删除该数据。

某些运算符同时存在于地图代数和 Python 中。 如果要使用运算符处理栅格数据(而非标量),则必须通过调用 Raster 类的构造函数 Raster("inRaster") 将输入栅格转换为栅格对象。

# The plus operator (available with Spatial Analyst or Image Analyst) is
# used on the input rasters to create 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 combination of rasters with numbers, the Spatial Analyst
# operator is used, creating an output raster object
out_raster = Raster("input") + 10

与栅格对象关联的某些属性仅在引用的栅格数据集为永久性时才可用。 当引用的栅格数据集为临时数据集时,为这些属性分配的值将为 None。 受影响的属性包括 catalogPathcompressionTypeformathasRATnamepath

将引用的栅格数据集设置成永久数据集后,它将无法返回到临时状态。

通过提供磁盘上现有栅格的路径来创建栅格对象时,默认情况下其 readOnly 属性为 True,且其像元值可以使用 [row, column] 索引符号读取。

in_raster = Raster('c:/data/inraster')

# Read the cell value at the second row and third column
v = in_raster[1, 2]

通过提供 RasterInfo 对象作为输入来创建栅格对象时,它将在 ArcGIS 临时目录中创建一个临时栅格。 默认情况下,此类栅格对象的 readOnly 属性是 False,其像元值可以使用 [row, column] 索引符号进行修改。

in_raster = Raster('c:/data/inraster')
raster_info = in_raster.getRasterInfo()
new_raster = Raster(raster_info)  # Create a new raster

# Modify the cell value at the second row and third column
new_raster[1, 2] = 3
new_raster.save('c:/output/outraster1')

RasterCellIterator 循环中,Raster 对象用于使用 [row, column] 索引表示法在像元级别下读取和写入数据。

语法

 Raster (inRaster, {is_multidimensional})
参数说明数据类型
inRaster
[inRaster,...]

输入栅格数据集或栅格数据集列表。

当提供多个多维栅格数据集时,文件将被解释为单个多维数据集,且变量和维度将合并到一起。如果两个文件包含维度值相同的相同变量,则输出栅格中的剖切将来自列表中的第一个多维栅格。

您还可以指定一个 RasterInfo 对象作为输入 inRaster,这将在磁盘上创建新栅格数据集。在这种情况下,将忽略 is_multidimensional 参数。

Raster
is_multidimensional

确定输入栅格是否将被视为多维。如果输入为多维,并应该作为多维处理,请指定 True,此选项将对数据集中的每个剖切进行处理。如果输入非多维,或者是多维但不应作为多维处理,请指定 False

(默认值为 False)

Boolean

属性

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

参考栅格数据集中的波段数。

Integer
bandNames
(只读)

参考栅格数据集中的波段名称。

String
blockSize
(只读)

参考栅格数据集的块大小。

tuple
catalogPath
(只读)

参考栅格数据集的完整路径和名称。

String
catalogPaths
(只读)

镶嵌数据集包含的每个项目的完整路径和名称。

String
compressionType
(只读)

指定压缩类型。 以下是可用的类型:

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

String
extent
(只读)

参考栅格数据集的范围。

Extent
format
(只读)

指定栅格格式。

  • BIL - Esri 波段按行交叉格式文件
  • BIP - Esri 波段按像元交叉格式文件
  • BMP - 位图图形栅格数据集格式
  • BSQ - Esri 波段顺序格式文件
  • DAT - ENVI DAT 文件
  • GIF - 栅格数据集的图形交换格式
  • Grid - Esri Grid 栅格数据集格式
  • IMAGINE 图像 - ERDAS IMAGINE 栅格数据格式
  • JP2000 - JPEG 2000 栅格数据集格式
  • JPEG - 联合图像专家组栅格数据集格式
  • PNG - 可移植网络图形栅格数据集格式
  • TIFF - 栅格数据集的标记图像文件格式

String
functions
(只读)

使用 rft.xml 文件的路径调用栅格函数模板。 可通过 Apply 函数使用调用的模板处理栅格。

String
hasRAT
(只读)

指定是否存在关联属性表:如果存在,则为 True;如果不存在,则为 False

Boolean
hasTranspose
(可读写)

指定是否存在与栅格相关联的多维数据的转置版本:如果存在,则为 True;如果不存在,则为 False

Boolean
height
(只读)

行数。

Integer
isInteger
(只读)

指定栅格数据集是否具有整型。 如果栅格数据集具有整型,则为 True

Boolean
isMultidimensional
(只读)

指定栅格数据集是否为多维。 如果栅格数据集为多维,则为 True

Boolean
isTemporary
(只读)

如果栅格数据集是临时的 (True),还是永久的 (False)。

Boolean
maximum
(只读)

参考栅格数据集中的最大值。

Double
mean
(只读)

参考栅格数据集中的平均值。

Double
meanCellHeight
(只读)

y 方向上的像元大小。

Double
meanCellWidth
(只读)

x 方向上的像元大小。

Double
minimum
(只读)

参考栅格数据集中的最小值。

Double
mdinfo
(只读)

栅格数据集的多维信息,包括变量名称、描述和单位以及维度名称、单位、间隔和范围。 例如,包含 10 个月以上月度温度数据的多维栅格将返回以下内容:{"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}

如果栅格不是多维栅格,则此属性返回 None

String
name
(只读)

参考栅格数据集的名称。

String
names
(只读)

镶嵌数据集包含的每个项目的名称。

String
noDataValue
(只读)

参考栅格数据集中的 NoData 值。

Double
noDataValues
(只读)

参考多波段栅格数据集中每个波段的 NoData 值。

tuple
path
(只读)

参考栅格数据集的完整路径。

String
pixelType
(只读)

指定参考栅格数据集的像素类型。 类型如下:

  • U1 - 1 位
  • U2 - 2 位
  • U4 - 4 位
  • U8 - 8 位无符号整型
  • S8 - 8 位整型
  • U16 - 16 位无符号整型
  • S16 - 16 位整型
  • U32 - 32 位无符号整型
  • S32 - 32 位整型
  • F32 - 单精度浮点型
  • F64 - 双精度浮点型

String
properties
(只读)

参考栅格数据集中的属性名称和值对。

Dictionary
RAT
(只读)

参考栅格数据集的属性表。 例如,具有两个类的栅格数据集的属性表将返回 {'OID': [0, 1], 'Value': [10, 20], 'ClassName': ['Low', 'High'], 'Red': [178, 56], 'Green': [178, 168], 'Blue': [178, 0], 'Alpha': [255, 255], 'Count': [887412.0, 962159.0]}。 如果栅格为多维栅格,则数据集中的每个剖切片都会有一个 Count 字段。

如果不存在属性表,则将返回 None

Dictionary
readOnly
(可读写)

指定栅格像元值是否可使用 [行, 列] 记法进行写入。 当此属性为 True 时,它们不可写入。 如果为 False,则其可写入。

Boolean
slices
(只读)

每个剖切的属性信息(包括其变量名称、维度名称和维度值),以词典列表形式返回。 例如,包含超过 24 个月的温度数据的多维栅格将返回以下内容:[{'variable': 'temp', 'StdTime': '2017-1-15'}, {'variable': 'temp', 'StdTime': '2017-2-15'}, .....{'variable': 'temp', 'StdTime': '2018-12-15'}]

String
spatialReference
(只读)

指定导出图像的空间参考。 支持的选项如下:

  • None
  • SpatialReference 数据类型
  • ICSICS:<object_id>,其中 object_id 值用于提供将使用其图像坐标系的特定栅格。
如果未指定任何值,则将使用栅格数据集的空间参考。

SpatialReference
standardDeviation
(只读)

参考栅格数据集中值的标准偏差。

Double
sum
(只读)

参考栅格数据集中值的总和。

Double
uncompressedSize
(只读)

磁盘上参考栅格数据集的大小。

Double
variables
(只读)

多维栅格数据集中的变量名称及其维度。 例如,包含超过 24 个月的温度数据的多维栅格将返回 ['temp(StdTime=24)']

String
variableNames
(只读)

多维栅格数据集中的变量名称。

String
width
(只读)

列数。

Integer

方法概述

方法说明
addDimension (variable, new_dimension_name, dimension_value, {dimension_attributes})

向多维栅格对象中的变量添加新维度,以便多维栅格可以与其他多维数据集兼容。

appendSlices (mdRaster)

从另一个多维栅格追加剖切片。

computeGSD (locations, spatial_reference, {dem})

返回输入影像的地面采样距离 (GSD) x 和 y 值。

computeHistograms ({variable}, {aoi}, {cellsize})

返回栅格的直方图。 如果栅格为多维栅格,则其将返回变量的直方图。

computeStatistics ({variable}, {aoi}, {cellsize})

返回栅格的统计数据。 如果栅格为多维栅格,则返回变量的统计数据。

exportImage ({width}, {height}, {format}, {extent}, {spatial_reference}, {mosaic_rule})

将栅格对象导出为 IPython Image 对象,以在 Jupyter Notebook 中进行可视化。

fromSTACItem (stac_item, {request_params})

时空资产目录 (STAC) 项目创建一个 Raster 对象。

getColormap ({variable_name})

返回栅格的色彩映射表。如果栅格为多维栅格,则返回变量的色彩映射表。

getDimensionAttributes (variable_name, dimension_name)

返回多维栅格数据集中特定变量的维度属性信息(例如,描述、单位等)。

getDimensionNames (variable_name)

返回与多维栅格数据集中的变量相关联的维度名称。

getDimensionValues (variable_name, dimension_name)

返回与多维栅格数据集中变量关联的维度的值。

getHistograms ({variable_name})

用于返回栅格的直方图。如果栅格为多维栅格,则其将返回变量的直方图。如果栅格为多波段栅格,则其将返回每个波段的直方图。

getProperty (property_name)

返回给定属性的值。

getRasterBands ({band_ids_or_names})

针对在多波段栅格数据集中指定的每个波段返回一个 Raster 对象。

getRasterInfo ()

返回一个 RasterInfo 对象,该对象将使用栅格对象属性初始化其属性。

getStatistics ({variable_name})

返回栅格的统计数据。如果栅格为多维栅格,则返回变量的统计数据。

getVariableAttributes (variable_name)

返回多维栅格数据集中变量的属性信息(例如,描述、单位等)。

isConstant (constantValue)

确定栅格是否仅包含常量值。

read ({upper_left_corner}, {origin_coordinate}, {ncols}, {nrows}, {nodata_to_value}, {cell_size})

读取栅格并将栅格转换为 NumPy 数组。

removeVariables (variable_names)

从云栅格格式 (CRF) 多维栅格数据集中移除一个变量或变量列表。

renameBand (current_band_name_or_index, new_band_name)

重命名多波段栅格数据集中的波段。

renameVariable (current_variable_name, new_variable_name)

重命名云栅格格式 (CRF) 多维栅格数据集中的变量。

save ({name})

永久保存栅格对象引用的数据集。

setColormap (color_map, {variable_name})

设置栅格的色彩映射表。如果栅格为多维栅格,则其将返回变量的色彩映射表。

setHistograms (histogram_obj, {variable_name})

用于设置栅格的直方图。如果栅格为多维栅格,则其将设置变量的直方图。

setProperty (property_name, property_value)

将自定义属性添加到栅格数据集。

如果属性名称已存在,则将覆盖现有属性值。

setStatistics (statistics_obj, {variable_name})

用于设置栅格的统计数据。如果栅格为多波段栅格,则其将设置每个波段的统计数据。如果栅格为多维栅格,则其将设置变量的统计数据。

setVariableAttributes (variable_name, variable_attributes)

用于设置多维栅格数据集中变量的属性信息(例如,描述、单位等)。

write (array, {upper_left_corner}, {origin_coordinate}, {value_to_nodata})

将三维或四维 NumPy 数组转换为栅格。

方法

addDimension (variable, new_dimension_name, dimension_value, {dimension_attributes})
参数说明数据类型
variable

要添加维度的变量名称。仅支持云栅格式 (.crf) 的多维栅格。

String
new_dimension_name

新维度的名称。

String
dimension_value

分配给新维度的值。

只能添加一个值,因为多个值(例如,多个深度)可能需要在数据集中添加新切片。要添加多个维度值与新切片,请使用 addDimension 方法,然后使用 Merge 函数将现有数据与栅格对象合并。

Double
dimension_attributes

Python 字典,其中包含要添加到新维度的属性信息,例如描述或单位。例如,要添加单位属性,请使用 {"unit": "meters"}

(默认值为 None)

Dictionary
返回值
数据类型说明
String

变量名称列表和多维栅格的相应尺寸。

appendSlices (mdRaster)
参数说明数据类型
mdRaster

包含要追加的剖切片的多维栅格。

该栅格必须与目标栅格具有维度名称相同的相同变量。像元大小、范围和空间参照系也必须匹配。

此栅格中的剖切片所针对的必须是遵循目标栅格中剖切片维度值的维度值。

如果变量具有两个维度,则系统将沿一个维度追加剖切片。另一个维度的剖切片数必须与目标栅格中维度的剖切片数相同。例如,如果盐度变量包含时间和深度维度上的剖切片,则可将时间片追加到其他盐度多维栅格,但前提是两个栅格中存在数量相同的深度剖切片。

Raster
返回值
数据类型说明
String

包含多维栅格中变量名称和关联维度的字符串。例如,如果生成的栅格具有 10 个带有降水量数据的时间片,则该栅格将返回 'prcp(StdTime=10)'

computeGSD (locations, spatial_reference, {dem})
参数说明数据类型
locations
[locations,...]

A list of x,y-coordinates.

List
spatial_reference

The spatial reference of the input locations. For example, the spatial reference can be specified using the following format: WGS_1984_UTM_Zone_11N.

(默认值为 None)

String
dem

The DEM to be used in the GSD computation.

(默认值为 None)

String
返回值
数据类型说明
String

地面采样距离值的列表。

computeHistograms ({variable}, {aoi}, {cellsize})
参数说明数据类型
variable

The variable name for the multidimensional dataset. If a variable is not specified and the raster is multidimensional, the histogram of all variables will be calculated.

String
aoi
[aoi,...]

The area of interest to calculate statistics for. This can be provided as Polygon object or a list of coordinates in the raster's spatial reference system in the form of [min_x, min_y, max_x, max_y].

List
cellsize

The cell size to calculate statistics from. The raster will be resampled to the specified cell size before statistics are calculated.

If no value is specified, the cell size of the raster will be used.

Double
返回值
数据类型说明
Dictionary

包含栅格或变量直方图的字典列表。 例如,如果计算了单一波段或变量的直方图,则将按以下格式返回输出:[{'size': 251, 'min': -0.5, 'max': 250.5, 'counts': [814.0, 894.0, 836.0, 902.0, 1317.0, 1263.0, 1360.0]}]

computeStatistics ({variable}, {aoi}, {cellsize})
参数说明数据类型
variable

The variable name of the multidimensional dataset. If a variable is not provided and the raster is multidimensional, the histogram of all variables will be calculated.

String
aoi
[aoi,...]

The area of interest that will be used to calculate statistics. This can be provided as a Polygon object or a list of coordinates in the raster's spatial reference system in the form of [min_x, min_y, max_x, max_y].

List
cellsize

The cell size that will be used to calculate statistics. The raster will be resampled to the specified cell size before statistics are calculated.

If no value is specified, the cell size of the raster will be used.

Double
返回值
数据类型说明
Dictionary

包含栅格或变量统计数据的字典列表。 例如,如果计算了单一波段或变量的统计数据,则将按以下格式返回输出:[{'min': 0.0, 'max': 250.0, 'mean': 114.60855843925984, 'sum': 51931430.0, 'standardDeviation': 97.18526137567137, 'median': 78.0, 'mode': 250.0, 'skipX': 1, 'skipY': 1, 'count': 453120.0, 'covariances': '0.000000'}]

exportImage ({width}, {height}, {format}, {extent}, {spatial_reference}, {mosaic_rule})
参数说明数据类型
width

The width of the output image in pixels. If a value is not specified, but the height is provided, the aspect ratio of the original raster will be maintained. If neither width nor height are specified, the width of the original raster dataset is used.

(默认值为 None)

Integer
height

The height of the output image in pixels. If a value is not specified, but the width is provided, the aspect ratio of the original raster will be maintained. If neither width nor height are specified, the height of the original raster dataset is used.

(默认值为 None)

Integer
format

The image format of the exported data. The supported formats include JPG, PNG, and PNG32.

(默认值为 PNG32)

String
extent

The extent or bounding box of the exported image. If a value is not specified, the extent of the raster dataset is used.

(默认值为 None)

Extent
spatial_reference

The spatial reference of the exported image. Supported options include the following:

  • None
  • SpatialReference data type
  • ICS or ICS:<object_id>, where object_id selects the specific raster whose image coordinate system should be used.
If a value is not specified, the spatial reference of the raster dataset is used.

(默认值为 None)

SpatialReference
mosaic_rule

Specifies how the input raster data should be mosaicked. This is applicable when the input raster dataset is a mosaic dataset. For information on how to format the mosaic rule, see Mosaic rule objects.

(默认值为 None)

Dictionary
返回值
数据类型说明
Object

作为 IPython Image 对象的导出图像。

fromSTACItem (stac_item, {request_params})
参数说明数据类型
stac_item

The URL of the STAC item or a pystac.Item object. The URL can be a static STAC item URL or a STAC API item URL, for example, "https://planetarycomputer.microsoft.com/api/stac/v1/collections/naip/items/tx_m_2609719_se_14_060_20201217".

  • https://planetarycomputer.microsoft.com/api/stac/v1—The following collections are supported: daymet-annual-pr, daymet-daily-hi, 3dep-seamless, 3dep-lidar-dsm, sentinel-1-rtc, gridmet, daymet-annual-na, daymet-monthly-na, daymet-annual-hi, daymet-monthly-hi, daymet-monthly-pr, hgb, cop-dem-glo-30, cop-dem-glo-90, terraclimate, gnatsgo-rasters, 3dep-lidar-hag, 3dep-lidar-intensity, 3dep-lidar-pointsourceid, mtbs, noaa-c-cap, alos-fnf-mosaic, 3dep-lidar-returns, mobi, landsat-c2-l2, chloris-biomass, daymet-daily-pr, 3dep-lidar-dtm-native, 3dep-lidar-classification, 3dep-lidar-dtm, gap, alos-dem, jrc-gsw, hrea, sentinel-2-l2a, daymet-daily-na, nrcan-landcover, ecmwf-forecast, noaa-mrms-qpe-24h-pass2, sentinel-1-grd, nasadem, io-lulc, landsat-c2-l1, drcog-lulc, chesapeake-lc-7, chesapeake-lc-13, chesapeake-lu, noaa-mrms-qpe-1h-pass1, noaa-mrms-qpe-1h-pass2, noaa-nclimgrid-monthly, usda-cdl, esa-cci-lc, esa-cci-lc-netcdf, noaa-climate-normals-netcdf, noaa-climate-normals-gridded, io-lulc-9-class, io-biodiversity, naip, noaa-cdr-sea-surface-temperature-whoi, noaa-cdr-ocean-heat-content, noaa-cdr-sea-surface-temperature-whoi-netcdf, sentinel-3-olci-wfr-l2-netcdf, noaa-cdr-ocean-heat-content-netcdf, sentinel-3-synergy-v10-l2-netcdf, sentinel-3-olci-lfr-l2-netcdf, sentinel-3-slstr-lst-l2-netcdf, sentinel-3-slstr-wst-l2-netcdf, sentinel-3-synergy-syn-l2-netcdf, sentinel-3-synergy-vgp-l2-netcdf, sentinel-3-synergy-vg1-l2-netcdf, and esa-worldcover.

  • https://earth-search.aws.element84.com/v0—All collections are supported.
  • https://earth-search.aws.element84.com/v1—All collections are supported.
  • https://services.sentinel-hub.com/api/v1/catalog—All collections are supported.
String
request_params

The STAC item request properties. These are therequests.get() method parameters and values in dictionary format.

This parameter is honored when the stac_item parameter is a URL.

{
"verify": False,
"headers": {"Authorization": "Bearer access_token_string"}
}
Dictionary
返回值
数据类型说明
Raster

返回该类的一个新实例。

getColormap ({variable_name})
参数说明数据类型
variable_name

多维栅格数据集的变量名称。如果未指定变量且栅格为多维栅格,则系统将返回第一个变量的色彩映射表。

String
返回值
数据类型说明
Dictionary

包含栅格或变量的色彩映射表的 Python 字典。将首先列出像素值,然后以十六进制颜色代码列出相应的色彩映射表值,例如 {'type': 'RasterColormap', 'values': [10, 20, 30], 'colors': ['#66FF33', '#0033CC', '#FF00FF']}

getDimensionAttributes (variable_name, dimension_name)
参数说明数据类型
variable_name

多维栅格数据集的变量名称。

String
dimension_name

多维栅格数据集的维度名称。

String
返回值
数据类型说明
String

维度的属性信息,例如,最小维度值、最大维度值、时间步长间隔和间隔单位。

getDimensionNames (variable_name)
参数说明数据类型
variable_name

多维栅格数据集的变量名称。

String
返回值
数据类型说明
String

与变量关联的维度名称。

getDimensionValues (variable_name, dimension_name)
参数说明数据类型
variable_name

多维栅格数据集的变量名称。

String
dimension_name

多维栅格数据集的维度名称。

String
返回值
数据类型说明
String

变量的维度值。

getHistograms ({variable_name})
参数说明数据类型
variable_name

多维栅格数据集的变量名称。如果未指定变量且栅格为多维栅格,则系统将返回第一个变量的直方图。

String
返回值
数据类型说明
Dictionary

栅格或变量的直方图值,例如 [{'size': 10, 'min': 0.0, 'max': 364.0, 'counts': [882.0, 18.0, 9.0, 0.0, 9.0, 0.0, 18.0, 9.0, 18.0, 0.0]}]

getProperty (property_name)
参数说明数据类型
property_name

栅格数据集的属性名称。

String
返回值
数据类型说明
String

属性值。

getRasterBands ({band_ids_or_names})
参数说明数据类型
band_ids_or_names
[band_ids_or_names,...]

要返回为 Raster 对象的波段的索引号或名称。如果未指定,则将提取所有波段。

(默认值为 None)

String
返回值
数据类型说明
Raster

指定的每个波段的 Raster 对象。

getRasterInfo ()
返回值
数据类型说明
Object

RasterInfo 对象。

getStatistics ({variable_name})
参数说明数据类型
variable_name

多维栅格数据集的变量名称。如果未指定变量且栅格为多维栅格,则系统将返回第一个变量的统计数据。

String
返回值
数据类型说明
Dictionary

栅格或变量的统计数据。

getVariableAttributes (variable_name)
参数说明数据类型
variable_name

多维栅格数据集的变量名称。

String
返回值
数据类型说明
String

变量的属性信息。

isConstant (constantValue)
参数说明数据类型
constantValue

The value to evaluate for in the raster.

Double
返回值
数据类型说明
Boolean

此布尔值表示栅格是否仅包含常量值。

read ({upper_left_corner}, {origin_coordinate}, {ncols}, {nrows}, {nodata_to_value}, {cell_size})
参数说明数据类型
upper_left_corner

可从中提取处理块以转换为数组的与 origin_coordinate 相关的坐标。应将其格式化为一个元组,其中含有分别表示在 x 和 y 方向上移动的方向的两个值。例如,值 (2,0) 表示应从 x 方向上与 origin_coordinate 相距两个像素的像素处开始提取数组。

如果未指定任何值,则使用 (0,0)。

(默认值为 None)

tuple
origin_coordinate

可从 Raster 对象中的原点提取处理块以转换为数组。坐标必须以栅格单位表示。

若未指定值,则将使用栅格的原点。

(默认值为 None)

Point
ncols

Raster 对象中要转换为 NumPy 数组的 upper_left_corner 中的列数。

若未指定值,则将使用栅格的列数。

(默认值为 None)

Integer
nrows

Raster 对象中要转换为 NumPy 数组的 upper_left_corner 中的行数。

若未指定值,则将使用栅格的行数。

(默认值为 None)

Integer
nodata_to_value

NumPy 数组中为 Raster 对象中标记为 NoData 的那些像素分配的像素值。

若未指定值,则将使用栅格的 NoData 值。

(默认值为 None)

Variant
cell_size

NumPy 数组中使用的像元大小。应将其格式化为一个元组,其中的两个值分别表示 x 和 y 方向上的像元大小,且单位应与栅格所使用的单位相匹配。例如,值 (2, 1) 表示输出像元大小在 x 方向上应为 2个单位,在 y 方向上应为 1 个单位。如果像元大小与数据源不同,则使用双线性插值法对像元值进行重采样。

若未指定值,则将使用栅格的像元大小。

(默认值为 None)

tuple
返回值
数据类型说明
NumPyArray

输出的 NumPy 数组。

如果栅格是单波段或多波段栅格,则数组的维度将为行、列和波段数。

如果栅格是多维栅格,则数组的维度将为剖切、行、列数以及波段数。

removeVariables (variable_names)
参数说明数据类型
variable_names
[variable_names,...]

要从多维栅格数据集中移除的变量名称或变量名称列表。

String
renameBand (current_band_name_or_index, new_band_name)
参数说明数据类型
current_band_name_or_index

待重命名的波段的名称或索引。波段索引从 1 开始。此参数可以为字符串或整数值。

String
new_band_name

新波段名称。

String
返回值
数据类型说明
Raster

具有重命名的波段的 Raster 对象。

renameVariable (current_variable_name, new_variable_name)
参数说明数据类型
current_variable_name

多维栅格数据集中变量的当前名称。

String
new_variable_name

多维栅格数据集中变量的新名称。

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

分配给磁盘上的栅格数据集的名称。

此方法支持将多维栅格数据集保存为云栅格格式 (CRF)。

String
setColormap (color_map, {variable_name})
参数说明数据类型
color_map

要应用于栅格的色彩映射表。这可以是一个字符串,用于指示色彩映射表的名称或者要使用的色彩映射表,例如,分别为 NDVIYellow To Red。这也可以是具有自定义色彩映射表或色彩映射表对象的 Python 字典,例如,自定义色彩映射表 {'values': [0, 1, 2, 3, 4, 5], 'colors': ['#000000', '#DCFFDF', '#B8FFBE', '#85FF90', '#50FF60','#00AB10']} 或自定义色彩映射表 {"type": "algorithmic", "fromColor": [115, 76, 0, 255],"toColor": [255, 25, 86, 255], "algorithm": "esriHSVAlgorithm"}

String
variable_name

多维栅格数据集的变量名称。如果未指定变量且栅格为多维栅格,则系统将设置第一个变量的色彩映射表。

String
setHistograms (histogram_obj, {variable_name})
参数说明数据类型
histogram_obj
[histogram_obj,...]

包含要设置的直方图信息的 Python 字典列表,例如 [{'size': 5, 'min': 19.0, 'max': 42.0, 'counts': [275, 17, 3065, 4, 22]}]

如果栅格为多波段栅格,则将使用列表中的每个字典来设置每个波段的直方图。第一个波段将使用第一个字典中的直方图。第二个波段将使用第二个字典中的直方图,依此类推。

  • size直方图中的图格数
  • min最小像素值
  • max最大像素值
  • counts包含每个图格中的像素数的列表,以图格顺序进行排序
Dictionary
variable_name

多维栅格数据集的变量名称。如果未指定变量且栅格为多维栅格,则系统将为第一个变量设置直方图。

String
setProperty (property_name, property_value)
参数说明数据类型
property_name

栅格数据集的属性名称。

String
property_value

分配给属性的值。

String
setStatistics (statistics_obj, {variable_name})
参数说明数据类型
statistics_obj
[statistics_obj,...]

包含统计数据和要设置的相应值的 Python 字典列表。例如,[{'min': 10, 'max': 20}] 用于设置最小像素值和最大像素值。

如果栅格为多波段栅格,则将使用列表中的每个字典来设置每个波段的统计数据。第一个波段将使用第一个字典中的统计数据。第二个波段将使用第二个字典中的统计数据,依此类推。

  • min最小像素值
  • max最大像素值
  • mean平均像素值
  • median像素中值
  • standardDeviation像素值的标准差
  • count总像素数
  • skipX水平跳跃因子
  • skipY垂直跳跃因子
List
variable_name

多维栅格数据集的变量名称。如果未指定变量且栅格为多维栅格,则系统将设置第一个变量的统计数据。

String
setVariableAttributes (variable_name, variable_attributes)
参数说明数据类型
variable_name

多维栅格数据集的变量名称。

String
variable_attributes

包含用于替换变量当前属性信息的属性信息的 Python 字典,例如 {'Description': 'Daily total precipitation', 'Unit': 'mm/day'}

Dictionary
返回值
数据类型说明
String

变量的属性信息。

write (array, {upper_left_corner}, {origin_coordinate}, {value_to_nodata})
参数说明数据类型
array

输入的 NumPy 数组。

(默认值为 None)

NumPyArray
upper_left_corner

可从中提取处理块以转换为栅格的与 origin_coordinate 相关的坐标。应将其格式化为一个包含两个值的元组,分别表示要在 x 和 y 方向上移动的像素数。例如,(2,0),表示将写入栅格的 NumPy 数组的源位置为在 x 方向上与 origin_coordinate 相距 2 个像素。

如果未指定值,则使用 (0,0)

(默认值为 None)

tuple
origin_coordinate

用于定义原点的 Point 对象,即,将写入 Raster 的 numpy 数组的源位置。x 值和 y 值采用栅格单位。若未指定值,则将使用栅格的左上角。

若未指定值,则将使用栅格的原点。这是默认设置。

(默认值为 None)

Point
value_to_nodata

要在栅格中用作 NoData 值的 NumPy 数组中的值。值是整型或浮点型。若未指定值,则将使用 Raster 的 NoData 值。

默认值为 None

(默认值为 None)

Double

如果栅格是单波段栅格,则数组的维度须为行、列、1。

如果栅格是多波段栅格,则数组的维度须为行、列和波段计数。

如果栅格是多维栅格且其中每个剖切都是单波段,则数组的维度须为剖切数、行、列、1。

如果栅格是多维栅格且其中每个剖切都是多波段,则数组的维度须为剖切数、行、列、波段计数。

代码示例

栅格示例 1

根据栅格数据集创建 Raster 对象并获取分析属性。

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
栅格示例 2

创建 Raster 对象,从栅格数据集中调用栅格函数模板,并应用处理模板。

import arcpy

#Create raster object
ras = arcpy.Raster(r"D:\Data\ndfd.crf")

#Define two raster function templates from the input CRF
ras.functions =[r"C:\weather.rft.xml", r"C:\heatindex.rft.xml"]

#Retrieve the first rft and process the raster object using the Apply function
rft = ras.functions
processed_raster = arcpy.ia.Apply(ras, json.dumps(rft[1]))
栅格示例 3

创建 Raster 对象、获取属性、创建随机误差栅格(+/- 3 英尺)、将随机误差栅格添加到高程栅格中并将其单位从英尺转换成米。

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")
栅格示例 4

从多维栅格数据集创建 Raster 对象,并获取包含变量和维度值的多维信息。

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")
栅格示例 5

基于多维栅格数据集创建 Raster 对象并计算变量的统计数据。

import arcpy

#Load a netCDF file as a multidimensional raster
mdim_raster = Raster("Precip_2000_2018.nc", True)

#Create an array that contains the corner coordinates for a bounding box
array = arcpy.Array([arcpy.Point(-119.8082436, 38.2177764), arcpy.Point(-119.7794812, 38.2038911), arcpy.Point(-119.7432803, 38.2232313), arcpy.Point(-119.7928706, 38.2425716)])

#Specify a spatial reference
spatial_reference = arcpy.SpatialReference(4326)

#Create a polygon object that will be used to specify the aoi
aoi= arcpy.Polygon(array, spatial_reference)

#return the statistics 
stats = mdim_raster.computeStatistics('precip', aoi, cellsize = 463)
栅格示例 6

STAC 项目创建 Raster 对象。

# 1) Creates a raster object from a STAC Item on Planetary Computer STAC API

from arcpy.ia import *

# Create a raster object from NAIP data accesible through Planetary Computer STAC API

ras = Raster.fromSTACItem(
stac_item="https://planetarycomputer.microsoft.com/api/stac/v1/collections/naip/items/tx_m_2609719_se_14_060_20201217"
)

# Apply grayscale raster function to the raster object
gray_ras = Grayscale(ras)

# 2) Creates a raster object from a STAC Item on Earth Search STAC API

from arcpy import Raster

# Create a raster object from Sentinel-2 L2A data accesible through Earth Search STAC API

ras = Raster.fromSTACItem(
stac_item="https://earth-search.aws.element84.com/v1/collections/sentinel-2-l2a/items/S2A_45XWD_20230328_0_L2A"
)

# Retrieve raster object properties
cols, rows = ras.width, ras.height