Cách sử dụng | Giá trị trả về |
---|---|
Image.arraySlice(axis, start, end, step) | Hình ảnh |
Đối số | Loại | Thông tin chi tiết |
---|---|---|
this: input | Hình ảnh | Nhập hình ảnh mảng. |
axis | Số nguyên, mặc định: 0 | Trục để tạo tập hợp con. |
start | Hình ảnh, mặc định: rỗng | Toạ độ của lát đầu tiên (bao gồm) dọc theo "trục". Các số âm được dùng để định vị điểm bắt đầu của việc phân đoạn tương ứng với điểm cuối của mảng, trong đó -1 bắt đầu ở vị trí cuối cùng trên trục, -2 bắt đầu ở vị trí gần cuối cùng, v.v. Phải có một dải cho chỉ mục bắt đầu hoặc một dải cho mỗi dải "đầu vào". Nếu đối số này không được đặt hoặc che ở một số pixel, thì lát tại pixel đó sẽ bắt đầu ở chỉ mục 0. |
end | Hình ảnh, mặc định: rỗng | Toạ độ (loại trừ) tại đó ngừng lấy các lát. Theo mặc định, đây sẽ là chiều dài của trục đã cho. Số âm được dùng để định vị điểm cuối của việc phân đoạn tương ứng với điểm cuối của mảng, trong đó -1 sẽ loại trừ vị trí cuối cùng, -2 sẽ loại trừ hai vị trí cuối cùng, v.v. Phải có một dải ô cho chỉ mục cuối hoặc một dải ô cho mỗi dải ô "đầu vào". Nếu đối số này không được đặt hoặc bị che ở một số pixel, thì lát cắt tại pixel đó sẽ kết thúc ngay sau chỉ mục cuối cùng. |
step | Số nguyên, mặc định: 1 | Khoảng cách giữa các lát cắt dọc theo "trục"; một lát cắt sẽ được lấy tại mỗi bội số nguyên của "bước" từ "bắt đầu" (bao gồm) đến "kết thúc" (không bao gồm). Phải là số dương. |
Ví dụ
Trình soạn thảo mã (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]]
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() print('1D array image (pixel):', samp_arr_img(array_img_1d).getInfo()) # [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):', samp_arr_img(array_img_1d.arraySlice(0, 0, 3)).getInfo()) # [0, 1, 2] # Get the last 3 elements. print('1D array image last 3 elements (pixel):', samp_arr_img(array_img_1d.arraySlice(0, -3)).getInfo()) # [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):', samp_arr_img(array_img_1d.arraySlice(0, 3, 6)).getInfo()) # [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)', samp_arr_img(array_img_1d.arraySlice(0, 4)).getInfo()) # [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)', samp_arr_img(array_img_1d.arraySlice(0, 0, None, 3)).getInfo()) # [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) print('2D array image (pixel)', samp_arr_img(array_img_2d).getInfo()) # [[0, 1, 2, 3], # [4, 5, 6, 7], # [8, 9, 10, 11]] # Get the second row. print('2D array image second row (pixel):', samp_arr_img(array_img_2d.arraySlice(0, 1, 2)).getInfo()) # [[4, 5, 6, 7] # Get the second column. print('2D array image second column (pixel):', samp_arr_img(array_img_2d.arraySlice(1, 1, 2)).getInfo()) # [[1], # [5], # [9]] # Get all columns except the last. print('2D array image all columns except last (pixel):', samp_arr_img(array_img_2d.arraySlice(1, 0, -1)).getInfo()) # [[0, 1, 2], # [4, 5, 6], # [8, 9, 10]]