이미지 내보내기

Earth Engine에서 GeoTIFF 또는 TFRecord 형식으로 이미지를 내보낼 수 있습니다. 더 많은 출력 옵션은 구성 매개변수를 참조하세요.

설정 예시

내보낼 이미지 데이터를 정의하는 것으로 시작합니다.

코드 편집기(JavaScript)

// Load a landsat image and select three bands.
var landsat = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_123032_20140515')
  .select(['B4', 'B3', 'B2']);

// Create a geometry representing an export region.
var geometry = ee.Geometry.Rectangle([116.2621, 39.8412, 116.4849, 40.01236]);

Python 설정

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

import ee
import geemap.core as geemap

Colab(Python)

# Load a landsat image and select three bands.
landsat = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_123032_20140515').select(
    ['B4', 'B3', 'B2']
)

# Create a geometry representing an export region.
geometry = ee.Geometry.Rectangle([116.2621, 39.8412, 116.4849, 40.01236])

다음으로 다음 내보내기에 사용할 투영 매개변수를 정의합니다. crs 매개변수를 사용하여 좌표계를 지정하고 crsTransform 매개변수를 사용하여 픽셀 그리드를 정확하게 지정합니다. crsTransform 매개변수는 행 우선 순서 [xScale, xShearing, xTranslation, yShearing, yScale, yTranslation]의 아핀 변환 행렬에서 가져온 매개변수 목록입니다. 이미지의 원점은 xTranslation 및 yTranslation 값으로 정의되고 이미지의 픽셀 크기는 xScale 및 yScale 값으로 정의됩니다. 아핀 행렬의 예시를 참조하세요.

코드 편집기(JavaScript)

// Retrieve the projection information from a band of the original image.
// Call getInfo() on the projection to request a client-side object containing
// the crs and transform information needed for the client-side Export function.
var projection = landsat.select('B2').projection().getInfo();

Python 설정

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

import ee
import geemap.core as geemap

Colab(Python)

# Retrieve the projection information from a band of the original image.
# Call getInfo() on the projection to request a client-side object containing
# the crs and transform information needed for the client-side Export function.
projection = landsat.select('B2').projection().getInfo()

scale 설정

바로가기로 scale 매개변수를 지정하면 Earth Engine에서 crsTransform 매개변수를 계산합니다. 하지만 이미지의 배율을 설정하는 것만으로는 투영의 원점을 지정할 수 없으며, 동일한 픽셀 크기의 다른 이미지에 비해 이동된 이미지가 생성될 수 있습니다.

잠재적 이동의 이유는 scale 매개변수가 crsTransform의 xScale 및 yScale 값을 채우는 데 사용되지만 xTranslation 및 yTranslation 값은 해당 xScale 및 yScale 값으로 나누면 나머지가 0이 되도록 계산되기 때문입니다. 이러한 매개변수는 투영의 원점이 픽셀의 모서리에 있는 픽셀 그리드를 지정합니다. 이 규칙은 투영의 원점에서 오프셋된 그리드를 사용하는 일부 데이터 제공업체에서 사용하는 변환 매개변수와 다릅니다. 예를 들어 USGS에서 제공하는 Landsat 이미지는 투영 원점에서 1/2픽셀만큼 오프셋된 변환 매개변수 (30m 대역의 경우 15m 오프셋)를 사용하는 반면 ESA에서 제공하는 Sentinel-2 이미지는 투영 원점과 정렬된 변환 매개변수를 사용합니다. 내보내기에 지정된 crsTransform가 원본 이미지의 crsTransform와 일치하지 않으면 출력 픽셀이 다시 샘플링되어 (기본적으로 최근접 이웃 사용) 결과 이미지가 원본 이미지에 비해 이동됩니다.

요약하자면 내보낸 이미지의 픽셀을 특정 이미지와 일치시켜야 하는 경우 crs 및 crsTransform 매개변수를 사용하여 그리드를 완전히 제어해야 합니다.

Drive에 추가

Drive 계정으로 이미지를 내보내려면 Export.image.toDrive()를 사용합니다. 예를 들어 Landsat 이미지의 일부를 내보내려면 내보낼 리전을 정의한 후 Export.image.toDrive()를 호출합니다.

코드 편집기(JavaScript)

// Export the image, specifying the CRS, transform, and region.
Export.image.toDrive({
  image: landsat,
  description: 'imageToDriveExample_transform',
  crs: projection.crs,
  crsTransform: projection.transform,
  region: geometry
});

Python 설정

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

import ee
import geemap.core as geemap

Colab(Python)

# Export the image, specifying the CRS, transform, and region.
task = ee.batch.Export.image.toDrive(
    image=landsat,
    description='imageToDriveExample_transform',
    crs=projection['crs'],
    crsTransform=projection['transform'],
    region=geometry,
)
task.start()

이 코드가 실행되면 코드 편집기 태스크 탭에 내보내기 태스크가 생성됩니다. 작업 옆에 있는 실행 버튼을 클릭하여 작업을 시작합니다. (코드 편집기 섹션에서 작업 관리자에 대해 자세히 알아보기) 지정된 fileFormat를 사용하여 Drive 계정에 이미지가 생성됩니다.

Cloud Storage로 전송

Google Cloud Storage 버킷으로 이미지를 내보내려면 Export.image.toCloudStorage()을 사용합니다. 이전 예시의 Landsat 이미지를 Drive 대신 Cloud Storage로 내보내려면 다음을 사용하세요.

코드 편집기(JavaScript)

// Export the image to Cloud Storage.
Export.image.toCloudStorage({
  image: landsat,
  description: 'imageToCloudExample',
  bucket: 'your-bucket-name',
  fileNamePrefix: 'exampleExport',
  crs: projection.crs,
  crsTransform: projection.transform,
  region: geometry
});

Python 설정

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

import ee
import geemap.core as geemap

Colab(Python)

# Export the image to Cloud Storage.
task = ee.batch.Export.image.toCloudStorage(
    image=landsat,
    description='imageToCloudExample',
    bucket='your-bucket-name',
    fileNamePrefix='exampleExport',
    crs=projection['crs'],
    crsTransform=projection['transform'],
    region=geometry,
)
task.start()

Drive로 내보내기와 마찬가지로 작업 탭에서 내보내기를 시작합니다. 내보낸 파일을 Earth Engine으로 다시 읽어오려는 경우(ee.Image.loadGeoTIFF() 사용 또는 COG 지원 애셋으로 등록) 버킷이 지원되는 위치에 있어야 합니다.

저작물로

Earth Engine 애셋 폴더의 애셋으로 이미지를 내보내려면 Export.image.toAsset()를 사용합니다. Earth Engine 애셋을 관리하거나 사용 중인 스토리지 한도를 확인하려면 애셋 관리자를 사용하세요. 다음 예시에서는 동일한 밴드에 서로 다른 피라미드 정책을 사용하여 Landsat 이미지의 일부를 내보내는 방법을 보여줍니다. 피라미드 정책은 Earth Engine이 애셋의 저해상도 버전을 계산하는 방법을 나타냅니다. Earth Engine에서 여러 해상도를 처리하는 방법에 대한 자세한 내용은 스케일 문서를 참조하세요.

코드 편집기(JavaScript)

// Get band 4 from the Landsat image, copy it.
var band4 = landsat.select('B4').rename('b4_mean')
  .addBands(landsat.select('B4').rename('b4_sample'))
  .addBands(landsat.select('B4').rename('b4_max'));

// Export the image to an Earth Engine asset.
Export.image.toAsset({
  image: band4,
  description: 'imageToAssetExample',
  assetId: 'exampleExport',
  crs: projection.crs,
  crsTransform: projection.transform,
  region: geometry,
  pyramidingPolicy: {
    'b4_mean': 'mean',
    'b4_sample': 'sample',
    'b4_max': 'max'
  }
});

Python 설정

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

import ee
import geemap.core as geemap

Colab(Python)

# Get band 4 from the Landsat image, copy it.
band_4 = (
    landsat.select('B4')
    .rename('b4_mean')
    .addBands(landsat.select('B4').rename('b4_sample'))
    .addBands(landsat.select('B4').rename('b4_max'))
)

# Export the image to an Earth Engine asset.
task = ee.batch.Export.image.toAsset(
    image=band_4,
    description='imageToAssetExample',
    assetId='projects/your-project/assets/exampleExport',
    crs=projection['crs'],
    crsTransform=projection['transform'],
    region=geometry,
    pyramidingPolicy={
        'b4_mean': 'mean',
        'b4_sample': 'sample',
        'b4_max': 'max',
    },
)
task.start()

'.default' 키를 사용하여 명시적으로 지정되지 않은 모든 밴드에 기본 피라미드 정책을 제공할 수 있습니다. '.default' 키만 전달할 수도 있습니다. 예를 들어 모든 밴드를 '샘플' 피라미드 정책으로 기본 설정하려면 {'.default': 'sample'}를 사용합니다.

구성 매개변수

Export.image에 전달된 구성 매개변수의 사전에 scale (미터 단위)과 내보내기 리전이 ee.Geometry로 포함되어 있는지 확인합니다. 내보낸 이미지는 지정된 축척의 픽셀로 지정된 영역을 포함합니다. 명시적으로 지정하지 않으면 출력의 CRS가 내보낼 이미지의 첫 번째 밴드에서 가져옵니다.

내보낸 이미지의 dimensions, crs 또는 crsTransform를 지정할 수도 있습니다. crs 및 crsTransform에 대한 자세한 내용은 용어집을 참조하세요. 예를 들어 다른 데이터 소스에 정확하게 정렬된 픽셀 블록을 가져오려면 dimensions, crs, crsTransform를 지정합니다. 영역을 포함하는 사전 정의된 크기 (예: 256x256 썸네일 이미지)의 픽셀 블록을 가져오려면 dimensions 및 region를 지정합니다.

fileFormat 매개변수 (기본값: 'GeoTIFF')를 사용하여 이미지 출력 형식(대상 위치가 toAsset()가 아닌 경우)을 지정할 수 있습니다.

formatOptions 매개변수

다른 구성 옵션은 formatOptions 매개변수로 설정됩니다. 이 매개변수는 아래 설명된 대로 각 fileFormat에 고유한 다른 형식 옵션으로 키가 지정된 사전이어야 합니다.

GeoTIFF

클라우드 최적화 GeoTIFF(COG)

Cloud Optimized GeoTIFF(COG)를 내보내려면 formatOptions에서 cloudOptimized 키를 true로 설정합니다. 이전 예시를 계속 진행합니다.

코드 편집기(JavaScript)

// Export a cloud-optimized GeoTIFF.
Export.image.toDrive({
  image: landsat,
  description: 'imageToCOGeoTiffExample',
  crs: projection.crs,
  crsTransform: projection.transform,
  region: geometry,
  fileFormat: 'GeoTIFF',
  formatOptions: {
    cloudOptimized: true
  }
});

Python 설정

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

import ee
import geemap.core as geemap

Colab(Python)

# Export a cloud-optimized GeoTIFF.
task = ee.batch.Export.image.toDrive(
    image=landsat,
    description='imageToCOGeoTiffExample',
    crs=projection['crs'],
    crsTransform=projection['transform'],
    region=geometry,
    fileFormat='GeoTIFF',
    formatOptions={'cloudOptimized': True},
)
task.start()

COG는 Cloud Storage에서 Image로 다시 로드하거나 애셋으로 등록할 수 있습니다. 전체 내보내기 사양 및 옵션은 COG 개요를 참조하세요.

Nodata

formatOptions 매개변수 내에서 noData 키를 사용하여 GeoTIFF nodata 값을 지정합니다. 예를 들면 다음과 같습니다.

코드 편집기(JavaScript)

// Set a nodata value and replace masked pixels around the image edge with it.
var noDataVal = -9999;
landsat = landsat.unmask(noDataVal);

Export.image.toDrive({
  image: landsat,
  description: 'imageNoDataExample',
  crs: projection.crs,
  scale: 2000,  // large scale for minimal demo
  region: landsat.geometry(),  // full image bounds
  fileFormat: 'GeoTIFF',
  formatOptions: {
    noData: noDataVal,
  }
});

Python 설정

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

import ee
import geemap.core as geemap

Colab(Python)

# Set a nodata value and replace masked pixels around the image edge with it.
no_data_val = -9999
landsat = landsat.unmask(no_data_val)

task = ee.batch.Export.image.toDrive(
    image=landsat,
    description='imageNoDataExample',
    crs=projection['crs'],
    scale=2000,  # large scale for minimal demo
    region=landsat.geometry(),  # full image bounds
    fileFormat='GeoTIFF',
    formatOptions={'noData': no_data_val},
)
task.start()

nodata 값은 이미지 PixelType의 유효한 범위 내에 있어야 합니다. 이미지 메타데이터를 출력하고 첫 번째 밴드의 data_type 속성을 확인하여 PixelType를 확인할 수 있습니다. 예를 들어 이미지 메서드 toShort() 또는 toInt()를 사용하여 데이터를 특정 유형으로 변환하여 이미지의 PixelType를 설정할 수도 있습니다.

TFRecord

TFRecord 데이터 형식 페이지를 참조하세요.

maxPixels

maxPixels 매개변수는 매우 큰 내보내기가 실수로 생성되지 않도록 방지하기 위한 것입니다. 기본값이 의도한 출력 이미지에 비해 너무 낮으면 maxPixels를 늘릴 수 있습니다. 예를 들면 다음과 같습니다.

Export.image.toDrive({
  image: landsat,
  description: 'maxPixelsExample',
  crs: projection.crs,
  crsTransform: projection.transform,
  region: geometry,
  maxPixels: 1e9
});

대용량 파일 내보내기

출력 이미지가 큰 경우 여러 파일로 내보내집니다. GeoTIFF로 내보내는 경우 이미지가 타일로 분할됩니다. 각 타일의 파일 이름은 baseFilename-yMin-xMin 형식입니다. 여기서 xMin 및 yMin는 내보낸 이미지의 전체 경계 상자 내에 있는 각 타일의 좌표입니다.

TFRecord로 내보내는 경우 파일은 N+1 파일에 대해 -00000, -00001,… -0000N로 추가됩니다. 파일에 대해 추론을 수행하고 예측을 이미지로 Earth Engine에 다시 업로드하려면 이 순서를 유지하는 것이 중요합니다. 자세한 내용은 TFRecord 파일로 이미지 업로드를 참조하세요.

코드 편집기에 표시되는 이미지 내보내기

Earth Engine에서 화면에 렌더링된 이미지를 내보내려면 시각화 이미지 및 합성 및 모자이크 섹션에 설명된 대로 시각화 이미지를 만듭니다. 코드 편집기는 'EPSG:3857' CRS를 사용하므로 내보내기에서 'EPSG:3857'의 CRS를 지정하여 코드 편집기 지도에 표시된 것과 동일한 투영으로 이미지를 가져옵니다. 출력의 해상도 및 좌표계를 지정하는 방법에 대한 자세한 내용은 이미지 내보내기 구성 섹션을 참조하세요.