RasterCollection

摘要

定义要包含在集合中的输入栅格和属性组,其中的集合将用于处理。

说明

RasterCollection 对象允许对一组栅格进行排序和过滤,并准备一个集合以进行其他处理和分析。

RasterCollection 对象包含 maxminmedianmeanmajoritysum 方法,以计算集合栅格中匹配波段上每个像素的统计信息。

例如,sum 方法将栅格项 1 波段 1 中的像素值与栅格项 2 波段 1 中的像素值相加,并返回波段 1 包含这些求和值的 Raster 对象。

RasterCollection 类的求和方法

语法

 RasterCollection (rasters, {attribute_dict})
参数说明数据类型
rasters
[rasters,...]

输入栅格数据集。受支持的输入包括栅格列表、镶嵌数据集、云栅格格式的多维栅格、NetCDF 文件或图像服务。如果使用的是栅格数据集列表,则所有栅格必须具有相同的像元大小和空间参考。

List
attribute_dict

包含当输入为栅格列表时要添加到每个栅格的属性信息的 Python 字典。对于每个键值对,键是属性名称,而值是用于表示每个栅格的属性值的值列表。例如,要将名称字段添加到包含三个栅格的列表中,请使用 {"name": ["Landsat8_Jan", "Landsat8_Feb", "Landsat8_Mar"]}

(默认值为 None)

Dictionary

属性

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

栅格集合中包含的字段名称列表。

String
count
(只读)

栅格集合中的项目总数。

Integer

方法概述

方法说明
addField (field_name, field_values)

将新字段添加至栅格集合并在其中填充值。

filter ({where_clause}, {query_geometry_or_extent})

按属性或几何过滤栅格项目的集合,并返回仅包含满足过滤器的项目的栅格集合。如果未提供任何参数,则来自栅格集合的所有栅格项目将在新的栅格集合中返回。

filterByAttribute (field_name, operator, field_values)

按属性查询过滤栅格项目的集合,并返回仅包含满足查询的项目的栅格集合。

要根据时间字段查询栅格集合,请使用 filterByTime 方法。

filterByCalendarRange (calendar_field, start, {end}, time_field_name, date_time_format)

按日历字段范围过滤栅格项目的集合,并返回仅包含满足过滤器的项目的栅格集合。 如果未提供任何参数,则来自栅格集合的所有栅格项目将在新的栅格集合中返回。

filterByGeometry (query_geometry_or_extent)

过滤栅格项目的集合,以便仅返回与几何相交的栅格项目。

filterByRasterProperty (property_name, operator, property_values)

按栅格属性查询过滤栅格项目的集合,并返回仅包含满足查询的项目的栅格集合。

filterByTime ({start_time}, {end_time}, {time_field_name}, {date_time_format})

按时间范围过滤栅格项目的集合,并返回仅包含满足过滤器的项目的栅格集合。

fromSTACAPI (stac_api, {query}, {attribute_dict}, {request_method}, {request_params}, {context})

根据时空资产目录 (STAC) API 搜索查询创建 RasterCollection 对象。

fromSTACCatalog (stac_catalog, {attribute_dict}, {request_params}, {context})

根据静态时空资产目录 (STAC) 创建一个 RasterCollection 对象。

getFieldValues (field_name, {max_count})

返回栅格集合中指定字段的值。

groupBy (field_name)

根据字段对栅格集合进行分组。 可通过字段值访问每个已分组栅格集合。

majority ({ignore_nodata}, {extent_type}, {cellsize_type})

返回一个栅格对象,其中每个波段都包含该波段在栅格集合中的所有栅格上出现最频繁的像素值。

例如,如果栅格集合中有 10 个栅格项目,每个栅格项目包含 4 个波段,则 majority 方法将确定在波段 1、波段 2、波段 3 和波段 4 的所有栅格项目上出现最频繁的像素值;将返回四波段栅格。 波段号需要使用波段指数在栅格项目之间进行匹配,因此栅格集合中的项目必须遵循相同的波段顺序。

map (func)

将 Python 函数映射到栅格集合。

max ({ignore_nodata}, extent_type, cellsize_type)

返回一个栅格对象,其中每个波段都包含该波段在栅格集合中的所有栅格上的最大像素值。

例如,如果栅格集合中有 10 个栅格项目,每个栅格项目包含 4 个波段,则 max 方法将计算在波段 1、波段 2、波段 3 和波段 4 的所有栅格项目上出现的最大像素值;将返回四波段栅格。 波段号需要使用波段指数在栅格项目之间进行匹配,因此栅格集合中的项目必须遵循相同的波段顺序。

mean ({ignore_nodata}, {extent_type}, {cellsize_type})

返回一个栅格对象,其中每个波段都包含该波段在栅格集合中的所有栅格上的平均像素值。

例如,如果栅格集合中有 10 个栅格项目,每个栅格项目包含 4 个波段,则 mean 方法将计算在波段 1、波段 2、波段 3 和波段 4 的所有栅格项目上出现的平均像素值;将返回四波段栅格。 波段号需要使用波段指数在栅格项目之间进行匹配,因此栅格集合中的项目必须遵循相同的波段顺序。

median ({ignore_nodata}, {extent_type}, {cellsize_type})

返回一个栅格对象,其中每个波段都包含该波段在栅格集合中的所有栅格上的像素中值。

例如,如果栅格集合中有 10 个栅格项目,每个栅格项目包含 4 个波段,则 median 方法将计算在波段 1、波段 2、波段 3 和波段 4 的所有栅格项目上出现的像素中值;将返回四波段栅格。 波段号需要使用波段指数在栅格项目之间进行匹配,因此栅格集合中的项目必须遵循相同的波段顺序。

merge (collection2)

返回已合并栅格集合,其中包含两个栅格集合中的所有栅格。

min ({ignore_nodata}, {extent_type}, {cellsize_type})

返回一个栅格对象,其中每个波段都包含该波段在栅格集合中的所有栅格上的最低像素值。

例如,如果栅格集合中有 10 个栅格项目,每个栅格项目包含 4 个波段,则 min 方法将计算在波段 1、波段 2、波段 3 和波段 4 的所有栅格项目上出现的最小像素值;将返回四波段栅格。 波段号需要使用波段指数在栅格项目之间进行匹配,因此栅格集合中的项目必须遵循相同的波段顺序。

mosaic ({mosaic_method})

返回一个栅格数据集,其中栅格集合中的所有项目都已镶嵌到单个栅格中。

qualityMosaic (quality_rc_or_list, {statistic_type})

返回一个栅格数据集,其中栅格集合中的所有项目都已根据质量要求镶嵌到单个栅格中。

reduce (func, {func_args})

将返回一个栅格对象,其中集合中的所有图像将根据 reducer 函数合并为单一图像。

例如,如果栅格集合中有 10 个栅格项目,每个栅格项目包含 4 个波段,则 Min 方法可以指定为 reducer 函数。 这将返回一个四波段栅格,每个波段包含所有十个栅格的最小值。

selectBands (band_ids_or_names)

选择栅格集合中每个栅格项目的波段列表,并返回包含仅具有所选波段的栅格项目的栅格集合。

sort (field_name, {ascending})

按字段名称对栅格集合进行排序,然后返回指定顺序的栅格集合。

std ({ignore_nodata}, {extent_type}, {cellsize_type})

返回一个栅格对象,其中每个波段都包含该波段在栅格集合中的所有栅格上的像素标准差值。

例如,如果栅格集合中有 10 个栅格项目,每个栅格项目包含 4 个波段,则 std 方法将计算在波段 1、2、3 和 4 的所有栅格项目上出现的像素标准差值;将返回四波段栅格。 波段号需要使用波段指数在栅格项目之间进行匹配,因此栅格集合中的项目必须遵循相同的波段顺序。

sum ({ignore_nodata}, {extent_type}, {cellsize_type})

返回一个栅格对象,其中每个波段都包含该波段在栅格集合中的所有栅格上的像素值之和。

例如,如果栅格集合中有 10 个栅格项目,每个栅格项目包含 4 个波段,则 sum 方法将计算在波段 1、波段 2、波段 3 和波段 4 的所有栅格项目上出现的每个像素的像素值之和;将返回四波段栅格。 波段号需要使用波段指数在栅格项目之间进行匹配,因此栅格集合中的项目必须遵循相同的波段顺序。

summarizeField (field_name, {summary_type})

汇总栅格集合的给定字段中的对象。

toMultidimensionalRaster (variable_field_name, dimension_field_names)

返回多维栅格数据集,其中栅格集合中的每个项目均为多维栅格中的一个剖切。

方法

addField (field_name, field_values)
参数说明数据类型
field_name

The name of the field to be added.

String
field_values
[field_values,...]

The list of values associated with the field name. The length of the list should match the number of items in the raster collection.

List
返回值
数据类型说明
RasterCollection

包含新字段的栅格集合。

filter ({where_clause}, {query_geometry_or_extent})
参数说明数据类型
where_clause

用于限制所返回的记录的表达式。有关 WHERE 子句和 SQL 语句的详细信息,请参阅在 ArcGIS 中使用的查询表达式的 SQL 参考

(默认值为 None)

String
query_geometry_or_extent

此对象用于过滤项目,以便仅返回与该对象相交的项目。

可以使用 Geometry 对象、Extent 对象、Raster 对象或要素类的路径进行指定。

(默认值为 None)

Geometry
返回值
数据类型说明
RasterCollection

满足属性或几何查询的栅格集合。

filterByAttribute (field_name, operator, field_values)
参数说明数据类型
field_name

过滤器中使用的字段名称。

String
operator

用于过滤属性的关键字。关键字包括以下内容:

  • CONTAINS字段中的属性包含指定的字符串、列表或数字。
  • ENDS_WITH该属性以指定的字符串或数字结尾。
  • EQUALS该属性等于指定的字符串、列表或数字。
  • GREATER_THAN该属性大于指定数字。
  • IN该属性是指定列表中的一个项目。
  • LESS_THAN该属性小于指定数字。
  • NOT_CONTAINS该属性不包含指定的字符串、列表或数字。
  • NOT_ENDS_WITH该属性不以指定的字符串或数字结尾。
  • NOT_EQUALS该属性不等于指定的字符串、列表或数字。
  • NOT_GREATER_THAN该属性不大于指定数字。
  • NOT_IN该属性不是指定列表中的一个项目。
  • NOT_LESS_THAN该属性不小于指定数字。
  • NOT_STARTS_WITH该属性不以指定的字符串或数字开头。
  • STARTS_WITH该属性以指定的字符串或数字开头。
String
field_values
[field_values,...]

要比较的一个或多个属性值。可以将其指定为字符串、列表或数字。

String
返回值
数据类型说明
RasterCollection

满足属性查询的栅格集合。

filterByCalendarRange (calendar_field, start, {end}, time_field_name, date_time_format)
参数说明数据类型
calendar_field

The name of the calendar field. Specify one of the following: HOUR, DAY_OF_WEEK, DAY_OF_MONTH, DAY_OF_YEAR, WEEK_OF_YEAR, MONTH, YEAR, or QUARTER.

String
start

The start value of the calendar_field. For example, to filter all items that were collected in January, filtered_rc = rc.filterByCalendarRange(calendar_field="MONTH", start=1).

Integer
end

The end value of the calendar_field. For example, to filter all items that were collected in the first five days of each year, filtered_rc = rc.filterByCalendarRange(calendar_field="DAY_OF_YEAR", start=1, end=5).

Integer
time_field_name

The name of the field that contains the time attribute for each item in the collection. The default is StdTime.

String
date_time_format

The time format of the values in the time field. For example, if the input date and time value is "1990-01-31T00:00:00", the date_time_format is "%Y-%m-%dT%H:%M:%S". If only the date value is required, date_time_format can be specified as "%Y-%m-%d".

String
返回值
数据类型说明
RasterCollection

满足时间范围查询的栅格集合。

filterByGeometry (query_geometry_or_extent)
参数说明数据类型
query_geometry_or_extent

此对象用于过滤项目,以便仅返回与该对象相交的项目。可以使用 Geometry 对象、Extent 对象、Raster 对象或要素类的路径进行指定。

Geometry
返回值
数据类型说明
RasterCollection

满足几何过滤器的栅格集合。

filterByRasterProperty (property_name, operator, property_values)
参数说明数据类型
property_name

过滤器中使用的属性的名称。

String
operator

用于过滤属性的运算符。

  • CONTAINS该属性包含指定的字符串、列表或数字。
  • ENDS_WITH该属性以指定的字符串或数字结尾。
  • EQUALS该属性等于指定的字符串、列表或数字。
  • GREATER_THAN该属性大于指定数字。
  • IN该属性是指定列表中的一个项目。
  • LESS_THAN该属性小于指定数字。
  • NOT_CONTAINS该属性不包含指定的字符串、列表或数字。
  • NOT_ENDS_WITH该属性不以指定的字符串或数字结尾。
  • NOT_EQUALS该属性不等于指定的字符串、列表或数字。
  • NOT_GREATER_THAN该属性不大于指定数字。
  • NOT_IN该属性不是指定列表中的一个项目。
  • NOT_LESS_THAN该属性不小于指定数字。
  • NOT_STARTS_WITH该属性不以指定的字符串或数字开头。
  • STARTS_WITH该属性以指定的字符串或数字开头。
String
property_values
[property_values,...]

要比较的一个或多个属性值。可以将其指定为字符串、列表或数字。

String
返回值
数据类型说明
RasterCollection

满足属性查询的栅格集合。

filterByTime ({start_time}, {end_time}, {time_field_name}, {date_time_format})
参数说明数据类型
start_time

用于指定起始时间的字符串。字符串的格式应与输入栅格集合的日期格式相匹配,例如“1990-01-01T13:30:00”。如果未指定,则必须指定结束时间,且仅会返回时间值早于或等于结束时间的项目。

(默认值为 None)

String
end_time

用于指定结束时间的字符串。字符串的格式应与输入栅格集合的日期格式相匹配,例如“1991-01-01T13:30:00”。如果未指定,则必须指定开始时间,且仅会返回时间值晚于或等于开始时间的项目。

(默认值为 None)

String
time_field_name

包含集合中每个项目的时间属性的字段名称。

(默认值为 StdTime)

String
date_time_format

start_timeend_time 值的格式。例如,如果提供的 start_time 值为 "1990-01-31",则 date_time_format 为 "%Y-%m-%d."。对于包含时间部分的日期,例如 "1990-01-31T00:00:00",默认格式为 "%Y-%m-%dT%H:%M:%S"。

String
返回值
数据类型说明
RasterCollection

满足时间范围过滤器的栅格集合。

fromSTACAPI (stac_api, {query}, {attribute_dict}, {request_method}, {request_params}, {context})
参数说明数据类型
stac_api

The URL of the STAC API root endpoint. This is the STAC API where the search will be performed, for example, "https://planetarycomputer.microsoft.com/api/stac/v1".

The following STAC APIs are supported:

  • 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, esa-worldcover, modis-64A1-061, modis-17A2H-061, modis-11A2-061, modis-17A2HGF-061, modis-17A3HGF-061, modis-09A1-061, modis-16A3GF-061, modis-21A2-061, modis-43A4-061, modis-09Q1-061, modis-14A1-061, modis-13Q1-061, modis-14A2-061, modis-15A2H-061, modis-11A1-061, modis-15A3H-061, modis-13A1-061, modis-10A2-061, modis-10A1-061, and aster-l1t.
  • 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.
  • https://landsatlook.usgs.gov/stac-server—All collections are supported.
  • https://geoportalstac.azurewebsites.net/stac—All collections are supported.
  • https://gpt.geocloud.com/sentinel/stac—All collections are supported.
String
query

The GET or POST request query dictionary that will be used to query a STAC API search endpoint. The key-value pairs depend on the specification of the stac_api value and the request_method value.

{
"collections": ["sentinel-2-l2a"],
"bbox": [-110, 39.5, -105, 40.5],
"query": {"eo:cloud_cover": {"lt": 0.5}},
"datetime": "2020-10-05T00:00:00Z/2020-10-10T12:31:12Z",
"limit": 100
}

For the bbox key, Extent and Polygon objects are also accepted (in any spatial reference).

Dictionary
attribute_dict

The attribute information that will be added to each STAC item raster returned from the query. For each key-value pair, the key is the attribute name, and the value is a list of values that represent the attribute value for each raster.

Attribute values can also be collected from the STAC items automatically using the STAC item metadata information. This can be done by specifying the STAC item property name for the attribute of interest as key-value pairs (attribute display name: STAC item property name).

{
"Name": "id",
"Sensor": "platform",
"StdTime": "datetime",
"Cloud Cover": "eo:cloud_cover",
"Spatial Reference": "proj:epsg",
"Extent": "bbox"
}

注:

If no Geometry key is specified, it will be automatically added for each raster in theRasterCollection object based on its STAC item's geometry property and will be in "Spatial Reference": {"wkid": 4326}.

Dictionary
request_method

Specifies the HTTP request method that will be used with the STAC API for the search.

  • GET—A GET request will be sent to the STAC API.
  • POST—A POST request will be sent to the STAC API.

Example: "POST"

(默认值为 POST)

String
request_params

The parameters of the STAC API search request. Specify therequests.post() orrequests.get() method parameters and values in dictionary format.

{
"verify": False,
"headers": {"Authorization": "Bearer access_token_string"}
}
Dictionary
context

Additional properties to control the creation of the object.

The dictionary supports the assetManagement and processingTemplate keys.

The assetManagement key specifies how to manage and select assets for the RasterCollection object. If multiple assets are selected, the collection will be composed of multiband rasters from those selected asset types. The value can be a list, string, or dictionary.

When working with individual assets, the asset key can be specified directly, for example, "B02" or {"key": "B02"}, or as a list. Each item in the list represents an asset key or identifier. Items in the list can be strings representing the asset key directly, or dictionaries providing additional details for locating the asset.

If the value of the assetManagement key is a dictionary, the following keys are supported:

  • key—A string representing the unique identifier for an asset, for example: "red".
  • path—A list representing the hierarchy of keys to navigate to the asset, for example: ["alternate", "s3"].
  • hrefKey—A string representing the key to access the asset URL, for example: "msft:https-url". If this value is different from the default href key, it should be specified here.

Examples:

{
    "assetManagement": [
        "red",
        "blue"
    ]
}
{
    "assetManagement": {
       "key": "tasmin",
       "hrefKey": "msft:https-url"
    }
}
{
    "assetManagement": [
       {"key": "TRAD",
        "path": ["alternate", "s3"]},
       {"key": "DRAD", 
        "path": ["alternate", "s3"]}
    ]
}

The processingTemplate key specifies the processing template that will be applied to the individual rasters in the collection. This is supported for selected collections and raster types. For more information about collections and raster types, see Satellite sensor raster types. The default for supported raster types is "Multiband"; otherwise, it's None.

Example:

{
    "processingTemplate": "Surface Reflectance"
}
Dictionary
返回值
数据类型说明
RasterCollection

返回该类的一个新实例

fromSTACCatalog (stac_catalog, {attribute_dict}, {request_params}, {context})
参数说明数据类型
stac_catalog

The URL of the STAC item, a pystac.Catalog, or a pystac.Collection object. If a URL is provided, the value must be a static STAC item URL or a STAC API Item URL, for example, "https://maxar-opendata.s3.amazonaws.com/events/India-Floods-Oct-2023/collection.json".

The following static catalogs (and their underlying child catalogs) are supported:

String
attribute_dict

The attribute information that will be added to each STAC item raster returned from the query. For each key-value pair, the key is the attribute name, and the value is a list of values that represent the attribute value for each raster.

Attribute values can also be collected from the STAC items automatically using the STAC item metadata information. To do this, specify the STAC item property name for the attribute of interest as key-value pairs (attribute display name: STAC item property name).

{
"Name": "id",
"Sensor": "platform",
"StdTime": "datetime",
"Cloud Cover": "eo:cloud_cover",
"Spatial Reference": "proj:epsg",
"Extent": "bbox"
}

注:

If no Geometry key is specified, it will be automatically added for each raster in theRasterCollection object based on its STAC item's geometry property and will use a spatial reference as follows: "Spatial Reference": {"wkid": 4326}.

Dictionary
request_params

The parameters of the STAC catalog or item request.

Specify therequests.post() orrequests.get() method parameters and values in dictionary format.

{
"verify": False,
"headers": {"Authorization": "Bearer access_token_string"}
}
Dictionary
context

Additional properties to control the creation of the object.

The dictionary supports the assetManagement and processingTemplate keys.

The assetManagement key specifies how to manage and select assets for the RasterCollection object. If multiple assets are selected, the collection will be composed of multiband rasters from those selected asset types. The value can be a list, string, or dictionary.

When working with individual assets, the asset key can be specified directly, for example, "B02" or {"key": "B02"}, or as a list. Each item in the list represents an asset key or identifier. Items in the list can be strings representing the asset key directly, or dictionaries providing additional details for locating the asset.

If the value of the assetManagement key is a dictionary, the following keys are supported:

  • key—A string representing the unique identifier for an asset, for example: "red".
  • path—A list representing the hierarchy of keys to navigate to the asset, for example: ["alternate", "s3"].
  • hrefKey—A string representing the key to access the asset URL, for example: "msft:https-url". If this value is different from the default href key, it should be specified here.

Examples:

{
    "assetManagement": [
        "red",
        "blue"
    ]
}
{
    "assetManagement": {
       "key": "tasmin",
       "hrefKey": "msft:https-url"
    }
}
{
    "assetManagement": [
       {"key": "TRAD",
        "path": ["alternate", "s3"]},
       {"key": "DRAD", 
        "path": ["alternate", "s3"]}
    ]
}

The processingTemplate key specifies the processing template that will be applied to the individual rasters in the collection. This is supported for selected collections and raster types. For more information about collections and raster types, see Satellite sensor raster types The default for supported raster types is "Multiband"; otherwise, it's None.

Example:

{
    "processingTemplate": "Surface Reflectance"
}
Dictionary
返回值
数据类型说明
RasterCollection

返回该类的一个新实例

getFieldValues (field_name, {max_count})
参数说明数据类型
field_name

要从中提取值的字段的名称。

String
max_count

一个用于指定要返回的最大字段值数量的整数。该值将按照集合中栅格项目的排序顺序返回。如果未指定任何值,则将返回给定字段的所有字段值。

(默认值为 None)

Integer
返回值
数据类型说明
String

指定字段名称的字段值列表。

groupBy (field_name)
参数说明数据类型
field_name

The name of the field. Items with the same field values will be grouped together.

String
返回值
数据类型说明
Dictionary

包含已分组栅格集合的字典。 字典键为与用于定义分组的字段名称关联的字段值。 字典值为栅格集合,其中字段名称包含相同的字段值。

majority ({ignore_nodata}, {extent_type}, {cellsize_type})
参数说明数据类型
ignore_nodata
[ignore_nodata,...]

Specifies whether NoData values are ignored.

(默认值为 True)

Boolean
extent_type

Computes the extent of the output raster object when the input rasters have different extents.

  • FirstOfDefines the output extent using the extent of the first input raster.
  • IntersectionOfDefines the output extent as the intersecting area of the input rasters.
  • UnionOfDefines the output extent as the total extent of the input rasters.
  • LastOfDefines the output extent using the extent of the last input raster.

(默认值为 FirstOf)

String
cellsize_type

Computes the cell size of the output raster object when the input rasters have different cell sizes.

  • FirstOfDefines the output extent using the extent of the first input raster.
  • IntersectionOfDefines the output extent as the intersecting area of the input rasters.
  • UnionOfDefines the output extent as the total extent of the input rasters.
  • LastOfDefines the output extent using the extent of the last input raster.

(默认值为 FirstOf)

String
返回值
数据类型说明
Raster

此栅格中的每个波段均包含该波段在栅格集合中所有项目上出现最频繁的像素值。

map (func)
参数说明数据类型
func

要映射到栅格集合的 Python 函数。该函数的返回值必须是其中一个键为 raster 的字典。例如,{"raster": output_raster_object, "name": input_item_name["name"]}


def NDVI(item):
    """Define a Python function to calculate NDVI"""
    # Create the raster object from the item
    raster_obj = item['Raster']
    # Create raster objects for the red and NIR bands
		  red, nir = raster_obj.getRasterBands(["red", "nir"])
    # Compute NDVI
    ndvi = (nir-red)/(nir+red)
    return {"raster": ndvi, "name": item['Name'], "stdTime": item['AcquisitionDate']}
ndvi_rc = rc.map(NDVI)

Function
返回值
数据类型说明
RasterCollection

此栅格集合中的每个项目均包含已应用函数并已附加属性的栅格。

max ({ignore_nodata}, extent_type, cellsize_type)
参数说明数据类型
ignore_nodata
[ignore_nodata,...]

Specifies whether NoData values are ignored.

(默认值为 True)

Boolean
extent_type

Computes the extent of the output raster object when the input rasters have different extents.

  • FirstOfDefines the output extent using the extent of the first input raster.
  • IntersectionOfDefines the output extent as the intersecting area of the input rasters.
  • UnionOfDefines the output extent using the extent of the last input raster.
  • LastOfDefines the output extent using the extent of the last input raster.

(默认值为 FirstOf)

String
cellsize_type

Computes the cell size of the output raster object when the input rasters have different cell sizes.

  • FirstOfDefines the output extent using the extent of the first input raster.
  • IntersectionOfDefines the output extent as the intersecting area of the input rasters.
  • UnionOfDefines the output extent as the total extent of the input rasters.
  • LastOfDefines the output extent using the extent of the last input raster.

(默认值为 FirstOf)

String
返回值
数据类型说明
Raster

此栅格中的每个波段都包含该波段在栅格集合中的所有栅格上的最大像素值。

mean ({ignore_nodata}, {extent_type}, {cellsize_type})
参数说明数据类型
ignore_nodata
[ignore_nodata,...]

Specifies whether NoData values are ignored.

(默认值为 True)

Boolean
extent_type

Computes the extent of the output raster object when the input rasters have different extents.

  • FirstOfDefines the output extent using the extent of the first input raster.
  • IntersectionOfDefines the output extent as the total extent of the input rasters.
  • UnionOfDefines the output extent as the total extent of the input rasters.
  • LastOfDefines the output extent using the extent of the last input raster.

(默认值为 FirstOf)

String
cellsize_type

Computes the cell size of the output raster object when the input rasters have different cell sizes.

  • FirstOfDefines the output extent using the extent of the first input raster.
  • IntersectionOfDefines the output extent as the intersecting area of the input rasters.
  • UnionOfDefines the output extent as the total extent of the input rasters.
  • LastOfDefines the output extent using the extent of the last input raster.

(默认值为 FirstOf)

String
返回值
数据类型说明
Raster

此栅格中的每个波段都包含该波段在栅格集合中的所有栅格上的平均像素值。

median ({ignore_nodata}, {extent_type}, {cellsize_type})
参数说明数据类型
ignore_nodata
[ignore_nodata,...]

Specifies whether NoData values are ignored.

(默认值为 True)

Boolean
extent_type

Computes the extent of the output raster object when the input rasters have different extents.

  • FirstOfDefines the output extent using the extent of the first input raster.
  • IntersectionOfDefines the output extent as the intersecting area of the input rasters.
  • UnionOfDefines the output extent as the total extent of the input rasters.
  • LastOfDefines the output extent using the extent of the last input raster.

(默认值为 FirstOf)

String
cellsize_type

Computes the extent of the output raster object when the input rasters have different extents.

  • FirstOfDefines the output extent using the extent of the first input raster.
  • IntersectionOfDefines the output extent as the intersecting area of the input rasters.
  • UnionOfDefines the output extent as the total extent of the input rasters.
  • LastOfDefines the output extent using the extent of the last input raster.

(默认值为 FirstOf)

String
返回值
数据类型说明
Raster

此栅格中的每个波段都包含该波段在栅格集合中的所有栅格上的像素中值。

merge (collection2)
参数说明数据类型
collection2

The raster collection to be merged.

RasterCollection
返回值
数据类型说明
RasterCollection

已合并栅格集合。

min ({ignore_nodata}, {extent_type}, {cellsize_type})
参数说明数据类型
ignore_nodata
[ignore_nodata,...]

Specifies whether NoData values are ignored.

(默认值为 True)

Boolean
extent_type

Computes the extent of the output raster object when the input rasters have different extents.

  • FirstOfDefines the output extent using the extent of the first input raster.
  • IntersectionOfDefines the output extent as the intersecting area of the input rasters.
  • UnionOfDefines the output extent as the total extent of the input rasters.
  • LastOfDefines the output extent using the extent of the last input raster.

(默认值为 FirstOf)

String
cellsize_type

Computes the cell size of the output raster object when the input rasters have different cell sizes.

  • FirstOfDefines the output extent using the extent of the first input raster.
  • IntersectionOfDefines the output extent as the intersecting area of the input rasters.
  • UnionOfDefines the output extent as the total extent of the input rasters.
  • LastOfDefines the output extent using the extent of the last input raster.

(默认值为 FirstOf)

String
返回值
数据类型说明
Raster

此栅格中的每个波段都包含该波段在栅格集合中的所有栅格上的最低像素值。

mosaic ({mosaic_method})
参数说明数据类型
mosaic_method

The method that will be used for overlapping areas between adjacent raster items. Mosaic method options include the following:

  • FIRSTThe pixel value from the first raster that is overlapping will be determined.
  • LASTThe pixel value from the last raster that is overlapping will be determined.
  • MEANThe average pixel value from the two rasters that are overlapping will be determined.
  • MINIMUMThe lower pixel value from the two raster datasets that are overlapping will be determined.
  • MAXIMUMThe higher pixel value from the two raster datasets that are overlapping will be determined.
  • SUMThe sum of pixel values from the two rasters that are overlapping will be determined.

For more information about mosaic methods, see Displaying overlapping imagery.

(默认值为 First)

String
返回值
数据类型说明
Raster

包含来自栅格集合的镶嵌栅格项目的栅格数据集。

qualityMosaic (quality_rc_or_list, {statistic_type})
参数说明数据类型
quality_rc_or_list

用作质量指标的栅格集合或栅格列表。

例如,Landsat 8 的波段 1 是“沿海/气溶胶”波段,可用于估算大气中细小气溶胶颗粒(例如烟尘和烟雾)的浓度。对于 Landsat 8 影像集合,请使用 selectBands 方法从每个栅格项目返回仅包含 波段 1 的 RasterCollection 对象。quality_rc_or_list 中的栅格项目数必须与要镶嵌的栅格集合中的栅格项目数相匹配。

RasterCollection
statistic_type

用于比较输入集合或质量栅格列表的统计数据。

  • MAX输入质量栅格中的最高像素值将是输出栅格中的像素值。这是默认设置。
  • MEDIAN输入质量栅格中的像素中值将是输出栅格中的像素值。
  • MIN输入质量栅格中的最小像素值将是输出栅格中的像素值。

例如,如需镶嵌输入栅格集合以使气溶胶含量最低的栅格位于顶部,请使用 MIN 统计类型。

String
返回值
数据类型说明
Raster

包含来自栅格集合的镶嵌栅格项目的栅格数据集。

reduce (func, {func_args})
参数说明数据类型
func
[func,...]

The function used to reduce the raster collection. This argument also accepts a custom reducer function.

(默认值为 None)

String
func_args

A dictionary that contains additional parameters for the reducer function.

rc = RasterCollection("<data path>")
max_raster = rc.reduce(func=Max, func_args={'extent_type': 'UnionOf', 
                                            'cellsize_type': 'MinOf', 
                                            'ignore_nodata': True, 
                                            'process_as_multiband': True})

(默认值为 None)

Dictionary
返回值
数据类型说明
RasterCollection

满足 reducer 方法的栅格集合。

selectBands (band_ids_or_names)
参数说明数据类型
band_ids_or_names
[band_ids_or_names,...]

要包含在返回的栅格项目中的波段名称或索引编号。可以使用单个字符串、整数或者字符串或整数的列表来进行指定。

Object
返回值
数据类型说明
RasterCollection

仅包含所选波段的栅格集合。

sort (field_name, {ascending})
参数说明数据类型
field_name

用于排序的字段名称。

String
ascending

指定按升序还是降序进行排序。

(默认值为 True)

Boolean
返回值
数据类型说明
RasterCollection

已排序的栅格项目集合。

std ({ignore_nodata}, {extent_type}, {cellsize_type})
参数说明数据类型
ignore_nodata
[ignore_nodata,...]

Specifies whether NoData values are ignored.

(默认值为 True)

Boolean
extent_type

Computes the extent of the output raster object when the input rasters have different extents.

  • FirstOfDefines the output extent using the extent of the first input raster.
  • IntersectionOfDefines the output extent as the total extent of the input rasters.
  • UnionOfDefines the output extent as the total extent of the input rasters.
  • LastOfDefines the output extent using the extent of the last input raster.

(默认值为 FirstOf)

String
cellsize_type

Computes the cell size of the output raster object when the input rasters have different cell sizes.

  • FirstOfDefines the output extent using the extent of the first input raster.
  • IntersectionOfDefines the output extent as the intersecting area of the input rasters.
  • UnionOfDefines the output extent as the total extent of the input rasters.
  • LastOfDefines the output extent using the extent of the last input raster.

(默认值为 FirstOf)

String
返回值
数据类型说明
Raster

栅格中每个波段都包含该波段在栅格集合中的所有栅格上的像素标准差值。

sum ({ignore_nodata}, {extent_type}, {cellsize_type})
参数说明数据类型
ignore_nodata
[ignore_nodata,...]

Specifies whether NoData values are ignored.

(默认值为 True)

Boolean
extent_type

Computes the extent of the output raster object when the input rasters have different extents.

  • FirstOfDefines the output extent using the extent of the first input raster.
  • IntersectionOfDefines the output extent as the intersecting area of the input rasters.
  • UnionOfDefines the output extent as the total extent of the input rasters.
  • LastOfDefines the output extent using the extent of the last input raster.
String
cellsize_type

Computes the cell size of the output raster object when the input rasters have different cell sizes.

  • FirstOfDefines the output extent using the extent of the first input raster.
  • IntersectionOfDefines the output extent as the intersecting area of the input rasters.
  • UnionOfDefines the output extent as the total extent of the input rasters.
  • LastOfDefines the output extent using the extent of the last input raster.
String
返回值
数据类型说明
Raster

此栅格中的每个波段都包含该波段在栅格集合中的所有栅格上的像素值之和。

summarizeField (field_name, {summary_type})
参数说明数据类型
field_name

The field name to summarize.

String
summary_type
[summary_type,...]

The summary methods to calculate for the selected field. One or more methods can be specified.

  • COUNTCalculates the number of non-null values of the selected field.
  • COUNT_DISTINCTCalculates the number of distinct values of the selected field.
  • FIRSTCalculates the field value of the first object in the collection.
  • HISTOGRAMCalculates a histogram of the selected field.
  • MAXCalculates the maximum of the values of the selected field.
  • MEANCalculates the mean of the selected field.
  • MINCalculates the minimum of the values of the selected field.
  • PRODUCTCalculates the product of the values of the selected field.
  • SAMPLE_SDCalculates the sample standard deviation of the values of the selected field.
  • SAMPLE_VARCalculates the sample variance of the values of the selected field.
  • SUMCalculates the sum of the values of the selected field.
  • TOTAL_SDCalculates the total standard deviation of the values of the selected field.
  • TOTAL_VARCalculates the total variance of the values of the selected field.
  • ALLCalculates all the above statistics of the selected field.

(默认值为 ALL)

String
返回值
数据类型说明
Dictionary

汇总方法和值的字典。

toMultidimensionalRaster (variable_field_name, dimension_field_names)
参数说明数据类型
variable_field_name

包含变量名称的字段的名称。

String
dimension_field_names
[dimension_field_names,...]

包含维度名称的一个或多个字段的名称。可将其指定为单个字符串或字符串列表。

对于与时间相关的维度,如需被识别为时间字段,则字段名称必须与以下选项之一相匹配:StdTimeDateTimeAcquisitionDate。对于与时间无关的维度,这些字段中的值必须为双精度。如果有两个或多个维度,请使用逗号分隔字段(例如 dimension_field_names = ["Time", "Depth"])。

String
返回值
数据类型说明
Raster

多维栅格对象。栅格集合中的每个项目都是多维栅格中的一个剖切。

代码示例

RasterCollection 示例 1(Python 窗口)

根据镶嵌数据集创建栅格集合,并按日期过滤集合。

# Import system modules
import arcpy
from arcpy.ia import *

# Construct a collection from a mosaic dataset
rc = RasterCollection(r'C:\data.gdb\time_series_landsat_images')

# Filter the collection to extract all images before year 2009
filtered_rc = rc.filterByTime(end_time = '2009-01-01T00:00:00', 
	time_field_name = 'AcquisitionDate')

# Return the dates in the filtered collection
dates = filtered_rc.getFieldValues('AcquisitionDate')
RasterCollection 示例 2(Python 窗口)

根据镶嵌数据集创建栅格集合,并按几何过滤集合。

# Import system modules
import arcpy
from arcpy.ia import *

# Construct a collection from a mosaic dataset
rc = RasterCollection(r'C:\data.gdb\time_series_landsat_images')

# Define line geometry 
line = arcpy.Polyline(arcpy.Array([arcpy.Point(54.9243963, 23.9279934), 
	arcpy.Point(55.29, 25.6)]),arcpy.SpatialReference(4326))

# Filter the collection to extract images that intersect with line geometry
filtered_rc = rc.filterByGeometry(line)

# Return the total number of items in the filtered collection
count = filtered_rc.count
RasterCollection 示例 3(独立脚本)

根据镶嵌数据集创建栅格集合,并按属性过滤集合。

# Name: RasterCollection_Ex_03.py
# Description: Generates a raster collection from a mosaic dataset and
#	filters by an attribute field
# Requirements: ArcGIS Image Analyst 

# Import system modules
import arcpy
from arcpy.ia import *

# Define arguments
mosaic_dataset = r'C:\data.gdb\time_series_landsat_images'

# Construct a collection from a mosaic dataset
rc = RasterCollection(mosaic_dataset)

# Filter the collection to extract only images from Landsat 7
Landsat7_rc = rc.filterByAttribute("SensorName", "contain", "Landsat7")

# Return the names of the sensors in the filtered collection to double confirm
sensors= Landsat7_rc.getFieldValues(field_name)
RasterCollection 示例 4(Python 窗口)

从表示 NDVI 的栅格列表中创建一个栅格集合,然后返回该集合中每个像素的最大 NDVI 值。

# Import system modules
import arcpy
from arcpy.ia import *
from arcpy import env

# Set workspace
arcpy.env.workspace = "C:/Data/NDVI"

# Get the list of tiff files from the workspace
NDVI_tiff_list = arcpy.ListRasters("*", "TIF")

# Generate a list of raster file names without the .tif extension 
name_list = []
for NDVI in NDVI_tiff_list:
    name_list.append(NDVI.replace(".tif","")

# Construct a collection from the list of raster file names
rc = RasterCollection(NDVI_tiff_list, {'name':name_list})

# Return a raster object where every pixel contains the 
# maximum value of that pixel over the entired NDVI raster collection
max_NDVI_rc = rc.max()

# Save the new raster object
max_NDVI_rc.save(r'C:\output\max_NDVI_raster.tif')
RasterCollection 示例 5(Python 窗口)

Python 函数映射到栅格集合以生成新集合。

# Import system modules
import arcpy
from arcpy.ia import *

arcpy.CheckOutExtension("ImageAnalyst")

# Construct a collection from a mosaic dataset
rc = RasterCollection(r'C:\Data.gdb\Landsat8_TimeSeries')

# Define a Python function to calculate the Soil Adjusted Vegetation Index (SAVI) 
def SAVI(item):
	# Get the raster object from the item
	raster = item['Raster']
	# Get the raster objects for the NIR and Red bands
	Red_band, NIR_band = raster.getRasterBands(["red","nir"])
	# Compute the index
	savi_index = ((1.5 * (NIR_band - Red_band))/(NIR_band + Red_band + 0.5))
	return{"raster": savi_index, "name": "Soil_Adjusted_Vegetation_Index", "StdTime":item['AcquisitionDate']}
	
# Run the Python function over the raster collection and generate a new collection
SAVI_rc = rc.map(SAVI)

# save it as a multidimensional raster
mdim_raster = SAVI_rc.toMultidimensionalRaster(variable_field_name = "name", dimension_field_names = "StdTime")
mdim_raster.save(r'C:\output\time_series_SAVI_raster.crf')
RasterCollection 示例 6(Python 窗口)

空间时间资产目录 (STAC) API 搜索查询创建一个 RasterCollection 对象。

# Import system modules
from arcpy.ia import *
from arcpy import AIO

# 1) Creates a raster collection from Earth Search STAC API

# Defining query parameters
query_params = {
    "collections": ["sentinel-2-l2a"],
    "bbox": [-110, 39.5, -105, 40.5],
    "query": {"eo:cloud_cover": {"lt": 10}},
    "datetime": "2020-10-05T00:00:00Z/2020-10-10T12:31:12Z",
    "limit": 5,
}
 
# Define attribute dictionary using the STAC Item properties
attribute_dict = {
    "Name": "id",
    "Platform": "platform",
    "StdTime": "datetime",
    "Cloud Cover": "eo:cloud_cover",
    "Spatial Reference": "proj:epsg",
    "Extent": "bbox",
}
 
# Construct a collection from the Sentinel-2 L2A data accesible through Earth Search STAC API

sentinel_2_rc = RasterCollection.fromSTACAPI(
    stac_api="https://earth-search.aws.element84.com/v1",
    query=query_params,
    attribute_dict=attribute_dict,
)

# Filter the collection further to work with data only from the Sentinel-2A satellite
filtered_rc = sentinel_2_rc.filterByAttribute("Platform", "EQUALS", "sentinel-2a")

# 2) Creates a raster collection from Planetray computer STAC API

# Defining query parameters
query_params = {
    "collections": ["naip"],
    "bbox": [-122.2751, 47.5469, -121.9613, 47.7458],
    "datetime": "2018-12-01/2020-12-31",
    "limit": 5,
}
 
# Define attribute dictionary using the STAC Item properties
attribute_dict = {
    "Name": "id",
    "GSD": "gsd",
    "StdTime": "datetime",
    "State": "naip:state",
    "Spatial Reference": "proj:epsg",
    "Extent": "bbox",
}
 
# Construct a collection from the NAIP data accesible through Planetary Computer STAC API
naip_rc = RasterCollection.fromSTACAPI(
    stac_api="https://planetarycomputer.microsoft.com/api/stac/v1",
    query=query_params,
    attribute_dict=attribute_dict,
)
 
# Define a Python function to map grayscale raster function to the whole collection
def grayscale(item):
    # Get the raster object from the item
    raster = item["Raster"]
    # Get the raster objects for the NIR and Red bands
    gray_raster = Grayscale(raster)
    # Compute the index
    return {
        "raster": gray_raster,
        "name": f"gray_{item['Name']}",
        "StdTime": item["StdTime"],
    }
 
# apply grayscale function to each raster item in the raster collection using the map function
gray_rc = naip_rc.map(grayscale)
 
# work with the first raster in the grayscale collection
gray_raster_1 = gray_rc[0]["Raster"]

# 3) Creates a raster collection from the Landsat-9 C2-L2 data accesible through

# Digital Earth Africa STAC API (with custom asset selection) - Requires acs (AIO object).

landsat_dea_acs = AIO(r"C:\acsfiles\s3_dea_landsat.acs")

landsat_dea_rc = RasterCollection.fromSTACAPI(
      stac_api="https://explorer.digitalearth.africa/stac",
      query={
	"collections": ["ls9_sr"],
	"bbox": [
	        25.982987096443583,
	        29.249912751222965,
	        28.30879111403085,
	        31.348538968581714,
	      ],
	     "datetime": "2023-12-25/2023-12-31",
	},
	attribute_dict={
	    "Name": "id",
	    "Sensor": "platform",
	    "Cloud Cover": "eo:cloud_cover",
	    "Row": "landsat:wrs_row",
	    "Path": "landsat:wrs_path",
	},
	context={"assetManagement": ["SR_B4", "SR_B3", "SR_B2"]}, # rgb
)
RasterCollection 示例 7(Python 窗口)

从静态时空资产目录 (STAC) 目录创建一个 RasterCollection 对象。

# Import system modules
from arcpy.ia import *

# 1) Creates a raster collection from Maxar STAC (Static Catalog)

# Define attribute dictionary using the STAC Item properties
attribute_dict = {
    "Name": "id",
    "Platform": "platform",
    "StdTime": "datetime",
    "Data Area": "tile:data_area",
    "Clouds Percent": "tile:clouds_percent",
    "Spatial Reference": "proj:epsg",
}

# Construct a collection from Maxar STAC

     maxar_rc = RasterCollection.fromSTACCatalog(
     stac_catalog="https://maxar-opendata.s3.amazonaws.com/events/Emilia-Romagna-Italy-flooding-may23/ard/acquisition_collections/103005009DF96A00_collection.json",
     attribute_dict=attribute_dict,
)

# Filter the collection further to only work with data that has tile area less than 15 square kilometer

filtered_rc =maxar_rc.filterByAttribute("Data Area", "LESS_THAN", 15)

# 2) Creates a raster collection from New Zealand Imagery STAC (Static Catalog)

# Define attribute dictionary using the STAC Item properties
attribute_dict = {
   "Name": "id",
   "Start StdTime": "start_datetime",
   "End StdTime": "end_datetime",
   "Extent": "bbox",
}

# Construct a collection from New Zealand Imagery STAC

     nz_rc = RasterCollection.fromSTACCatalog(
     stac_catalog="https://nz-imagery.s3-ap-southeast-2.amazonaws.com/tasman/tasman_snc30002_2002_0.75m/rgb/2193/collection.json",
     attribute_dict=attribute_dict,
)

# Define a Python function to map grayscale raster function to the whole collection

def grayscale(item):
	# Get the raster object from the item
	raster = item["Raster"]

	# Get the raster objects for the NIR and Red bands
	gray_raster = Grayscale(raster)

	# Compute the index
	return {
		"raster": gray_raster,
		"name": f"gray_{item['Name']}",
		"StdTime": item["Start StdTime"],
		}

# apply grayscale function to each raster item in the raster collection using the map function

gray_rc = nz_rc.map(grayscale)

# work with the first raster in the grayscale collection

gray_raster_1 = gray_rc[8]["Raster"]

#3) Creates a raster collection from UMBRA STAC (with custom asset selection)

umbra_rc = RasterCollection.fromSTACCatalog(
stac_catalog="https://s3.us-west-2.amazonaws.com/umbra-open-data-catalog/stac/2024/2024-02/2024-02-19/catalog.json",
       attribute_dict={
	"Name": "id",
	"Sensor": "platform",
	"StdTime": "datetime",
	"Polarizations": "sar:polarizations",
	"Extent": "bbox",
	},
	context={"assetManagement": ["GEC"]},
	)