过滤筛选就是从数据中筛选出符合条件的数据,比如在海量的Landsat数据中选出符合你的研究区间和研究时间内的数据。
在GEE中实现过滤的方法叫做Filter,主要的过滤规则可分为:
具体方法有:
ee.Filter.eq() ee.Filter.neq() ee.Filter.ge() ee.Filter.gte() ee.Filter.le()
ee.Filter.lte()
ee.Filter.maxDifference()
ee.Filter.stringContains() ee.Filter.StarsWith() ee.Filter.EndWith()
ee.Filter.Rangecontains() ee.Filter.listContains() ee.Filter.inList()
ee.Filter.calendarRange() ee.FilterDateRangeContains() ee.Filter.dayOfYear()
ee.Filter.and() ee.Filter.or() ee.Filter.not() ee.Filter()
// ee.Filter.and = ee.Filter
var filter_1 = ee.Filter.eq/neq/gt/gte/lt/lte('字段','字段值');
// eq/ neq/ gt/ gte/ lt/ lte
// equales/ notEquals/ greaterThan/ greaterThanOrEquals/ lessThan/ lessThanOrEquals
//关系进行判断,返回筛选器
var result_filter = (FeatureCollection/ImageCollection).fliter(filter_1);
//此时筛选结果仍为Collection类型。
若返回非Collection类型,如下所示:
var result_filter = (FeatureCollection/ImageCollection).fliter(filter_1).first();
var CQ_Area = CQ.get('Shape_Area')
var Smaller_Than_CQ_Filter = ee.Filter.lt('Shape_Area',CQ_Area) // 筛选出面积比CQ小的元素
var Smaller_Than_CQ_Provinces = China_Provinces.filter(Smaller_Than_CQ_Filter) //返回结果
ee.Filter.maxDifference()
两个量之间某一变量的差值小于设定阈值
var filter_1 = ee.Filter.maxDifference('最大差值','属性字段','字段数值');
var filter_1 = ee.Filter.maxDifference('10','area',100);
//表示面积字段area与100最大相差10的区域
var result_filter = (FeatureCollection/ImageCollection).fliter(filter_1);
ee.Filter.StarsWith()
ee.Filter.EndWith()
ee.Filter.stringContains()
var filter_1 = ee.Filter.stringStartsWith('字段','起始字符串');
// 筛选出指定字段内以某一字符为开头的数据
var filter_2 = ee.Filter.stringEndsWith('字段','末尾字符串');
// 筛选出指定字段内以某一字符为末尾的数据
var filter_3 = ee.Filter.stringContains('字段','包含字符串');
// 筛选出指定字段内包含某一字符为的数据
ee.Filter.Rangecontains()
var filter_1 = ee.Filter.rangeContains('字段','起始字母', '终止字母');
'var filter_1 = ee.Filter.rangeContains('NAME','B', 'D');'
//表示筛选出NAME字段中包含字母B到D的全部区域
ee.Filter.listContains()
var filter_1 = ee.Filter.listContains('字段','列表内包含值');
ee.Filter.inList()
var list_1 = ee.List('字符串1', '字符串2', '字符串3');
var filter_1 = ee.Filter.inlist('字段',list_1);
//筛选出字段中包含列表内某些元素的结果(多值筛选)
ee.Filter.dayOfYear()
var filter_1 = ee.Filter.calendarRange(day1, day2, 'day_of_year');
//筛选一年中第day1到第day2天中的影像
var filter_2 = ee.Filter.calendarRange(month1, month2, 'month_of_year');
//按月份筛选
ee.Filter.calendarRange()
var Point = ee.Geometry.Point(119.2351, 29.3642);
var L8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_TOA")
.filterDate('2021-01-01','2022-01-01')
.filterBounds(Point);
var L8_00_200_Filter = ee.Filter.calendarRange(00,200,'day_of_year');
var L8_00_200_Images = L8.filter(L8_00_200_Filter);
print(L8,L8_00_100_Images);
其中L8有19景影像,前200天有13景
ee.FilterDateRangeContains()
var Point = ee.Geometry.Point(119.2351, 29.3642);
var L8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_TOA")
.filterDate('2021-01-01','2022-01-01')
.filterBounds(Point);
var Date_Range = ee.DateRange( '2021-01-01', '2021-05-01' );
var Rang_Filter = ee.Filter.dateRangeContains(null, null, 'DATE_ACQUIRED', Date_Range );
var L8_Filted_Images = L8.filter(Rang_Filter)
print(L8,L8_Filted_Images)
对于
var Rang_Filter = ee.Filter.dateRangeContains(null, null, 'DATE_ACQUIRED', Date_Range );
解释如下:
var filter_1 = ee.Filter.and(filter_A, filter_B);
//筛选交filter
var filter_2 = ee.Filter.or(filter_A, filter_B);
//筛选并filter
var filter_2 = filter_1.not();
//要filter_1筛选结果不符合的部分
ee.Filter.and = ee.Filter