ee.Image.arraySlice

'start'(포함)에서 'end'(제외)까지 'step'의 증분으로 지정된 축을 따라 각 위치를 슬라이싱하여 하위 배열을 만듭니다.

결과는 입력과 동일한 차원을 가지며 슬라이싱 축을 제외한 모든 방향에서 길이가 동일합니다. 여기서 길이는 'axis'를 따라 입력 배열의 길이 범위 내에 있는 'start'에서 'end'까지 'step'의 위치 수입니다. 즉, start=end이거나 시작 또는 종료 값이 완전히 범위를 벗어난 경우 결과는 지정된 축을 따라 길이가 0일 수 있습니다.

사용반환 값
Image.arraySlice(axis, start, end, step)이미지
인수유형세부정보
this: input이미지입력 배열 이미지입니다.
axis정수, 기본값: 0하위 집합을 만들 축입니다.
start이미지, 기본값: null'axis'를 따라 첫 번째 슬라이스 (포함)의 좌표입니다. 음수는 배열의 끝을 기준으로 슬라이싱의 시작 위치를 지정하는 데 사용됩니다. 여기서 -1은 축의 마지막 위치에서 시작하고 -2는 마지막 위치에서 시작합니다. 시작 색인에 밴드가 하나 있어야 하거나 '입력' 밴드당 밴드가 하나 있어야 합니다. 이 인수가 일부 픽셀에서 설정되지 않거나 마스크 처리된 경우 해당 픽셀의 슬라이스는 색인 0에서 시작됩니다.
end이미지, 기본값: null슬라이스를 가져오는 것을 중지할 좌표 (제외)입니다. 기본적으로 지정된 축의 길이가 됩니다. 음수는 배열의 끝을 기준으로 슬라이싱의 끝 위치를 지정하는 데 사용됩니다. 여기서 -1은 마지막 위치를 제외하고 -2는 마지막 두 위치를 제외합니다. 종료 색인에 밴드가 하나 있어야 하거나 '입력' 밴드당 밴드가 하나 있어야 합니다. 이 인수가 일부 픽셀에서 설정되지 않거나 마스크 처리된 경우 해당 픽셀의 슬라이스는 마지막 색인 바로 뒤에서 종료됩니다.
step정수, 기본값: 1'axis'를 따라 슬라이스 간의 간격입니다. 슬라이스는 'start'(포함)에서 'end'(제외)까지 'step'의 각 정수 배수에서 가져옵니다. 양수여야 합니다.

코드 편집기(JavaScript)

// A function to print arrays for a selected pixel in the following examples.
function sampArrImg(arrImg) {
  var point = ee.Geometry.Point([-121, 42]);
  return arrImg.sample(point, 500).first().get('array');
}

// Create a 1D array image with length 12.
var arrayImg1D = ee.Image([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]).toArray();
print('1D array image (pixel)', sampArrImg(arrayImg1D));
// [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]

// Get the first 3 elements.
print('1D array image first 3 elements (pixel)',
      sampArrImg(arrayImg1D.arraySlice(0, 0, 3)));
// [0, 1, 2]

// Get the last 3 elements.
print('1D array image last 3 elements (pixel)',
      sampArrImg(arrayImg1D.arraySlice(0, -3)));
// [9, 10, 11]

// Get elements at index positions 3 through 5 (0-based).
print('1D array image elements at index positions 3 through 5 (pixel)',
      sampArrImg(arrayImg1D.arraySlice(0, 3, 6)));
// [3, 4, 5]

// Get elements at index positions 4 through end (0-based).
print('1D array image elements at index positions 4 through end (pixel)',
      sampArrImg(arrayImg1D.arraySlice(0, 4)));
// [4, 5, 6, 7, 8, 9, 10, 11]

// Get elements using a step of 3.
print('1D array image elements at a step of 3 (pixel)',
      sampArrImg(arrayImg1D.arraySlice(0, 0, null, 3)));
// [0, 3, 6, 9]

// Create a 2D array image with 3 rows and 4 columns.
var arrayImg2D = arrayImg1D.arrayReshape(ee.Image([3, 4]).toArray(), 2);
print('2D array image (pixel)', sampArrImg(arrayImg2D));
// [[0, 1,  2,  3],
//  [4, 5,  6,  7],
//  [8, 9, 10, 11]]

// Get the second row.
print('2D array image second row (pixel)',
      sampArrImg(arrayImg2D.arraySlice(0, 1, 2)));
// [[4, 5, 6, 7]

// Get the second column.
print('2D array image second column (pixel)',
      sampArrImg(arrayImg2D.arraySlice(1, 1, 2)));
// [[1],
//  [5],
//  [9]]

// Get all columns except the last.
print('2D array image all columns except last (pixel)',
      sampArrImg(arrayImg2D.arraySlice(1, 0, -1)));
// [[0, 1,  2],
//  [4, 5,  6],
//  [8, 9, 10]]

Python 설정

Python API 및 대화형 개발을 위한 geemap 사용에 관한 자세한 내용은 Python 환경 페이지를 참고하세요.

import ee
import geemap.core as geemap

Colab (Python)

# A function to print arrays for a selected pixel in the following examples.
def samp_arr_img(arr_img):
  point = ee.Geometry.Point([-121, 42])
  return arr_img.sample(point, 500).first().get('array')

# Create a 1D array image with length 12.
array_img_1d = ee.Image([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]).toArray()
display('1D array image (pixel):', samp_arr_img(array_img_1d))
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]

# Get the first 3 elements.
display('1D array image first 3 elements (pixel):',
        samp_arr_img(array_img_1d.arraySlice(0, 0, 3)))
# [0, 1, 2]

# Get the last 3 elements.
display('1D array image last 3 elements (pixel):',
        samp_arr_img(array_img_1d.arraySlice(0, -3)))
# [9, 10, 11]

# Get elements at index positions 3 through 5 (0-based).
display('1D array image elements at index positions 3 through 5 (pixel):',
        samp_arr_img(array_img_1d.arraySlice(0, 3, 6)))
# [3, 4, 5]

# Get elements at index positions 4 through end (0-based).
display('1D array image elements at index positions 4 through end (pixel)',
        samp_arr_img(array_img_1d.arraySlice(0, 4)))
# [4, 5, 6, 7, 8, 9, 10, 11]

# Get elements using a step of 3.
display('1D array image elements at a step of 3 (pixel)',
        samp_arr_img(array_img_1d.arraySlice(0, 0, None, 3)))
# [0, 3, 6, 9]

# Create a 2D array image with 3 rows and 4 columns.
array_img_2d = array_img_1d.arrayReshape(ee.Image([3, 4]).toArray(), 2)
display('2D array image (pixel)', samp_arr_img(array_img_2d))
# [[0, 1,  2,  3],
#  [4, 5,  6,  7],
#  [8, 9, 10, 11]]

# Get the second row.
display('2D array image second row (pixel):',
        samp_arr_img(array_img_2d.arraySlice(0, 1, 2)))
# [[4, 5, 6, 7]

# Get the second column.
display('2D array image second column (pixel):',
        samp_arr_img(array_img_2d.arraySlice(1, 1, 2)))
# [[1],
#  [5],
#  [9]]

# Get all columns except the last.
display('2D array image all columns except last (pixel):',
        samp_arr_img(array_img_2d.arraySlice(1, 0, -1)))
# [[0, 1,  2],
#  [4, 5,  6],
#  [8, 9, 10]]