相關地圖項目群組可結合為 FeatureCollection
,以便對整個集合執行其他作業,例如篩選、排序和算繪。除了簡單的特徵 (幾何圖形 + 屬性) 之外,地圖集合也可以包含其他集合。
FeatureCollection
建構函式
建立 FeatureCollection
的方法之一,是向建構函式提供功能清單。地圖項目不必具有相同的幾何圖形類型或屬性。例如:
程式碼編輯器 (JavaScript)
// Make a list of Features. var features = [ ee.Feature(ee.Geometry.Rectangle(30.01, 59.80, 30.59, 60.15), {name: 'Voronoi'}), ee.Feature(ee.Geometry.Point(-73.96, 40.781), {name: 'Thiessen'}), ee.Feature(ee.Geometry.Point(6.4806, 50.8012), {name: 'Dirichlet'}) ]; // Create a FeatureCollection from the list and print it. var fromList = ee.FeatureCollection(features); print(fromList);
import ee import geemap.core as geemap
Colab (Python)
# Make a list of Features. features = [ ee.Feature( ee.Geometry.Rectangle(30.01, 59.80, 30.59, 60.15), {'name': 'Voronoi'} ), ee.Feature(ee.Geometry.Point(-73.96, 40.781), {'name': 'Thiessen'}), ee.Feature(ee.Geometry.Point(6.4806, 50.8012), {'name': 'Dirichlet'}), ] # Create a FeatureCollection from the list and print it. from_list = ee.FeatureCollection(features) display(from_list)
個別幾何圖形也可以轉換為單一 Feature
的 FeatureCollection
:
程式碼編輯器 (JavaScript)
// Create a FeatureCollection from a single geometry and print it. var fromGeom = ee.FeatureCollection(ee.Geometry.Point(16.37, 48.225)); print(fromGeom);
import ee import geemap.core as geemap
Colab (Python)
# Create a FeatureCollection from a single geometry and print it. from_geom = ee.FeatureCollection(ee.Geometry.Point(16.37, 48.225)) display(from_geom)
表格資料集
Earth Engine 會代管各種表格資料集。如要載入資料表資料集,請將資料表 ID 提供給 FeatureCollection
建構函式。例如,如要載入 RESOLVE 生態區資料:
程式碼編輯器 (JavaScript)
var fc = ee.FeatureCollection('RESOLVE/ECOREGIONS/2017'); Map.setCenter(12.17, 20.96, 3); Map.addLayer(fc, {}, 'ecoregions');
import ee import geemap.core as geemap
Colab (Python)
fc = ee.FeatureCollection('RESOLVE/ECOREGIONS/2017') m = geemap.Map() m.set_center(12.17, 20.96, 3) m.add_layer(fc, {}, 'ecoregions') display(m)
請注意,您可以透過 Earth Engine 資料目錄搜尋圖像資料集和表格資料集。
隨機樣本
如要取得指定區域內的隨機點集合,您可以使用:
程式碼編輯器 (JavaScript)
// Define an arbitrary region in which to compute random points. var region = ee.Geometry.Rectangle(-119.224, 34.669, -99.536, 50.064); // Create 1000 random points in the region. var randomPoints = ee.FeatureCollection.randomPoints(region); // Display the points. Map.centerObject(randomPoints); Map.addLayer(randomPoints, {}, 'random points');
import ee import geemap.core as geemap
Colab (Python)
# Define an arbitrary region in which to compute random points. region = ee.Geometry.Rectangle(-119.224, 34.669, -99.536, 50.064) # Create 1000 random points in the region. random_points = ee.FeatureCollection.randomPoints(region) # Display the points. m = geemap.Map() m.center_object(random_points) m.add_layer(random_points, {}, 'random points') display(m)