Filter
# 简介
过滤器对象(Filter)支持ImageCollection和FeatureCollection的数据过滤,支持空间范围、日期和属性字段的过滤。
# And
过滤对象与连接。
函数 | 返回值 |
---|---|
And(filter) | Filter |
参数 | 类型 | 说明 |
---|---|---|
filter | Filter | 过滤对象 |
# 示例
f1 = pie.Filter.lt('date','2019-12-14')
f2 = pie.Filter.gt('date', '2019-11-12')
f = f1.And(f2)
# bounds
生成过滤器用于筛选过滤对象中与给定空间范围相交的部分。
函数 | 返回值 |
---|---|
bounds(geometry) | Filter |
参数 | 类型 | 说明 |
---|---|---|
geometry | 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)
imageCollection = pie.ImageCollection("LC08/01/T1")
res = imageCollection.filter(pie.Filter.date('2019-01-01','2019-03-01')).filter(pie.Filter.bounds(geometry))
print(res.size().getInfo())
# calendarRange
如果对象的时间戳在日历字段的给定范围内,则返回一个筛选器。月份、每年的第几天、每月的第几天和每周的第几天都以1为基础。假设时间为UTC。假设星期一开始为第一天。如果end<start,并且value>=start或value<=end,则通过。
函数 | 返回值 |
---|---|
calendarRange(start, end, field) | Filter |
参数 | 类型 | 说明 |
---|---|---|
start | Int | 所需日历字段的开始,包括该值。 |
end | Int | 所需日历字段的结尾,包括该值。默认为与“开始”相同的值。 |
field | String | 要筛选的日历字段。选项包括:’year', 'month', 'hour', 'minute', 'day_of_year', 'day_of_month', and 'day_of_week'。默认为"day_of_year" |
# 示例
imageCollection = pie.ImageCollection("LC08/01/T1_SR")
filter = pie.Filter.calendarRange(2020, 2020,"year").calendarRange(1, 2,"month")
images_result = imageCollection.filter(filter)
print(images_result.size().getInfo())
# contains
生成过滤器,用于筛选过滤对象中包含于给定空间范围的部分。
函数 | 返回值 |
---|---|
contains(geo) | Filter |
参数 | 类型 | 说明 |
---|---|---|
geo | Geometry | 过滤空间范围 |
# 示例
geometry0 = pie.Geometry.Polygon([
[
[
108.30748338729393,
40.778219603719776
],
[
124.76684548237449,
40.778219603719776
],
[
124.76684548237449,
28.57306444267688
],
[
108.30748338729393,
28.57306444267688
],
[
108.30748338729393,
40.778219603719776
]
]
], None)
geoFilter = pie.Filter.contains(geometry0)
imageCollection0 = pie.ImageCollection('LC08/01/T1_SR')
resumeFeature = imageCollection0.filter(geoFilter)
print(resumeFeature.size().getInfo())
# date
生成过滤器用于筛选过滤对象中在给定时间范围内的部分。
函数 | 返回值 |
---|---|
date(start, end) | Filter |
参数 | 类型 | 说明 |
---|---|---|
start | String | 过滤起始日期(包含) |
end | String | 过滤终止日期(不包含) |
# 示例
imageCollection0 = pie.ImageCollection('LE07/01/T1')
filter = pie.Filter.date("2019-12-01", "2019-12-31")
filter_image = imageCollection0.filter(filter)
print(filter_image.size().getInfo())
# dayOfYear
返回一个筛选器,如果对象的时间戳在给定的日期范围内则通过。
函数 | 返回值 |
---|---|
dayOfYear(start, end) | Filter |
参数 | 类型 | 说明 |
---|---|---|
start | Int | 所需日期范围的开始,包括当前值。从1-366。 |
end | Int | 所需日期范围的结束,不包括当前值。从1-366。 |
# 示例
imageCollection = pie.ImageCollection('H08/AHI-L1-G')
images_result = imageCollection.filter(pie.Filter.dayOfYear(200, 250))
count = images_result.size()
print(count.getInfo())
# eq
生成过滤器,用于筛选过滤对象中指定属性的值等于给定值的对象。
函数 | 返回值 |
---|---|
eq(name, value) | Filter |
参数 | 类型 | 说明 |
---|---|---|
name | Stirng | 属性的名称 |
value | Int | 属性的值 |
# 示例
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)
imageCollection = pie.ImageCollection("LC08/01/T1")
res = imageCollection.filter(pie.Filter.eq("date","2019-11-14")).filterBounds(geometry)
print(res.size().getInfo())
# gt
生成过滤器,用于筛选过滤对象中指定属性值大于给定值的对象。
函数 | 返回值 |
---|---|
gt(name, value) | Filter |
参数 | 类型 | 说明 |
---|---|---|
name | Stirng | 属性名 |
value | Int | 属性值 |
# 示例
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)
imageCollection = pie.ImageCollection("LC08/01/T1")
res = imageCollection.filter(pie.Filter.date('2019-01-01','2019-03-01')).filter(pie.Filter.gt("date","2019-02-01")).filterBounds(geometry)
print(res.size().getInfo())
# gte
生成过滤器,用于筛选过滤对象中指定属性值大于等于给定值的对象。
函数 | 返回值 |
---|---|
gte(name, value) | Filter |
参数 | 类型 | 说明 |
---|---|---|
name | Stirng | 属性名 |
value | Int | 属性值 |
# 示例
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)
imageCollection = pie.ImageCollection("LC08/01/T1")
filter = pie.Filter()
res = imageCollection.filter(filter.date('2019-01-01','2019-03-01')).filter(filter.gte("date","2019-02-01")).filterBounds(geometry)
print(res.size().getInfo())
# inList
返回一个筛选器,如果对象的指定字段值包含于给定的数组内则通过。
函数 | 返回值 |
---|---|
inList(field, list) | Filter |
参数 | 类型 | 说明 |
---|---|---|
field | String | 指定的字段 |
list | Array | 指定的数组 |
# 示例
imageCollection=pie.ImageCollection('LC08/01/T1_SR')
cloudFilter=pie.Filter.inList("cloudCover",[2.39, 24.34, 94.53, 25.1, 30.9])
images_result=imageCollection.filter(cloudFilter)
print(images_result.size().getInfo())
# lt
生成过滤器,用于筛选过滤对象中指定属性值小于给定值的对象。
函数 | 返回值 |
---|---|
lt(name, value) | Filter |
参数 | 类型 | 说明 |
---|---|---|
name | Stirng | 属性名 |
value | Int | 属性值 |
# 示例
imageCollection0 = pie.ImageCollection('LC08/01/T1_SR')
f1 = pie.Filter.lt('date', "2015-1-1")
imageCollection0 = imageCollection0.filter(f1)
print(imageCollection0.size().getInfo())
# lte
生成过滤器,用于筛选过滤对象中指定属性值小于等于给定值的对象。
函数 | 返回值 |
---|---|
lte(name, value) | Filter |
参数 | 类型 | 说明 |
---|---|---|
name | Stirng | 属性名 |
value | Int | 属性值 |
# 示例
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)
imageCollection = pie.ImageCollection("LC08/01/T1")
res = imageCollection.filter(pie.Filter.date('2019-01-01','2019-03-01')).filter(pie.Filter.lte("date","2019-02-01")).filterBounds(geometry)
print(res.size().getInfo())
# maxDifference
返回一个筛选器,如果对象的指定字段值在给定参考值的给定数值范围内则通过。
函数 | 返回值 |
---|---|
maxDifference(difference, name, value) | Filter |
参数 | 类型 | 说明 |
---|---|---|
difference | Number | 筛选器将返回True的最大差值 |
name | String | 字段名称 |
value | Number | 参考值 |
# 示例
imageCollection = pie.ImageCollection('LC08/01/T1_SR')
filter = pie.Filter.maxDifference(10,"cloudCover",20)
images_result = imageCollection.filter(filter)
print(images_result.size().getInfo())
# neq
生成过滤器,用于筛选过滤对象中指定属性的值不等于给定值的对象。
函数 | 返回值 |
---|---|
neq(name, value) | Filter |
参数 | 类型 | 说明 |
---|---|---|
name | Stirng | 属性名 |
value | Int | 属性值 |
# 示例
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)
imageCollection = pie.ImageCollection("LC08/01/T1")
res = imageCollection.filter(pie.Filter.date('2019-01-01','2019-03-01')).filter(pie.Filter.neq("date","2019-01-07")).filterBounds(geometry)
print(res.size().getInfo())
# Not
返回一个筛选器,若当前筛选器结果为不通过则通过。
函数 | 返回值 |
---|---|
Not(rightFilter) | Filter |
参数 | 类型 | 说明 |
---|---|---|
rightFilter | Filter | 当前筛选器 |
# 示例
imageCollection = pie.ImageCollection('LC08/01/T1_SR').filterDate("2019-12-01", "2019-12-31")
filter = pie.Filter.maxDifference(10,"cloudCover","20")
notFilter = pie.Filter.Not(filter)
images_result = imageCollection.filter(notFilter)
print(images_result.size().getInfo())
# notNull
返回一个筛选器,如果过滤对象的所有指定属性的属性值都不为空则通过。
函数 | 返回值 |
---|---|
notNull(list) | Filter |
参数 | 类型 | 说明 |
---|---|---|
list | Array | 属性名列表 |
# 示例
imageCollection = pie.ImageCollection('LC08/01/T1_SR').filterDate("2019-12-01", "2019-12-31")
filter = pie.Filter.notNull(["sceneId","sensorId"])
images_result = imageCollection.filter(filter)
print(images_result.size().getInfo())
# Or
过滤对象或连接。
函数 | 返回值 |
---|---|
Or(filter) | Filter |
参数 | 类型 | 说明 |
---|---|---|
filter | Filter | 过滤对象 |
# 示例
filter1 = pie.Filter.eq("date","2019-11-14");
filter2 = pie.Filter.eq("date","2019-12-14").Or(filter1);
# stringContains
返回一个筛选器,如果过滤对象中指定属性的值中包含指定值则通过。
函数 | 返回值 |
---|---|
stringContains(name, value) | Filter |
参数 | 类型 | 说明 |
---|---|---|
name | String | 属性名 |
value | object | 指定值 |
# 示例
imageCollection = pie.ImageCollection('LC08/01/T1_SR')
filter = pie.Filter.stringContains("sceneId","LC8119038")
images_result = imageCollection.filter(filter)
print(images_result.size().getInfo())
# stringEndsWith
返回一个筛选器,如果过滤对象中指定属性的值以指定值为结尾则通过。
函数 | 返回值 |
---|---|
stringEndsWith(name, value) | Filter |
参数 | 类型 | 说明 |
---|---|---|
name | String | 属性名 |
value | Object | 指定值 |
# 示例
imageCollection = pie.ImageCollection('LC08/01/T1_SR')
filter = pie.Filter.stringEndsWith("sceneId","LGN02")
images_result = imageCollection.filter(filter)
print(images_result.size().getInfo())
# stringStartsWith
返回一个筛选器,如果过滤对象中指定属性的值以指定值为开头则通过。
函数 | 返回值 |
---|---|
stringStartsWith (name, value) | Filter |
参数 | 类型 | 说明 |
---|---|---|
name | String | 属性名 |
value | Object | 指定值 |
# 示例
imageCollection = pie.ImageCollection('LC08/01/T1_SR')
filter = pie.Filter.stringStartsWith("sceneId","LC8119038")
images_result = imageCollection.filter(filter)
print(images_result.size().getInfo())
# withinDistance
生成过滤器,用于筛选过滤对象中距离给定空间范围的距离在预定距离内的部分。
函数 | 返回值 |
---|---|
withinDistance(geo, distance, proj) | Filter |
参数 | 类型 | 说明 |
---|---|---|
geo | Geometry | 过滤空间范围 |
distance | Number | 预定距离,默认单位是米,如果是度,需要设置proj为地理坐标系 |
proj | Dictionary | 坐标系,指定distance的单位;可以WKT串也可以是EPSG编码表示方式 |
# 示例
polygon = pie.Geometry.Polygon([[[120, 30], [120, 31], [121, 31], [121, 30],[120, 30]]],None)
imageCollection = pie.ImageCollection('LC08/01/T1_SR')
filter = pie.Filter.withinDistance(polygon,1000000,None)
images_result = imageCollection.filter(filter)
print(images_result.size().getInfo())