Thông báo : Tất cả dự án phi thương mại đã đăng ký sử dụng Earth Engine trước
ngày 15 tháng 4 năm 2025 phải
xác minh điều kiện sử dụng phi thương mại để duy trì quyền truy cập. Nếu bạn chưa xác minh trước ngày 26 tháng 9 năm 2025, quyền truy cập của bạn có thể bị tạm ngưng.
Gửi ý kiến phản hồi
ee.Image.distance
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Tính khoảng cách đến pixel khác 0 gần nhất trong mỗi dải tần, bằng cách sử dụng nhân khoảng cách đã chỉ định.
Cách sử dụng Giá trị trả về Image. distance (kernel , skipMasked )
Hình ảnh
Đối số Loại Thông tin chi tiết this: image
Hình ảnh Hình ảnh đầu vào. kernel
Kernel, mặc định: null Hạt nhân khoảng cách. Một trong các giá trị chebyshev, euclidean hoặc manhattan. skipMasked
Boolean, mặc định: true Che các pixel đầu ra nếu pixel đầu vào tương ứng bị che.
Ví dụ
Trình soạn thảo mã (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' );
Thiết lập Python
Hãy xem trang
Môi trường Python để biết thông tin về API Python và cách sử dụng geemap
cho quá trình phát triển tương tác.
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
Gửi ý kiến phản hồi
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0 . Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers . Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-07-26 UTC.
Bạn muốn chia sẻ thêm với chúng tôi?
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-26 UTC."],[],[]]