公告:所有在
2025 年 4 月 15 日之前注册使用 Earth Engine 的非商业项目都必须
验证是否符合非商业性质的资格条件,才能继续使用 Earth Engine。
ee.Image.reproject
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
强制以给定的投影和分辨率计算图像。
用法 | 返回 |
---|
Image.reproject(crs, crsTransform, scale) | 图片 |
参数 | 类型 | 详细信息 |
---|
此:image | 图片 | 要重新投影的图片。 |
crs | 投影 | 要将图片投影到的 CRS。 |
crsTransform | 列表,默认值:null | CRS 转换值列表。这是 3x2 转换矩阵的行优先顺序。此选项与 scale 选项互斥,并会替换投影上已有的任何转换。 |
scale | 浮点数,默认值:null | 如果指定了比例,则通过将指定比例值除以指定投影中一米的标称大小来缩放投影。如果未指定比例,则使用指定投影的比例。 |
示例
代码编辑器 (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 API 和如何使用 geemap
进行交互式开发,请参阅
Python 环境页面。
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
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003e\u003ccode\u003eImage.reproject()\u003c/code\u003e forces an image to be computed in a specified projection and resolution, often for analysis or visualization purposes.\u003c/p\u003e\n"],["\u003cp\u003eThis method is generally avoided and should primarily be used when other methods for setting projection and scale are unavailable.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003ecrs\u003c/code\u003e and \u003ccode\u003escale\u003c/code\u003e or \u003ccode\u003ecrsTransform\u003c/code\u003e parameters control the reprojection; the latter offers more precise control.\u003c/p\u003e\n"],["\u003cp\u003eSetting the default projection using \u003ccode\u003esetDefaultProjection\u003c/code\u003e is an alternative for image composites, avoiding resampling inherent in \u003ccode\u003ereproject\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eReprojection is crucial for tasks like terrain analysis where pixel scale significantly affects results.\u003c/p\u003e\n"]]],[],null,["# ee.Image.reproject\n\nForce an image to be computed in a given projection and resolution.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|------------------------------------------------------|---------|\n| Image.reproject`(crs, `*crsTransform* `, `*scale*`)` | Image |\n\n| Argument | Type | Details |\n|----------------|----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| this: `image` | Image | The image to reproject. |\n| `crs` | Projection | The CRS to project the image to. |\n| `crsTransform` | List, default: null | The list of CRS transform values. This is a row-major ordering of the 3x2 transform matrix. This option is mutually exclusive with the scale option, and replaces any transform already on the projection. |\n| `scale` | Float, default: null | If scale is specified, then the projection is scaled by dividing the specified scale value by the nominal size of a meter in the specified projection. If scale is not specified, then the scale of the given projection will be used. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// Use of ee.Image.reproject is rarely needed and should generally be avoided.\n// Defining the projection and scale of analysis should be handled by \"scale\",\n// \"crs\", and \"crsTransform\" parameters whenever they are offered by a function.\n// It is occasionally useful for forcing computation or visualization at a\n// desired scale and projection when alternative methods are not available. In\n// this example it is used to compute and visualize terrain slope from a DEM\n// composite.\n\n// Calculate mean elevation from two DEM datasets. The resulting composite\n// image has a default CRS of WGS84 with 1 degree pixels.\nvar dem1 = ee.Image('NASA/NASADEM_HGT/001').select('elevation');\nvar dem2 = ee.Image('CGIAR/SRTM90_V4').select('elevation');\nvar demMean = ee.ImageCollection([dem1, dem2]).mean();\n\n// Display the DEMs on the map, note that they all render as expected.\nvar demVisParams = {min: 500, max: 2500};\nMap.setCenter(-123.457, 47.815, 11);\nMap.addLayer(dem1, demVisParams, 'DEM 1');\nMap.addLayer(dem2, demVisParams, 'DEM 2');\nMap.addLayer(demMean, demVisParams, 'DEM composite');\n\n// Calculate terrain slope from the composite DEM (WGS84, 1 degree pixel scale).\nvar demCompSlope = ee.Terrain.slope(demMean);\n\n// Because the composite has 1 degree pixel scale, the slope calculation\n// is essenstially meaningless and difficult to even display (you may need to\n// zoom out to see the individual 1 degree pixels).\nMap.addLayer(demCompSlope, {min: 0, max: 0.3}, 'Slope');\n\n// We can use ee.Image.reproject to force the slope calculation and display\n// the result with a reasonable scale of 30 m on WGS84 CRS, for example.\nvar slopeScale = ee.Terrain.slope(\n demMean.reproject({\n crs: 'EPSG:4326',\n scale: 30\n })\n);\nMap.addLayer(slopeScale, {min: 0, max: 45}, 'Slope w/ CRS and scale');\n\n// To more precisely control the reprojection, you can use the \"crsTransform\"\n// parameter instead of the \"scale\" parameter or set the projection according to\n// a reference image. For example, here the input composite image for the slope\n// function is set to match the grid spacing and alignment of the NASADEM image.\nvar nasademProj = dem1.projection();\nvar demMeanReproj = demMean.reproject(nasademProj);\nvar slopeRefProj = ee.Terrain.slope(demMeanReproj);\nMap.addLayer(slopeRefProj, {min: 0, max: 45}, 'Slope w/ reference proj');\nprint('Reference projection', nasademProj);\nprint('DEM composite projection', demMeanReproj.projection());\n\n// An alternative method for changing the projection of image composites\n// (not accepting the default WGS84 CRS with 1 degree pixel scale) is to\n// explicitly set the default projection using ee.Image.setDefaultProjection,\n// which will not force resampling, like ee.Image.reproject will.\nvar demMeanProj = ee.ImageCollection([dem1, dem2]).mean()\n .setDefaultProjection(nasademProj);\nvar slopeProj = ee.Terrain.slope(demMeanProj);\nMap.addLayer(slopeProj, {min: 0, max: 45}, 'slope w/ default projection set');\n```\nPython setup\n\nSee the [Python Environment](/earth-engine/guides/python_install) page for information on the Python API and using\n`geemap` for interactive development. \n\n```python\nimport ee\nimport geemap.core as geemap\n```\n\n### Colab (Python)\n\n```python\n# Use of ee.Image.reproject is rarely needed and should generally be avoided.\n# Defining the projection and scale of analysis should be handled by \"scale\",\n# \"crs\", and \"crsTransform\" parameters whenever they are offered by a function.\n# It is occasionally useful for forcing computation or visualization at a\n# desired scale and projection when alternative methods are not available. In\n# this example it is used to compute and visualize terrain slope from a DEM\n# composite.\n\n# Calculate mean elevation from two DEM datasets. The resulting composite\n# image has a default CRS of WGS84 with 1 degree pixels.\ndem_1 = ee.Image('NASA/NASADEM_HGT/001').select('elevation')\ndem_2 = ee.Image('CGIAR/SRTM90_V4').select('elevation')\ndem_mean = ee.ImageCollection([dem_1, dem_2]).mean()\n\n# Display the DEMs on the map, note that they all render as expected.\ndem_vis_params = {'min': 500, 'max': 2500}\nm = geemap.Map()\nm.set_center(-123.457, 47.815, 11)\nm.add_layer(dem_1, dem_vis_params, 'DEM 1')\nm.add_layer(dem_2, dem_vis_params, 'DEM 2')\nm.add_layer(dem_mean, dem_vis_params, 'DEM composite')\n\n# Calculate terrain slope from the composite DEM (WGS84, 1 degree pixel scale).\ndem_comp_slope = ee.Terrain.slope(dem_mean)\n\n# Because the composite has 1 degree pixel scale, the slope calculation\n# is essenstially meaningless and difficult to even display (you may need to\n# zoom out to see the individual 1 degree pixels).\nm.add_layer(dem_comp_slope, {'min': 0, 'max': 0.3}, 'Slope')\n\n# We can use ee.Image.reproject to force the slope calculation and display\n# the result with a reasonable scale of 30 m on WGS84 CRS, for example.\nslope_scale = ee.Terrain.slope(dem_mean.reproject(crs='EPSG:4326', scale=30))\nm.add_layer(slope_scale, {'min': 0, 'max': 45}, 'Slope w/ CRS and scale')\n\n# To more precisely control the reprojection, you can use the \"crsTransform\"\n# parameter instead of the \"scale\" parameter or set the projection according to\n# a reference image. For example, here the input composite image for the slope\n# function is set to match the grid spacing and alignment of the NASADEM image.\nnasadem_proj = dem_1.projection()\ndem_mean_reproj = dem_mean.reproject(nasadem_proj)\nslope_ref_proj = ee.Terrain.slope(dem_mean_reproj)\nm.add_layer(slope_ref_proj, {'min': 0, 'max': 45}, 'Slope w/ reference proj')\ndisplay('Reference projection', nasadem_proj)\ndisplay('DEM composite projection', dem_mean_reproj.projection())\n\n# An alternative method for changing the projection of image composites\n# (not accepting the default WGS84 CRS with 1 degree pixel scale) is to\n# explicitly set the default projection using ee.Image.setDefaultProjection,\n# which will not force resampling, like ee.Image.reproject will.\ndem_mean_proj = (\n ee.ImageCollection([dem_1, dem_2]).mean().setDefaultProjection(nasadem_proj)\n)\nslope_proj = ee.Terrain.slope(dem_mean_proj)\nm.add_layer(\n slope_proj, {'min': 0, 'max': 45}, 'slope w/ default projection set'\n)\nm\n```"]]