אתם יכולים לייצא תמונות מ-Earth Engine בפורמט GeoTIFF או TFRecord. בקטע פרמטרים של הגדרות אישיות מפורטות אפשרויות פלט נוספות.
הגדרה לדוגמה
קודם כל, מגדירים את נתוני התמונה שרוצים לייצא:
Code Editor (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]);
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 הוא רשימה של פרמטרים ממטריצת טרנספורמציה אפינית בסדר row-major [xScale, xShearing, xTranslation, yShearing, yScale, yTranslation]. מקור התמונה מוגדר על ידי הערכים xTranslation ו-yTranslation, וגודל הפיקסלים של התמונה מוגדר על ידי הערכים xScale ו-yScale. דוגמאות למטריצות אפיניות
Code Editor (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();
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 משמש לאכלוס הערכים xScale ו-yScale של crsTransform, אבל הערכים xTranslation ו-yTranslation מחושבים כך שאם הם מחולקים בערכים התואמים של xScale ו-yScale, השארית תהיה אפס. הפרמטרים האלה מציינים רשת פיקסלים שבה נקודת המוצא של ההיטל נמצאת בפינה של פיקסל. המוסכמה הזו שונה מפרמטרי התרגום שבהם משתמשים חלק מספקי הנתונים, שמשתמשים ברשתות שמוסטות מהמקור של ההיטל. לדוגמה, בתמונות Landsat שסופקו על ידי USGS נעשה שימוש בפרמטרים של תרגום שמוסטים בחצי פיקסל מהמקור של ההיטל (היסט של 15 מטרים לפסים של 30 מטרים), ואילו בתמונות Sentinel-2 שסופקו על ידי ESA נעשה שימוש בפרמטרים של תרגום שתואמים למקור של ההיטל. אם ה-crsTransform שצוין בייצוא לא תואם ל-crsTransform של התמונה המקורית, הפיקסלים של הפלט יידגמו מחדש (באמצעות השכן הקרוב ביותר כברירת מחדל), מה שיגרום לתמונה שתתקבל להיות מוסטת ביחס לתמונה המקורית.
לסיכום, אם אתם צריכים להתאים את הפיקסלים של התמונה המיוצאת לתמונה ספציפית, הקפידו להשתמש בפרמטרים crs ו-crsTransform כדי לקבל שליטה מלאה על הרשת.
ל-Drive
כדי לייצא תמונה לחשבון Drive, משתמשים ב-Export.image.toDrive(). לדוגמה, כדי לייצא חלקים מתמונה של Landsat, מגדירים אזור לייצוא ואז מפעילים את Export.image.toDrive():
Code Editor (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 });
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()
כשהקוד הזה יופעל, תיווצר משימת ייצוא בכרטיסייה Tasks (משימות) בכלי לעריכת קוד. לוחצים על הכפתור הפעלה לצד המשימה כדי להתחיל אותה. (מידע נוסף על מנהל המשימות זמין בקטע "עורך הקוד"). התמונה תיווצר בחשבון Drive שלכם עם fileFormat שציינתם.
ל-Cloud Storage
כדי לייצא קובץ אימג' לקטגוריה של Google Cloud Storage, משתמשים ב-Export.image.toCloudStorage(). כדי לייצא את תמונת Landsat מהדוגמה הקודמת ל-Cloud Storage במקום ל-Drive, משתמשים בקוד הבא:
Code Editor (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 });
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 מטפל ברזולוציות מרובות.
Code Editor (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' } });
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.
אפשר לציין את פורמט הפלט של התמונה (אם היעד הוא לא toAsset()) באמצעות הפרמטר fileFormat ('GeoTIFF' כברירת מחדל).
פרמטר formatOptions
אפשרויות הגדרה אחרות נקבעות באמצעות הפרמטר formatOptions, שצריך להיות מילון עם מפתחות של אפשרויות פורמט אחרות, ספציפיות לכל fileFormat, כפי שמתואר בהמשך.
GeoTIFF
Cloud Optimized GeoTIFF (COG)
כדי לייצא Cloud Optimized GeoTIFF (COG), מגדירים את המפתח cloudOptimized לערך true ב-formatOptions. בהמשך לדוגמה הקודמת:
Code Editor (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 } });
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
מציינים את הערך של GeoTIFF nodata באמצעות המפתח noData בפרמטר formatOptions. לדוגמה:
Code Editor (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, } });
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 של התמונה. אפשר לבדוק את PixelType על ידי הדפסת המטא-נתונים של התמונה ובדיקת המאפיין data_type של הרצועה הראשונה. אפשר גם להגדיר את PixelType של התמונה על ידי המרת הנתונים לסוג ספציפי באמצעות שיטות התמונה toShort() או toInt(), לדוגמה.
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, הקבצים יתווספו על ידי -00000, -00001,… -0000N עבור קובצי N+1. חשוב לשמור על הסדר הזה אם אתם מתכוונים לבצע הסקה על הקבצים ולהעלות את החיזויים בחזרה ל-Earth Engine כתמונה. פרטים נוספים זמינים במאמר העלאת תמונות כקובצי TFRecord.
ייצוא תמונות כפי שהן מופיעות בעורך הקוד
כדי לייצא תמונות כפי שהן מוצגות במסך ב-Earth Engine, צריך ליצור תמונות להמחשה כפי שמוסבר בקטעים תמונות להמחשה ויצירת קומפוזיציות ופסיפסים. מכיוון ש-Code Editor משתמש ב-CRS של 'EPSG:3857', צריך לציין CRS של 'EPSG:3857' בייצוא כדי לקבל תמונה באותו היטל כמו זה שמוצג במפה של Code Editor. בקטע שעוסק בהגדרת ייצוא תמונות מוסבר איך לציין את הרזולוציה ואת מערכת הקואורדינטות של הפלט.