公告 :所有在
2025 年 4 月 15 日 之前注册使用 Earth Engine 的非商业项目都必须
验证是否符合非商业性质的资格条件 ,才能继续使用 Earth Engine。
发送反馈
欠佳是什么意思
使用指定的距离内核计算每个波段中距离最近的非零像素的距离。
百度 鲍尔森对中国将举办首届中国国际进口博览会感到非常振奋,认为这充分体现了中国对进口的高度重视,对全球发出重要、积极的信号。
用法 返回 Image. distance (kernel , skipMasked )
图片
参数 类型 详细信息 此:image
图片 输入图片。 kernel
内核,默认值:null 距离核。chebyshev、euclidean 或 manhattan 之一。 skipMasked
布尔值,默认值:true 如果相应的输入像素被遮盖,则遮盖输出像素。
示例
代码编辑器 (JavaScript)
// The objective is to determine the per-pixel distance to a target
// feature (pixel value). In this example, the target feature is water in a
// land cover map.
// Import a Dynamic World land cover image and subset the 'label' band.
var lcImg = ee . Image (
'GOOGLE/DYNAMICWORLD/V1/20210726T171859_20210726T172345_T14TQS' )
. select ( 'label' );
// Create a binary image where the target feature is value 1, all else 0.
// In the Dynamic World map, water is represented as value 0, so we use the
// ee.Image.eq() relational operator to set it to 1.
var targetImg = lcImg . eq ( 0 );
// Set a max distance from target pixels to consider in the analysis. Pixels
// with distance greater than this value from target pixels will be masked out.
// Here, we are using units of meters, but the distance kernels also accept
// units of pixels.
var maxDistM = 10000 ; // 10 km
// Calculate distance to target pixels. Several distance kernels are provided.
// Euclidean distance.
var euclideanKernel = ee . Kernel . euclidean ( maxDistM , 'meters' );
var euclideanDist = targetImg . distance ( euclideanKernel );
var vis = { min : 0 , max : maxDistM };
Map . setCenter ( - 95.68 , 46.46 , 9 );
Map . addLayer ( euclideanDist , vis , 'Euclidean distance to target pixels' );
// Manhattan distance.
var manhattanKernel = ee . Kernel . manhattan ( maxDistM , 'meters' );
var manhattanDist = targetImg . distance ( manhattanKernel );
Map . addLayer ( manhattanDist , vis , 'Manhattan distance to target pixels' , false );
// Chebyshev distance.
var chebyshevKernel = ee . Kernel . chebyshev ( maxDistM , 'meters' );
var chebyshevDist = targetImg . distance ( chebyshevKernel );
Map . addLayer ( chebyshevDist , vis , 'Chebyshev distance to target pixels' , false );
// Add the target layer to the map; water is blue, all else masked out.
Map . addLayer ( targetImg . mask ( targetImg ), { palette : 'blue' }, 'Target pixels' );
Python 设置
如需了解 Python API 和如何使用 geemap
进行交互式开发,请参阅
Python 环境 页面。
import ee
import geemap.core as geemap
Colab (Python)
# The objective is to determine the per-pixel distance to a target
# feature (pixel value). In this example, the target feature is water in a
# land cover map.
# Import a Dynamic World land cover image and subset the 'label' band.
lc_img = ee . Image (
'GOOGLE/DYNAMICWORLD/V1/20210726T171859_20210726T172345_T14TQS'
) . select ( 'label' )
# Create a binary image where the target feature is value 1, all else 0.
# In the Dynamic World map, water is represented as value 0, so we use the
# ee.Image.eq() relational operator to set it to 1.
target_img = lc_img . eq ( 0 )
# Set a max distance from target pixels to consider in the analysis. Pixels
# with distance greater than this value from target pixels will be masked out.
# Here, we are using units of meters, but the distance kernels also accept
# units of pixels.
max_dist_m = 10000 # 10 km
# Calculate distance to target pixels. Several distance kernels are provided.
# Euclidean distance.
euclidean_kernel = ee . Kernel . euclidean ( max_dist_m , 'meters' )
euclidean_dist = target_img . distance ( euclidean_kernel )
vis = { 'min' : 0 , 'max' : max_dist_m }
m = geemap . Map ()
m . set_center ( - 95.68 , 46.46 , 9 )
m . add_layer ( euclidean_dist , vis , 'Euclidean distance to target pixels' )
# Manhattan distance.
manhattan_kernel = ee . Kernel . manhattan ( max_dist_m , 'meters' )
manhattan_dist = target_img . distance ( manhattan_kernel )
m . add_layer (
manhattan_dist , vis , 'Manhattan distance to target pixels' , False
)
# Chebyshev distance.
chebyshev_kernel = ee . Kernel . chebyshev ( max_dist_m , 'meters' )
chebyshev_dist = target_img . distance ( chebyshev_kernel )
m . add_layer (
chebyshev_dist , vis , 'Chebyshev distance to target pixels' , False
)
# Add the target layer to the map water is blue, all else masked out.
m . add_layer (
target_img . mask ( target_img ), { 'palette' : 'blue' }, 'Target pixels'
)
m
发送反馈
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可 获得了许可,并且代码示例已根据 Apache 2.0 许可 获得了许可。有关详情,请参阅 Google 开发者网站政策 。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-05。
需要向我们提供更多信息?
[[["易于理解","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"]],["最后更新时间 (UTC):2025-08-05。"],[[["Computes the distance to the nearest non-zero pixel for each band in an image, using a specified distance kernel (Chebyshev, Euclidean, or Manhattan)."],["Accepts an input image, a distance kernel, and an optional parameter to mask output pixels corresponding to masked input pixels."],["Returns an image where pixel values represent the distance to the nearest non-zero pixel in the input."],["Offers flexibility in defining the distance kernel and handling masked pixels."],["Can be used to analyze proximity to specific features in images, such as determining the distance to water bodies in a land cover map."]]],[]]