公告:凡是在
2025 年 4 月 15 日前註冊使用 Earth Engine 的非商業專案,都必須
驗證非商業用途資格,才能繼續存取。如未在 2025 年 9 月 26 日前完成驗證,存取權可能會暫停。
ee.Image.reproject
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
強制以特定投影和解析度計算圖片。
用量 | 傳回 |
---|
Image.reproject(crs, crsTransform, scale) | 圖片 |
引數 | 類型 | 詳細資料 |
---|
這個:image | 圖片 | 要重新投影的圖片。 |
crs | 預測值 | 要將圖片投影至的 CRS。 |
crsTransform | 清單,預設值為空值 | CRS 轉換值清單。這是 3x2 轉換矩陣的列優先順序。這個選項與縮放選項互斥,且會取代投影上已有的任何變形。 |
scale | 浮點值,預設值為空值 | 如果指定比例,系統會將指定比例值除以指定投影中一公尺的名義大小,藉此縮放投影。如未指定比例,系統會使用指定投影的比例。 |
範例
程式碼編輯器 (JavaScript)
// Use of ee.Image.reproject is rarely needed and should generally be avoided.
// Defining the projection and scale of analysis should be handled by "scale",
// "crs", and "crsTransform" parameters whenever they are offered by a function.
// It is occasionally useful for forcing computation or visualization at a
// desired scale and projection when alternative methods are not available. In
// this example it is used to compute and visualize terrain slope from a DEM
// composite.
// Calculate mean elevation from two DEM datasets. The resulting composite
// image has a default CRS of WGS84 with 1 degree pixels.
var dem1 = ee.Image('NASA/NASADEM_HGT/001').select('elevation');
var dem2 = ee.Image('CGIAR/SRTM90_V4').select('elevation');
var demMean = ee.ImageCollection([dem1, dem2]).mean();
// Display the DEMs on the map, note that they all render as expected.
var demVisParams = {min: 500, max: 2500};
Map.setCenter(-123.457, 47.815, 11);
Map.addLayer(dem1, demVisParams, 'DEM 1');
Map.addLayer(dem2, demVisParams, 'DEM 2');
Map.addLayer(demMean, demVisParams, 'DEM composite');
// Calculate terrain slope from the composite DEM (WGS84, 1 degree pixel scale).
var demCompSlope = ee.Terrain.slope(demMean);
// Because the composite has 1 degree pixel scale, the slope calculation
// is essenstially meaningless and difficult to even display (you may need to
// zoom out to see the individual 1 degree pixels).
Map.addLayer(demCompSlope, {min: 0, max: 0.3}, 'Slope');
// We can use ee.Image.reproject to force the slope calculation and display
// the result with a reasonable scale of 30 m on WGS84 CRS, for example.
var slopeScale = ee.Terrain.slope(
demMean.reproject({
crs: 'EPSG:4326',
scale: 30
})
);
Map.addLayer(slopeScale, {min: 0, max: 45}, 'Slope w/ CRS and scale');
// To more precisely control the reprojection, you can use the "crsTransform"
// parameter instead of the "scale" parameter or set the projection according to
// a reference image. For example, here the input composite image for the slope
// function is set to match the grid spacing and alignment of the NASADEM image.
var nasademProj = dem1.projection();
var demMeanReproj = demMean.reproject(nasademProj);
var slopeRefProj = ee.Terrain.slope(demMeanReproj);
Map.addLayer(slopeRefProj, {min: 0, max: 45}, 'Slope w/ reference proj');
print('Reference projection', nasademProj);
print('DEM composite projection', demMeanReproj.projection());
// An alternative method for changing the projection of image composites
// (not accepting the default WGS84 CRS with 1 degree pixel scale) is to
// explicitly set the default projection using ee.Image.setDefaultProjection,
// which will not force resampling, like ee.Image.reproject will.
var demMeanProj = ee.ImageCollection([dem1, dem2]).mean()
.setDefaultProjection(nasademProj);
var slopeProj = ee.Terrain.slope(demMeanProj);
Map.addLayer(slopeProj, {min: 0, max: 45}, 'slope w/ default projection set');
Python 設定
請參閱
Python 環境頁面,瞭解 Python API 和如何使用 geemap
進行互動式開發。
import ee
import geemap.core as geemap
Colab (Python)
# Use of ee.Image.reproject is rarely needed and should generally be avoided.
# Defining the projection and scale of analysis should be handled by "scale",
# "crs", and "crsTransform" parameters whenever they are offered by a function.
# It is occasionally useful for forcing computation or visualization at a
# desired scale and projection when alternative methods are not available. In
# this example it is used to compute and visualize terrain slope from a DEM
# composite.
# Calculate mean elevation from two DEM datasets. The resulting composite
# image has a default CRS of WGS84 with 1 degree pixels.
dem_1 = ee.Image('NASA/NASADEM_HGT/001').select('elevation')
dem_2 = ee.Image('CGIAR/SRTM90_V4').select('elevation')
dem_mean = ee.ImageCollection([dem_1, dem_2]).mean()
# Display the DEMs on the map, note that they all render as expected.
dem_vis_params = {'min': 500, 'max': 2500}
m = geemap.Map()
m.set_center(-123.457, 47.815, 11)
m.add_layer(dem_1, dem_vis_params, 'DEM 1')
m.add_layer(dem_2, dem_vis_params, 'DEM 2')
m.add_layer(dem_mean, dem_vis_params, 'DEM composite')
# Calculate terrain slope from the composite DEM (WGS84, 1 degree pixel scale).
dem_comp_slope = ee.Terrain.slope(dem_mean)
# Because the composite has 1 degree pixel scale, the slope calculation
# is essenstially meaningless and difficult to even display (you may need to
# zoom out to see the individual 1 degree pixels).
m.add_layer(dem_comp_slope, {'min': 0, 'max': 0.3}, 'Slope')
# We can use ee.Image.reproject to force the slope calculation and display
# the result with a reasonable scale of 30 m on WGS84 CRS, for example.
slope_scale = ee.Terrain.slope(dem_mean.reproject(crs='EPSG:4326', scale=30))
m.add_layer(slope_scale, {'min': 0, 'max': 45}, 'Slope w/ CRS and scale')
# To more precisely control the reprojection, you can use the "crsTransform"
# parameter instead of the "scale" parameter or set the projection according to
# a reference image. For example, here the input composite image for the slope
# function is set to match the grid spacing and alignment of the NASADEM image.
nasadem_proj = dem_1.projection()
dem_mean_reproj = dem_mean.reproject(nasadem_proj)
slope_ref_proj = ee.Terrain.slope(dem_mean_reproj)
m.add_layer(slope_ref_proj, {'min': 0, 'max': 45}, 'Slope w/ reference proj')
display('Reference projection', nasadem_proj)
display('DEM composite projection', dem_mean_reproj.projection())
# An alternative method for changing the projection of image composites
# (not accepting the default WGS84 CRS with 1 degree pixel scale) is to
# explicitly set the default projection using ee.Image.setDefaultProjection,
# which will not force resampling, like ee.Image.reproject will.
dem_mean_proj = (
ee.ImageCollection([dem_1, dem_2]).mean().setDefaultProjection(nasadem_proj)
)
slope_proj = ee.Terrain.slope(dem_mean_proj)
m.add_layer(
slope_proj, {'min': 0, 'max': 45}, 'slope w/ default projection set'
)
m
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[[["容易理解","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-07-26 (世界標準時間)。"],[],[]]