ImageCollection
# 简介
影像集(ImageCollection)是PIE-Engine中的影像集合对象,包含一个或多个Image对象。PIE-Engine Studio提供构建影像集算子及影像集相关算法,包括但不限于加载影像集、获取影像集属性信息、影像过滤、影像拼接、统计计算、影像集内Image循环计算。
# ImageCollection
构造函数。
函数 | 返回值 |
---|---|
ImageCollection(args,columns) | ImageCollection |
参数 | 类型 | 说明 |
---|---|---|
args | String | 数据路径 |
# 示例
imageCollection = pie.ImageCollection("LC08/01/T1")
# filter
对ImageCollection对象通过指定过滤器进行过滤,返回过滤后的ImageCollection对象。
函数 | 返回值 |
---|---|
filter(self,pieFilter) | ImageCollection |
参数 | 类型 | 说明 |
---|---|---|
pieFilter | Json对象 | 过滤方法 |
# 示例
geometry = pie.Geometry.Polygon([[
[
119.3491304643045,
41.93963532628737
],
[
119.59902198978665,
41.810901313779254
],
[
119.80720978302583,
41.95876844737799
],
[
119.57030643209589,
42.04057148950443
],
[
119.3491304643045,
41.93963532628737
]
]], None)
filter = pie.Filter().date('2019-01-01','2019-03-01')
imageCollection = pie.ImageCollection("LC08/01/T1")
imageCollection = imageCollection.filter(filter).filterBounds(geometry)
print(imageCollection.size().getInfo())
# filterBounds
对ImageCollection对象进行空间范围过滤,筛选出在给定空间范围内的影像,返回过滤后的ImageCollection对象。
函数 | 返回值 |
---|---|
filterBounds(self,geometry) | ImageCollection |
参数 | 类型 | 说明 |
---|---|---|
Geometry | Json | 矢量数据范围 |
# 示例
polygon = pie.Geometry.Polygon([[[120, 41], [121, 41], [121, 42], [120, 42],[120, 41]]], None)
imageCollection = pie.ImageCollection().load("LC08/01/T1").filterBounds(polygon).filterDate("2019-01-01","2019-01-10")
# filterDate
对ImageCollection对象通过日期进行过滤,筛选出在给定时间范围内的影像,返回过滤后的ImageCollection对象。
函数 | 返回值 |
---|---|
filterDate(self,start,end) | ImageCollection |
参数 | 类型 | 说明 |
---|---|---|
start | string | 开始过滤日期(包括) |
end | string | 结束过滤日期(不包括) |
# 示例
imageCollection = pie.ImageCollection("LC08/01/T1")
imageCollection = imageCollection.filterDate("2019-01-06","2019-01-09")
print(imageCollection.size().getInfo())
# first
获得ImageCollection对象中的第一个Image对象。
函数 | 返回值 |
---|---|
first() | Image |
# 示例
imageCollection = pie.ImageCollection("LC08/01/T1").filterDate("2019-12-01", "2019-12-31")
image = imageCollection.first()
print(image.getInfo())
# fromImages
根据Image列表构建ImageCollection对象。
函数 | 返回值 |
---|---|
fromImages(args) | ImageCollection |
参数 | 类型 | 说明 |
---|---|---|
args | Array | 影像数据列表 |
# 示例
image1 = pie.Image("LC08/01/T1/LC08_121031_20171203").select("B3")
image2 = pie.Image("LC08/01/T1/LC08_121032_20191225").select("B3")
imageCollection = pie.ImageCollection().fromImages([image1,image2])
# get
根据属性名获得ImageCollection下的属性值信息。
函数 | 返回值 |
---|---|
get(key) | String|Number|Boolean|Object|List |
参数 | 类型 | 说明 |
---|---|---|
key | String | 属性名 |
# 示例
imageCollection = pie.ImageCollection("LC08/01/T1").filterDate("2019-12-01", "2019-12-02")
imageCollection = imageCollection.set("key1", {'name':123})
value = imageCollection.get("key1")
print(value.getInfo())
# getAt
获得ImageCollection对象中指定编号的Image对象。
函数 | 返回值 |
---|---|
getAt(index) | Image |
参数 | 类型 | 说明 |
---|---|---|
index | Number | Image的编号 |
# 示例
imageCollection = pie.ImageCollection("LC08/01/T1").filterDate("2019-12-01", "2019-12-31")
image = imageCollection.getAt(0)
print(image.getInfo())
# getNumber
根据属性名获得ImageCollection下的属性值信息,并且将其转换为数值类型。
函数 | 返回值 |
---|---|
getNumber(property) | Number |
参数 | 类型 | 说明 |
---|---|---|
property | String | 属性名 |
# 示例
imageCollection = pie.ImageCollection("LC08/01/T1").filterDate("2019-12-01", "2019-12-02")
dict = {'key1': {'name':"abc", 'value':123}, 'key2': 12.34, 'key3': "12.34"}
imageCollection = imageCollection.setMulti(dict)
value = imageCollection.getString("key3").getInfo()
print(value)
# getString
根据属性名获得ImageCollection下的属性值信息,并且将其转换为字符串类型。
函数 | 返回值 |
---|---|
getString(property) | String |
参数 | 类型 | 说明 |
---|---|---|
property | String | 属性名 |
# 示例
imageCollection = pie.ImageCollection("LC08/01/T1").filterDate("2019-12-01", "2019-12-02")
dict = {'key1': {'name':"abc", 'value':123}, 'key2': 12.34, 'key3': "12.34"}
imageCollection = imageCollection.setMulti(dict)
value = imageCollection.getString("key2").getInfo()
print(value)
# id
返回ImageCollection对象的id。
函数 | 返回值 |
---|---|
id() | String |
# 示例
imageCollection = pie.ImageCollection("LC08/01/T1").filterDate("2019-12-01", "2019-12-02")
id = imageCollection.id()
print(id.getInfo())
# load
根据提供路径加载ImageCollection对象,一般在ImageCollection初始化的时候会默认调用该方法。
函数 | 返回值 |
---|---|
load(id) | ImageCollection |
参数 | 类型 | 说明 |
---|---|---|
id | String | 数据路径 |
# 示例
imageCollection = pie.ImageCollection.load("LC08/01/T1")
# map
针对ImageCollection中的每个Image用同一函数进行循环计算,返回运算结果的ImageCollection。
函数 | 返回值 |
---|---|
map(algorithm,dropNulls) | ImageCollection |
参数 | 类型 | 说明 |
---|---|---|
algorithm | Function | 参数是Image的方法,需要返回Image |
dropNulls | Boolean | 是否允许返回空值; |
# 示例
imageCollection = pie.ImageCollection("LC08/01/T1").filterDate("2019-12-01", "2019-12-31")
imageCollectionNDVI = imageCollection.map(lambda image: image.select("B5").
subtract(image.select("B4")).divide(image.select("B5").add(image.select("B4"))), True)
# max
对ImageCollection中的Image进行最大值计算,返回一个将ImageCollection中每个影像对应波段的对应像素值求最大值得到的Image对象。
函数 | 返回值 |
---|---|
max() | Image |
# 示例
geometry = pie.Geometry.Polygon([[
[
119.3491304643045,
41.93963532628737
],
[
119.59902198978665,
41.810901313779254
],
[
119.80720978302583,
41.95876844737799
],
[
119.57030643209589,
42.04057148950443
],
[
119.3491304643045,
41.93963532628737
]
]], None)
filter = pie.Filter().date('2019-01-01','2019-03-01')
imageCollection = pie.ImageCollection("LC08/01/T1")
imageCollection = imageCollection.filter(filter).filterBounds(geometry)
image = imageCollection.max()
print(image.getInfo())
# mean
对ImageCollection中的Image进行平均值计算,返回一个将ImageCollection中每个影像对应波段的对应像素值求均值得到的Image对象。
函数 | 返回值 |
---|---|
mean() | Image |
# 示例
geometry = pie.Geometry.Polygon([[
[
119.3491304643045,
41.93963532628737
],
[
119.59902198978665,
41.810901313779254
],
[
119.80720978302583,
41.95876844737799
],
[
119.57030643209589,
42.04057148950443
],
[
119.3491304643045,
41.93963532628737
]
]], None)
filter = pie.Filter().date('2019-01-01','2019-03-01')
imageCollection = pie.ImageCollection("LC08/01/T1")
imageCollection = imageCollection.filter(filter).filterBounds(geometry)
image = imageCollection.mean()
print(image.getInfo())
# median
对ImageCollection中的Image进行中值计算,返回一个将ImageCollection中每个影像对应波段的对应像素值求中值得到的Image对象。
函数 | 返回值 |
---|---|
median() | Image |
# 示例
geometry = pie.Geometry.Polygon([[
[
119.3491304643045,
41.93963532628737
],
[
119.59902198978665,
41.810901313779254
],
[
119.80720978302583,
41.95876844737799
],
[
119.57030643209589,
42.04057148950443
],
[
119.3491304643045,
41.93963532628737
]
]], None)
filter = pie.Filter().date('2019-01-01','2019-03-01')
imageCollection = pie.ImageCollection("LC08/01/T1")
imageCollection = imageCollection.filter(filter).filterBounds(geometry)
image = imageCollection.median()
print(image.getInfo())
# min
对ImageCollection中的Image进行最小值计算,返回一个将ImageCollection中每个影像对应波段的对应像素值求最小值得到的Image对象。
函数 | 返回值 |
---|---|
min() | Image |
# 示例
geometry = pie.Geometry.Polygon([[
[
119.3491304643045,
41.93963532628737
],
[
119.59902198978665,
41.810901313779254
],
[
119.80720978302583,
41.95876844737799
],
[
119.57030643209589,
42.04057148950443
],
[
119.3491304643045,
41.93963532628737
]
]], None)
filter = pie.Filter().date('2019-01-01','2019-03-01')
imageCollection = pie.ImageCollection("LC08/01/T1")
imageCollection = imageCollection.filter(filter).filterBounds(geometry)
image = imageCollection.min()
print(image.getInfo())
# mosaic
对ImageCollection中的Image进行镶嵌,返回一个镶嵌合成后的Image对象。
函数 | 返回值 |
---|---|
mosaic() | Image |
# 示例
geometry = pie.Geometry.Polygon([[
[
119.3491304643045,
41.93963532628737
],
[
119.59902198978665,
41.810901313779254
],
[
119.80720978302583,
41.95876844737799
],
[
119.57030643209589,
42.04057148950443
],
[
119.3491304643045,
41.93963532628737
]
]], None)
filter = pie.Filter().date('2019-01-01','2019-03-01')
imageCollection = pie.ImageCollection("LC08/01/T1")
imageCollection = imageCollection.filter(filter).filterBounds(geometry)
image = imageCollection.mosaic()
print(image.getInfo())
# propertyNames
返回ImageCollection对象的属性信息。
函数 | 返回值 |
---|---|
propertyNames() | List |
# 示例
imageCollection = pie.ImageCollection("LC08/01/T1").filterDate("2019-12-01", "2019-12-02")
imageCollection = imageCollection.set("key1", {'name':123})
propertyNames = imageCollection.propertyNames().getInfo()
print(propertyNames)
# qualityMosaic
使用质量波段作为参考,对ImageCollection中的Image进行镶嵌,返回一个镶嵌合成后的Image对象。
函数 | 返回值 |
---|---|
qualityMosaic(args) | Image |
参数 | 类型 | 说明 |
---|---|---|
args | String | 质量波段的名称 |
# 示例
geometry = pie.Geometry.Polygon([[
[
119.3491304643045,
41.93963532628737
],
[
119.59902198978665,
41.810901313779254
],
[
119.80720978302583,
41.95876844737799
],
[
119.57030643209589,
42.04057148950443
],
[
119.3491304643045,
41.93963532628737
]
]], None)
filter = pie.Filter().date('2019-01-01','2019-03-01')
imageCollection = pie.ImageCollection("LC08/01/T1")
imageCollection = imageCollection.filter(filter).filterBounds(geometry)
image = imageCollection.qualityMosaic("B1")
print(image.getInfo())
# reduce
将一个统计器应用到影像集合中的所有影像。如果统计器有单一输入,则该统计器将被分别应用于该影像集中所有波段;否则输入个数需与影像集波段数一致。 输出波段名由统计器的输出名决定:多输入值的统计器将直接运用输出名,单一输入的统计器将在输出名前加输入波段的名称作为前缀。
函数 | 返回值 |
---|---|
reduce(reducer) | Image |
参数 | 类型 | 说明 |
---|---|---|
reducer | Reducer | 统计计算器 |
# 示例
filterCloud = pie.Filter.lte("cloudCover",5)
filterPro1 = pie.Filter.eq("wrsPath","119")
filterPro2 = pie.Filter.eq("wrsRow","38")
imageCollection = pie.ImageCollection().load("LC08/01/T1_SR").filterDate("2013-04-01", "2020-01-01").filter(filterCloud).filter(filterPro1).filter(filterPro2)
result = imageCollection.reduce(pie.Reducer.first())
Map = pie.Map()
Map.addLayer(result.select("B1"),{'min':0,'max':2000},"Layer")
Map.setCenter(120,31.5,7)
Map
# reduceColumns
根据指定selector中的属性值将统计器运用于一个ImageCollection中的所有元素,返回结果为以输出结果名为键的字典对象。
函数 | 返回值 |
---|---|
reduceColumns(self,reducer,selector,weightSelectors) | Dictionary |
参数 | 类型 | 说明 |
---|---|---|
reducer | Reducer | 统计器,目前仅支持toList统计器 |
selector | Array | 要统计的属性列表 |
weightSelectors | Array | 默认为None |
# 示例
filter = pie.Filter.eq("date","2019-11-14")
imageCollection = pie.ImageCollection("LC08/01/T1").filter(filter).select("B3")
value = imageCollection.reduceColumns(pie.Reducer.toList(2),['cloudCover','sceneId'])
print(value.getInfo())
# select
根据波段名称从ImageCollection中选择波段,返回一个ImageCollection对象。
函数 | 返回值 |
---|---|
select(args) | ImageCollection |
参数 | 类型 | 说明 |
---|---|---|
args | String|Array | 波段名称或波段名称列表 |
# 示例
polygon = pie.Geometry.Polygon([[[120, 41], [121, 41], [121, 42], [120, 42],[120, 41]]], None)
imageCollection = pie.ImageCollection().load("LC08/01/T1").filterBounds(polygon).filterDate("2019-01-01","2019-01-10")
print(imageCollection.size().getInfo())
print(imageCollection.select('B3').getInfo())
# set
设置ImageCollection下的属性信息,如果存在就覆盖更新,如果不存在则直接创建。
函数 | 返回值 |
---|---|
set(key,value) | Void |
参数 | 类型 | 说明 |
---|---|---|
key | String | 属性名 |
value | String|Number|Boolean|Object|List | 属性值 |
# 示例
imageCollection = pie.ImageCollection("LC08/01/T1").filterDate("2019-12-01", "2019-12-02")
imageCollection = imageCollection.set("key1", {'name':123})
value = imageCollection.get("key1").getInfo()
print(value)
# setMaskValue
对ImageCollection中的Image设置过滤值,返回过滤后的ImageCollection对象。
函数 | 返回值 |
---|---|
setMaskValue(value) | ImageCollection |
参数 | 类型 | 说明 |
---|---|---|
value | Number | 过滤值 |
# 示例
geometry = pie.Geometry.Polygon([[
[
116.29721542611139,
39.961859016358545
],
[
116.30175848687782,
39.8352246197168
],
[
116.46530867451116,
39.83755029383428
],
[
116.46379432092459,
39.96534105732522
],
[
116.29721542611139,
39.961859016358545
]
]], None)
l8collection = pie.ImageCollection('LC08/01/T1').filterBounds(geometry).filterDate("2019-01-01","2019-01-08").setMaskValue(3000)
print(l8collection.size().getInfo())
print(l8collection.getInfo())
# setMulti
批量设置ImageCollection下的属性信息,如果存在就覆盖更新,如果不存在则直接创建。
函数 | 返回值 |
---|---|
setMulti(properties) | Void |
参数 | 类型 | 说明 |
---|---|---|
properties | Dictionary | 属性键值对,以字典形式传入 |
# 示例
imageCollection = pie.ImageCollection("LC08/01/T1").filterDate("2019-12-01", "2019-12-02")
dict = {'key1': {'name':"abc", 'value':123}, 'key2': 12.34, 'key3': "12.34"}
imageCollection = imageCollection.setMulti(dict)
print(imageCollection.getInfo())
# size
获得ImageCollection中Image的个数。
函数 | 返回值 |
---|---|
size() | Number |
# 示例
imageCollection = pie.ImageCollection("LC08/01/T1").filterDate("2019-12-01", "2019-12-31")
print(imageCollection.size().getInfo())
# sum
对ImageCollection中的Image进行求和计算,返回一个将ImageCollection中每个影像对应波段的对应像素值求和得到的Image对象。
函数 | 返回值 |
---|---|
sum() | Image |
# 示例
geometry = pie.Geometry.Polygon([[
[
119.3491304643045,
41.93963532628737
],
[
119.59902198978665,
41.810901313779254
],
[
119.80720978302583,
41.95876844737799
],
[
119.57030643209589,
42.04057148950443
],
[
119.3491304643045,
41.93963532628737
]
]], None)
filter = pie.Filter().date('2019-01-01','2019-03-01')
imageCollection = pie.ImageCollection("LC08/01/T1")
imageCollection = imageCollection.filter(filter).filterBounds(geometry)
image = imageCollection.sum()
print(image.getInfo())