공지사항:
2025년 4월 15일 전에 Earth Engine 사용을 위해 등록된 모든 비상업용 프로젝트는 Earth Engine 액세스를 유지하기 위해
비상업용 자격 요건을 인증해야 합니다.
ee.Image.distance
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
지정된 거리 커널을 사용하여 각 밴드에서 0이 아닌 가장 가까운 픽셀까지의 거리를 계산합니다.
사용 | 반환 값 |
---|
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
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-07-26(UTC)
[null,null,["최종 업데이트: 2025-07-26(UTC)"],[[["\u003cp\u003eComputes the distance to the nearest non-zero pixel for each band in an image, using a specified distance kernel (Chebyshev, Euclidean, or Manhattan).\u003c/p\u003e\n"],["\u003cp\u003eAccepts an input image, a distance kernel, and an optional parameter to mask output pixels corresponding to masked input pixels.\u003c/p\u003e\n"],["\u003cp\u003eReturns an image where pixel values represent the distance to the nearest non-zero pixel in the input.\u003c/p\u003e\n"],["\u003cp\u003eOffers flexibility in defining the distance kernel and handling masked pixels.\u003c/p\u003e\n"],["\u003cp\u003eCan be used to analyze proximity to specific features in images, such as determining the distance to water bodies in a land cover map.\u003c/p\u003e\n"]]],[],null,["# ee.Image.distance\n\nComputes the distance to the nearest non-zero pixel in each band, using the specified distance kernel.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|-----------------------------------------------|---------|\n| Image.distance`(`*kernel* `, `*skipMasked*`)` | Image |\n\n| Argument | Type | Details |\n|---------------|------------------------|-----------------------------------------------------------------|\n| this: `image` | Image | The input image. |\n| `kernel` | Kernel, default: null | The distance kernel. One of chebyshev, euclidean, or manhattan. |\n| `skipMasked` | Boolean, default: true | Mask output pixels if the corresponding input pixel is masked. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// The objective is to determine the per-pixel distance to a target\n// feature (pixel value). In this example, the target feature is water in a\n// land cover map.\n\n// Import a Dynamic World land cover image and subset the 'label' band.\nvar lcImg = ee.Image(\n 'GOOGLE/DYNAMICWORLD/V1/20210726T171859_20210726T172345_T14TQS')\n .select('label');\n\n// Create a binary image where the target feature is value 1, all else 0.\n// In the Dynamic World map, water is represented as value 0, so we use the\n// ee.Image.eq() relational operator to set it to 1.\nvar targetImg = lcImg.eq(0);\n\n// Set a max distance from target pixels to consider in the analysis. Pixels\n// with distance greater than this value from target pixels will be masked out.\n// Here, we are using units of meters, but the distance kernels also accept\n// units of pixels.\nvar maxDistM = 10000; // 10 km\n\n// Calculate distance to target pixels. Several distance kernels are provided.\n\n// Euclidean distance.\nvar euclideanKernel = ee.Kernel.euclidean(maxDistM, 'meters');\nvar euclideanDist = targetImg.distance(euclideanKernel);\nvar vis = {min: 0, max: maxDistM};\nMap.setCenter(-95.68, 46.46, 9);\nMap.addLayer(euclideanDist, vis, 'Euclidean distance to target pixels');\n\n// Manhattan distance.\nvar manhattanKernel = ee.Kernel.manhattan(maxDistM, 'meters');\nvar manhattanDist = targetImg.distance(manhattanKernel);\nMap.addLayer(manhattanDist, vis, 'Manhattan distance to target pixels', false);\n\n// Chebyshev distance.\nvar chebyshevKernel = ee.Kernel.chebyshev(maxDistM, 'meters');\nvar chebyshevDist = targetImg.distance(chebyshevKernel);\nMap.addLayer(chebyshevDist, vis, 'Chebyshev distance to target pixels', false);\n\n// Add the target layer to the map; water is blue, all else masked out.\nMap.addLayer(targetImg.mask(targetImg), {palette: 'blue'}, 'Target pixels');\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# The objective is to determine the per-pixel distance to a target\n# feature (pixel value). In this example, the target feature is water in a\n# land cover map.\n\n# Import a Dynamic World land cover image and subset the 'label' band.\nlc_img = ee.Image(\n 'GOOGLE/DYNAMICWORLD/V1/20210726T171859_20210726T172345_T14TQS'\n).select('label')\n\n# Create a binary image where the target feature is value 1, all else 0.\n# In the Dynamic World map, water is represented as value 0, so we use the\n# ee.Image.eq() relational operator to set it to 1.\ntarget_img = lc_img.eq(0)\n\n# Set a max distance from target pixels to consider in the analysis. Pixels\n# with distance greater than this value from target pixels will be masked out.\n# Here, we are using units of meters, but the distance kernels also accept\n# units of pixels.\nmax_dist_m = 10000 # 10 km\n\n# Calculate distance to target pixels. Several distance kernels are provided.\n\n# Euclidean distance.\neuclidean_kernel = ee.Kernel.euclidean(max_dist_m, 'meters')\neuclidean_dist = target_img.distance(euclidean_kernel)\nvis = {'min': 0, 'max': max_dist_m}\nm = geemap.Map()\nm.set_center(-95.68, 46.46, 9)\nm.add_layer(euclidean_dist, vis, 'Euclidean distance to target pixels')\n\n# Manhattan distance.\nmanhattan_kernel = ee.Kernel.manhattan(max_dist_m, 'meters')\nmanhattan_dist = target_img.distance(manhattan_kernel)\nm.add_layer(\n manhattan_dist, vis, 'Manhattan distance to target pixels', False\n)\n\n# Chebyshev distance.\nchebyshev_kernel = ee.Kernel.chebyshev(max_dist_m, 'meters')\nchebyshev_dist = target_img.distance(chebyshev_kernel)\nm.add_layer(\n chebyshev_dist, vis, 'Chebyshev distance to target pixels', False\n)\n\n# Add the target layer to the map water is blue, all else masked out.\nm.add_layer(\n target_img.mask(target_img), {'palette': 'blue'}, 'Target pixels'\n)\nm\n```"]]