Học Google Earth Engine 10. Xuất dữ liệu trên gee

3.8. Xuất dữ liệu – Exporting Data

Earth Engine cho phép xuất cả dữ liệu vector và raster để sử dụng trong một chương trình bên ngoài. Dữ liệu vectơ có thể được xuất dưới dạng CSV hoặc Shapefile, trong khi Rasters có thể được xuất dưới dạng tệp GeoTIFF. Bây giờ chúng tôi sẽ xuất Sentinel-2 Composite dưới dạng tệp GeoTIFF.

Mẹo: Trình chỉnh sửa mã hỗ trợ tự động hoàn thành các hàm API bằng cách sử dụng tổ hợp Ctrl + Dấu cách (Ctrl + Space). Nhập một vài ký tự của một hàm và nhấn Ctrl + Space để xem các đề xuất tự động hoàn thành. Bạn cũng có thể sử dụng cùng một tổ hợp phím để tự động điền tất cả các tham số của hàm.

var s2 = ee.ImageCollection(“COPERNICUS/S2”)

var urban = ee.FeatureCollection(“users/ujavalgandhi/e2e/ne_10m_urban_areas”)

var filtered = urban.filter(ee.Filter.eq(‘system:index’, ‘00000000000000002bf8’)) //Sửa thành 00000000000000000983 để có khu vực Hà Nội

var geometry = filtered.geometry()

var rgbVis = {

  min: 0.0,

  max: 3000,

  bands: [‘B4’, ‘B3’, ‘B2’], 

};

var filtered = s2.filter(ee.Filter.lt(‘CLOUDY_PIXEL_PERCENTAGE’, 30))

  .filter(ee.Filter.date(‘2019-01-01’, ‘2020-01-01’))

  .filter(ee.Filter.bounds(geometry))

var image = filtered.median(); 

var clipped = image.clip(geometry)

Map.addLayer(clipped, rgbVis, ‘Clipped’) 

Map.centerObject(clipped, 8)

var exportImage = clipped.select(‘B.*’)

//Đoạn code export dữ liệu

Export.image.toDrive({

    image: exportImage,

    description: ‘Bangalore_Composite_Raw’,

    folder: ‘earthengine’,

    fileNamePrefix: ‘bangalore_composite_raw’,

    region: geometry,

    scale: 20,

    maxPixels: 1e9

})

// Rather than exporting raw bands, we can apply a rendered image

// visualize() function allows you to apply the same parameters 

// that are used in earth engine which exports a 3-band RGB image

// Thay vì xuất các dải thô, chúng ta có thể áp dụng hình ảnh được kết xuất

// hàm visual() cho phép bạn áp dụng các tham số giống nhau

// được sử dụng trong công cụ Earth Engine xuất hình ảnh RGB 3 band

print(clipped)

var visualized = clipped.visualize(rgbVis)

print(visualized)

// Now the ‘visualized’ image is RGB image, no need to give visParams

Map.addLayer(visualized, {}, ‘Visualized Image’) 

Export.image.toDrive({

    image: visualized,

    description: ‘Bangalore_Composite_Visualized’,

    folder: ‘earthengine’,

    fileNamePrefix: ‘bangalore_composite_visualized’,

    region: geometry,

    scale: 20,

    maxPixels: 1e9

})

3.8.1. Bài tập

// Write the export function to export the results for your chosen urban area

// Viết hàm xuất để xuất kết quả cho khu vực thành thị bạn đã chọn

3.8.2. Kết quả

// Write the export function to export the results for your chosen urban area

// Viết hàm xuất để xuất kết quả cho khu vực thành thị bạn đã chọn

var s2 = ee.ImageCollection(“COPERNICUS/S2”)

var urban = ee.FeatureCollection(“users/ujavalgandhi/e2e/ne_10m_urban_areas”)

var filtered = urban.filter(ee.Filter.eq(‘system:index’, ‘00000000000000000983’)) //Sửa thành 00000000000000000983 để có khu vực Hà Nội

var geometry = filtered.geometry()

var rgbVis = {

  min: 0.0,

  max: 3000,

  bands: [‘B4’, ‘B3’, ‘B2’], 

};

var filtered = s2.filter(ee.Filter.lt(‘CLOUDY_PIXEL_PERCENTAGE’, 30))

  .filter(ee.Filter.date(‘2019-01-01’, ‘2020-01-01’))

  .filter(ee.Filter.bounds(geometry))

var image = filtered.median(); 

var clipped = image.clip(geometry)

Map.addLayer(clipped, rgbVis, ‘Clipped’) 

Map.centerObject(clipped, 8)

var exportImage = clipped.select(‘B.*’)

Export.image.toDrive({

    image: exportImage,

    description: ‘Bangalore_Composite_Raw’,

    folder: ‘earthengine’,

    fileNamePrefix: ‘bangalore_composite_raw’,

    region: geometry,

    scale: 20,

    maxPixels: 1e9

})

// Rather than exporting raw bands, we can apply a rendered image

// visualize() function allows you to apply the same parameters 

// that are used in earth engine which exports a 3-band RGB image

// Thay vì xuất các dải thô, chúng ta có thể áp dụng hình ảnh được kết xuất

// hàm visual() cho phép bạn áp dụng các tham số giống nhau

// được sử dụng trong công cụ Earth Engine xuất hình ảnh RGB 3 band

print(clipped)

var visualized = clipped.visualize(rgbVis)

print(visualized)

// Now the ‘visualized’ image is RGB image, no need to give visParams

Map.addLayer(visualized, {}, ‘Visualized Image’) 

Export.image.toDrive({

    image: visualized,

    description: ‘Bangalore_Composite_Visualized’,

    folder: ‘earthengine’,

    fileNamePrefix: ‘bangalore_composite_visualized’,

    region: geometry,

    scale: 20,

    maxPixels: 1e9

})

Xem video hướng dẫn

Recommended For You

About the Author: Admin