公告:凡是在
2025 年 4 月 15 日前註冊使用 Earth Engine 的非商業專案,都必須
驗證非商業用途資格,才能繼續存取 Earth Engine。
ee.FeatureCollection.runBigQuery
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
執行 BigQuery 查詢,擷取結果並以 FeatureCollection 的形式呈現。
用量 | 傳回 |
---|
ee.FeatureCollection.runBigQuery(query, geometryColumn, maxBytesBilled) | FeatureCollection |
引數 | 類型 | 詳細資料 |
---|
query | 字串 | 要在 BigQuery 資源上執行的 GoogleSQL 查詢。 |
geometryColumn | 字串,預設值:空值 | 要用來做為主要地形特徵幾何圖形的資料欄名稱。如未指定,系統會使用第一個幾何圖形資料欄。 |
maxBytesBilled | Long,預設值:100000000000 | 處理查詢時計費的位元組數上限。超過此上限的 BigQuery 工作會失敗,且不會產生費用。 |
範例
程式碼編輯器 (JavaScript)
// Get places from Overture Maps Dataset in BigQuery public data.
Map.setCenter(-3.69, 40.41, 12)
var mapGeometry= ee.Geometry(Map.getBounds(true)).toGeoJSONString();
var sql =
"SELECT geometry, names.primary as name, categories.primary as category "
+ " FROM bigquery-public-data.overture_maps.place "
+ " WHERE ST_INTERSECTS(geometry, ST_GEOGFROMGEOJSON('" + mapGeometry+ "'))";
var features = ee.FeatureCollection.runBigQuery({
query: sql,
geometryColumn: 'geometry'
});
// Display all relevant features on the map.
Map.addLayer(features,
{'color': 'black'},
'Places from Overture Maps Dataset');
// Create a histogram of the categories and print it.
var propertyOfInterest = 'category';
var histogram = features.filter(ee.Filter.notNull([propertyOfInterest]))
.aggregate_histogram(propertyOfInterest);
print(histogram);
// Create a frequency chart for the histogram.
var categories = histogram.keys().map(function(k) {
return ee.Feature(null, {
key: k,
value: histogram.get(k)
});
});
var sortedCategories = ee.FeatureCollection(categories).sort('value', false);
print(ui.Chart.feature.byFeature(sortedCategories).setChartType('Table'));
Python 設定
請參閱「
Python 環境」頁面,瞭解 Python API 和如何使用 geemap
進行互動式開發。
import ee
import geemap.core as geemap
Colab (Python)
import json
import pandas as pd
# Get places from Overture Maps Dataset in BigQuery public data.
location = ee.Geometry.Point(-3.69, 40.41)
map_geometry = json.dumps(location.buffer(5e3).getInfo())
sql = f"""SELECT geometry, names.primary as name, categories.primary as category
FROM bigquery-public-data.overture_maps.place
WHERE ST_INTERSECTS(geometry, ST_GEOGFROMGEOJSON('{map_geometry}'))"""
features = ee.FeatureCollection.runBigQuery(
query=sql, geometryColumn="geometry"
)
# Display all relevant features on the map.
m = geemap.Map()
m.center_object(location, 13)
m.add_layer(features, {'color': 'black'}, 'Places from Overture Maps Dataset')
display(m)
# Create a histogram of the place categories.
property_of_interest = 'category'
histogram = (
features.filter(
ee.Filter.notNull([property_of_interest])
).aggregate_histogram(property_of_interest)
).getInfo()
# Display the histogram as a pandas DataFrame.
df = pd.DataFrame(list(histogram.items()), columns=['category', 'frequency'])
df = df.sort_values(by=['frequency'], ascending=False, ignore_index=True)
display(df)
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-06-24 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-06-24 (世界標準時間)。"],[],[]]