ee.FeatureCollection.filterDate

可依日期範圍篩選集合的捷徑。開始和結束時間可以是日期、數字 (解讀為自 1970-01-01T00:00:00Z 算起的毫秒數),或字串 (例如「1996-01-01T08:00」)。根據「system:time_start」。

這等同於 this.filter(ee.Filter.date(...));如需其他日期篩選選項,請參閱 ee.Filter 型別。

傳回經過篩選的集合。

用量傳回
FeatureCollection.filterDate(start, end)集合
引數類型詳細資料
這個:collection集合Collection 執行個體。
startDate|Number|String開始日期 (含)。
endDate|Number|String,選填結束日期 (不含)。(選用步驟) 如未指定,系統會建立從「start」開始的 1 毫秒範圍。

範例

程式碼編輯器 (JavaScript)

// Constructed FeatureCollection representing a field site sampled at
// four different dates; date recorded as "system:time_start" property in units
// of milliseconds since Unix epoch.
var geom = ee.Geometry.Point([-119.56, 37.67]);
var fc = ee.FeatureCollection([
  ee.Feature(geom, {'prop': 10, 'system:time_start': ee.Date('2021-06-10')}),
  ee.Feature(geom, {'prop': 11, 'system:time_start': ee.Date('2021-06-20')}),
  ee.Feature(geom, {'prop': 19, 'system:time_start': ee.Date('2021-07-10')}),
  ee.Feature(geom, {'prop': 10, 'system:time_start': ee.Date('2021-07-20')})
]);

// Filter the observations in July 2021.
print('Field site observations collection in July 2021',
      fc.filterDate('2021-07-01', '2021-08-01'));

// Alternative input formats.
print('ee.DateRange as an input',
      fc.filterDate(ee.DateRange('2021-07-01', '2021-08-01')));

print('Numbers (milliseconds since Unix epoch) as an input',
      fc.filterDate(1625875200000, 1626739200001));

print('ee.Date objects as an input',
      fc.filterDate(ee.Date('2021-07-01'), ee.Date('2021-08-01')));

Python 設定

請參閱 Python 環境頁面,瞭解 Python API 和如何使用 geemap 進行互動式開發。

import ee
import geemap.core as geemap

Colab (Python)

# Constructed FeatureCollection representing a field site sampled at
# four different dates; date recorded as "system:time_start" property in units
# of milliseconds since Unix epoch.
geom = ee.Geometry.Point([-119.56, 37.67])
fc = ee.FeatureCollection([
    ee.Feature(geom, {'prop': 10, 'system:time_start': ee.Date('2021-06-10')}),
    ee.Feature(geom, {'prop': 11, 'system:time_start': ee.Date('2021-06-20')}),
    ee.Feature(geom, {'prop': 19, 'system:time_start': ee.Date('2021-07-10')}),
    ee.Feature(geom, {'prop': 10, 'system:time_start': ee.Date('2021-07-20')})
])

# Filter the observations in July 2021.
print('Field site observations collection in July 2021:',
      fc.filterDate('2021-07-01', '2021-08-01').getInfo())

# Alternative input formats.
print('ee.DateRange as an input:',
      fc.filterDate(ee.DateRange('2021-07-01', '2021-08-01')).getInfo())

print('Numbers (milliseconds since Unix epoch) as an input:',
      fc.filterDate(1625875200000, 1626739200001).getInfo())

print('ee.Date objects as an input:',
      fc.filterDate(ee.Date('2021-07-01'), ee.Date('2021-08-01')).getInfo())