הצגה חזותית של תמונות

יש כמה שיטות של ee.Image שמפיקות ייצוגים חזותיים של RGB של נתוני תמונות, לדוגמה: visualize(), getThumbURL(), getMap(), getMapId() (בשימוש בתצוגת המפה של Colab Folium) וגם, Map.addLayer() (בשימוש בתצוגת המפה של Code Editor, לא זמין ל-Python). כברירת מחדל, השיטות האלה מקצות את שלושת הפסים הראשונים לאדום, ירוק וכחול, בהתאמה. ברירת המחדל של המתיחה מבוססת על סוג הנתונים ברצועות (למשל, ערכי float נמתחים ב-[0, 1], נתונים של 16 ביט נמתחים לטווח המלא של הערכים האפשריים), שיכול להיות מתאים או לא מתאים. כדי להשיג את אפקטי התצוגה הרצויים, אפשר לספק פרמטרים של תצוגה:

פרמטרים של תצוגה חזותית של תמונות
פרמטר תיאור סוג
להקות רשימה מופרדת בפסיקים של שלושה שמות של ערוצים שימופו ל-RGB list
דקות ערכים למיפוי ל-0 מספר או רשימה של שלושה מספרים, אחד לכל פס
max הערכים למיפוי ל-255 מספר או רשימה של שלושה מספרים, אחד לכל פס
gain הערכים שבהם צריך להכפיל כל ערך של פיקסל מספר או רשימה של שלושה מספרים, אחד לכל פס
bias הערכים שצריך להוסיף לכל DN מספר או רשימה של שלושה מספרים, אחד לכל פס
gamma גורמי תיקון גאמה מספר או רשימה של שלושה מספרים, אחד לכל פס
palette רשימה של מחרוזות צבע בסגנון CSS (תמונות עם פס אחד בלבד) רשימה מופרדת בפסיקים של מחרוזות הקסדצימליות
opacity האטימות של השכבה (0.0 היא שקיפות מלאה ו-1.0 היא אטימות מלאה) number
פורמט "jpg" או "png" מחרוזת

תמונות RGB משולבות

הדוגמה הבאה ממחישה את השימוש בפרמטרים כדי לעצב תמונה של Landsat 8 כקומפוזיציה של צבעים שגויים:

Code Editor (JavaScript)

// Load an image.
var image = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140318');

// Define the visualization parameters.
var vizParams = {
  bands: ['B5', 'B4', 'B3'],
  min: 0,
  max: 0.5,
  gamma: [0.95, 1.1, 1]
};

// Center the map and display the image.
Map.setCenter(-122.1899, 37.5010, 10); // San Francisco Bay
Map.addLayer(image, vizParams, 'false color composite');

הגדרה של Python

בדף סביבת Python מפורט מידע על API בשפת Python ועל השימוש ב-geemap לפיתוח אינטראקטיבי.

import ee
import geemap.core as geemap

Colab (Python)

# Load an image.
image = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140318')

# Define the visualization parameters.
image_viz_params = {
    'bands': ['B5', 'B4', 'B3'],
    'min': 0,
    'max': 0.5,
    'gamma': [0.95, 1.1, 1],
}

# Define a map centered on San Francisco Bay.
map_l8 = geemap.Map(center=[37.5010, -122.1899], zoom=10)

# Add the image layer to the map and display it.
map_l8.add_layer(image, image_viz_params, 'false color composite')
display(map_l8)

בדוגמה הזו, הערוץ 'B5' מוקצה לאדום, הערוץ 'B4' מוקצה לירוק והערוץ 'B3' מוקצה לכחול.

false_color_sf
תמונה משולבת בצבעים מדומים של אזור מפרץ סן פרנסיסקו, קליפורניה, ארה"ב, שצולמה על ידי Landsat 8.

לוחות צבעים

כדי להציג פס בודד של תמונה בצבע, מגדירים את הפרמטר palette עם סולם צבעים שמיוצג על ידי רשימה של מחרוזות צבע בסגנון CSS. (מידע נוסף זמין במאמר הזה). בדוגמה הבאה אפשר לראות איך משתמשים בצבעים מציאן ('00FFFF') לכחול ('0000FF') כדי לעבד תמונה של Normalized Difference Water Index (NDWI):

Code Editor (JavaScript)

// Load an image.
var image = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140318');

// Create an NDWI image, define visualization parameters and display.
var ndwi = image.normalizedDifference(['B3', 'B5']);
var ndwiViz = {min: 0.5, max: 1, palette: ['00FFFF', '0000FF']};
Map.addLayer(ndwi, ndwiViz, 'NDWI', false);

הגדרה של Python

בדף סביבת Python מפורט מידע על API בשפת Python ועל השימוש ב-geemap לפיתוח אינטראקטיבי.

import ee
import geemap.core as geemap

Colab (Python)

# Load an image.
image = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140318')

# Create an NDWI image, define visualization parameters and display.
ndwi = image.normalizedDifference(['B3', 'B5'])
ndwi_viz = {'min': 0.5, 'max': 1, 'palette': ['00FFFF', '0000FF']}

# Define a map centered on San Francisco Bay.
map_ndwi = geemap.Map(center=[37.5010, -122.1899], zoom=10)

# Add the image layer to the map and display it.
map_ndwi.add_layer(ndwi, ndwi_viz, 'NDWI')
display(map_ndwi)

בדוגמה הזו, שימו לב שהפרמטרים min ו-max מציינים את טווח ערכי הפיקסלים שעליהם צריך להחיל את לוח הצבעים. ערכי הביניים נמתחים באופן לינארי.

‫שימו לב גם שהפרמטר show מוגדר כ-false בדוגמה של עורך הקוד. כתוצאה מכך, השכבה לא תהיה גלויה כשהיא תתווסף למפה. תמיד אפשר להפעיל אותה שוב באמצעות מנהל השכבות בפינה השמאלית העליונה של המפה בכלי לעריכת קוד.

ndwi_sf
‫Landsat 8 NDWI, אזור מפרץ סן פרנסיסקו, ארה"ב. טורקיז מייצג ערכים נמוכים, כחול מייצג ערכים גבוהים.

שמירת לוחות הצבעים שמוגדרים כברירת מחדל

כדי לשמור פלטות צבעים בתמונת סיווג כך שלא תצטרכו לזכור להחיל אותן, אתם יכולים להגדיר שני מאפייני תמונה של מחרוזת עם שמות מיוחדים לכל פס סיווג.

לדוגמה, אם בתמונה יש פס בשם 'landcover' עם שלושה ערכים (0, 1 ו-2) שתואמים לסיווגים "מים", "יער" ו"אחר", אפשר להגדיר את המאפיינים הבאים כדי שבתצוגה החזותית שמוגדרת כברירת מחדל יופיע צבע מסוים לכל סיווג (הערכים שמשמשים לניתוח לא יושפעו):

  • landcover_class_values="0,1,2"
  • landcover_class_palette="0000FF,00FF00,AABBCD"

בדף הנכסים מוסבר איך להגדיר מטא נתונים של נכס.

מסכה

אפשר להשתמש ב-image.updateMask() כדי להגדיר את האטימות של פיקסלים ספציפיים על סמך המיקום של פיקסלים בתמונת מסכה שהערך שלהם הוא לא אפס. פיקסלים ששווים לאפס במסכה לא נכללים בחישובים, ורמת האטימות שלהם מוגדרת ל-0 בתצוגה. בדוגמה הבאה נעשה שימוש בסף NDWI (למידע על ספים, עיינו בקטע פעולות יחסיות) כדי לעדכן את המסכה בשכבת ה-NDWI שנוצרה קודם:

Code Editor (JavaScript)

// Mask the non-watery parts of the image, where NDWI < 0.4.
var ndwiMasked = ndwi.updateMask(ndwi.gte(0.4));
Map.addLayer(ndwiMasked, ndwiViz, 'NDWI masked');

הגדרה של Python

בדף סביבת Python מפורט מידע על API בשפת Python ועל השימוש ב-geemap לפיתוח אינטראקטיבי.

import ee
import geemap.core as geemap

Colab (Python)

# Mask the non-watery parts of the image, where NDWI < 0.4.
ndwi_masked = ndwi.updateMask(ndwi.gte(0.4))

# Define a map centered on San Francisco Bay.
map_ndwi_masked = geemap.Map(center=[37.5010, -122.1899], zoom=10)

# Add the image layer to the map and display it.
map_ndwi_masked.add_layer(ndwi_masked, ndwi_viz, 'NDWI masked')
display(map_ndwi_masked)

תמונות להמחשה

משתמשים ב-method‏ image.visualize() כדי להמיר תמונה לתמונת RGB של 8 ביט, להצגה או לייצוא. לדוגמה, כדי להמיר את התמונה המשולבת בצבעים מלאכותיים ואת ה-NDWI לתמונות תצוגה עם 3 ערוצים, משתמשים בקוד הבא:

Code Editor (JavaScript)

// Create visualization layers.
var imageRGB = image.visualize({bands: ['B5', 'B4', 'B3'], max: 0.5});
var ndwiRGB = ndwiMasked.visualize({
  min: 0.5,
  max: 1,
  palette: ['00FFFF', '0000FF']
});

הגדרה של Python

בדף סביבת Python מפורט מידע על API בשפת Python ועל השימוש ב-geemap לפיתוח אינטראקטיבי.

import ee
import geemap.core as geemap

Colab (Python)

image_rgb = image.visualize(bands=['B5', 'B4', 'B3'], max=0.5)
ndwi_rgb = ndwi_masked.visualize(min=0.5, max=1, palette=['00FFFF', '0000FF'])

פסיפס

אפשר להשתמש במסכות וב-imageCollection.mosaic() (מידע נוסף זמין בקטע בנושא פסיפס) כדי להשיג אפקטים קרטוגרפיים שונים. ה-method‏ mosaic() מעבדת שכבות בתמונת הפלט לפי הסדר שלהן באוסף הקלט. בדוגמה הבאה משתמשים ב-mosaic() כדי לשלב את ה-NDWI המוסתר ואת השילוב של הצבעים המזויפים ולקבל תצוגה חזותית חדשה:

Code Editor (JavaScript)

// Mosaic the visualization layers and display (or export).
var mosaic = ee.ImageCollection([imageRGB, ndwiRGB]).mosaic();
Map.addLayer(mosaic, {}, 'mosaic');

הגדרה של Python

בדף סביבת Python מפורט מידע על API בשפת Python ועל השימוש ב-geemap לפיתוח אינטראקטיבי.

import ee
import geemap.core as geemap

Colab (Python)

# Mosaic the visualization layers and display (or export).
mosaic = ee.ImageCollection([image_rgb, ndwi_rgb]).mosaic()

# Define a map centered on San Francisco Bay.
map_mosaic = geemap.Map(center=[37.5010, -122.1899], zoom=10)

# Add the image layer to the map and display it.
map_mosaic.add_layer(mosaic, None, 'mosaic')
display(map_mosaic)

בדוגמה הזו, שימו לב שרשימה של שתי תמונות הוויזואליזציה נשלחת ל-constructor של ImageCollection. הסדר של הרשימה קובע את הסדר שבו התמונות מוצגות במפה.

mosaic_sf
פסיפס של קומפוזיציה בצבעים מדומים של Landsat 8 ו-NDWI. אזור מפרץ סן פרנסיסקו, ארה"ב.

קליפ

השיטה image.clip() שימושית להשגת אפקטים קרטוגרפיים. בדוגמה הבאה, הפסיפס שנוצר קודם נחתך לאזור מאגר שרירותי מסביב לעיר סן פרנסיסקו:

Code Editor (JavaScript)

// Create a circle by drawing a 20000 meter buffer around a point.
var roi = ee.Geometry.Point([-122.4481, 37.7599]).buffer(20000);

// Display a clipped version of the mosaic.
Map.addLayer(mosaic.clip(roi), null, 'mosaic clipped');

הגדרה של Python

בדף סביבת Python מפורט מידע על API בשפת Python ועל השימוש ב-geemap לפיתוח אינטראקטיבי.

import ee
import geemap.core as geemap

Colab (Python)

# Create a circle by drawing a 20000 meter buffer around a point.
roi = ee.Geometry.Point([-122.4481, 37.7599]).buffer(20000)
mosaic_clipped = mosaic.clip(roi)

# Define a map centered on San Francisco.
map_mosaic_clipped = geemap.Map(center=[37.7599, -122.4481], zoom=10)

# Add the image layer to the map and display it.
map_mosaic_clipped.add_layer(mosaic_clipped, None, 'mosaic clipped')
display(map_mosaic_clipped)

בדוגמה הקודמת, שימו לב שהקואורדינטות מסופקות ל-constructor של Geometry, ואורך המאגר מצוין כ-20,000 מטרים. מידע נוסף על גיאומטריות

clipped_sf
הפסיפס שמוצג למעלה, חתוך למאגר סביב סן פרנסיסקו, קליפורניה, ארה"ב.

עיבוד מפות קטגוריות

פלטות שימושיות גם לעיבוד מפות עם ערכים נפרדים, למשל מפה של תכסית קרקע. אם יש כמה מחלקות, משתמשים בלוח הצבעים כדי להגדיר צבע שונה לכל מחלקה. (השיטה image.remap() יכולה להיות שימושית בהקשר הזה, כדי להמיר תוויות שרירותיות למספרים שלמים עוקבים). בדוגמה הבאה נעשה שימוש בפלטה כדי לעבד קטגוריות של תכסית קרקע:

Code Editor (JavaScript)

// Load 2012 MODIS land cover and select the IGBP classification.
var cover = ee.Image('MODIS/061/MCD12Q1/2012_01_01')
  .select('LC_Type1');

// Define a palette for the 17 distinct land cover classes.
var igbpPalette = [
  '152106', '225129', '369b47', '30eb5b', '387242', // forest
  '6a2325', 'c3aa69', 'b76031', 'd9903d', '91af40',  // shrub, grass
  '111149', // wetlands
  'cdb33b', // croplands
  'cc0013', // urban
  '33280d', // crop mosaic
  'd7cdcc', // snow and ice
  'f7e084', // barren
  'aec3d4'  // water
];

// Specify the min and max labels and the color palette matching the labels.
Map.setCenter(-99.229, 40.413, 5);
Map.addLayer(cover,
             {min: 1, max: 17, palette: igbpPalette},
             'IGBP classification');

הגדרה של Python

בדף סביבת Python מפורט מידע על API בשפת Python ועל השימוש ב-geemap לפיתוח אינטראקטיבי.

import ee
import geemap.core as geemap

Colab (Python)

# Load 2012 MODIS land cover and select the IGBP classification.
cover = ee.Image('MODIS/061/MCD12Q1/2012_01_01').select('LC_Type1')

# Define a palette for the 17 distinct land cover classes.
igbp_palette = [
    '152106',
    '225129',
    '369b47',
    '30eb5b',
    '387242',  # forest
    '6a2325',
    'c3aa69',
    'b76031',
    'd9903d',
    '91af40',  # shrub, grass
    '111149',  # wetlands
    'cdb33b',  # croplands
    'cc0013',  # urban
    '33280d',  # crop mosaic
    'd7cdcc',  # snow and ice
    'f7e084',  # barren
    'aec3d4',  # water
]

# Define a map centered on the United States.
map_palette = geemap.Map(center=[40.413, -99.229], zoom=5)

# Add the image layer to the map and display it. Specify the min and max labels
# and the color palette matching the labels.
map_palette.add_layer(
    cover, {'min': 1, 'max': 17, 'palette': igbp_palette}, 'IGBP classes'
)
display(map_palette)
landcover_palettized
תכסית קרקע של MODIS 2012 באמצעות סיווג IGBP.

Styled Layer Descriptors

אפשר להשתמש ב-Styled Layer Descriptor‏ (SLD) כדי לעבד תמונות לתצוגה. צריך לספק ל-image.sldStyle() תיאור XML של הסמלים והצבעים של התמונה, ובמיוחד של הרכיב RasterSymbolizer. כאן אפשר לקרוא מידע נוסף על רכיבים מסוג RasterSymbolizer. לדוגמה, כדי לעבד את מפת תכסית הקרקע שמתוארת בקטע "עיבוד מפות קטגוריות" באמצעות SLD, משתמשים בקוד הבא:

Code Editor (JavaScript)

var cover = ee.Image('MODIS/061/MCD12Q1/2012_01_01').select('LC_Type1');

// Define an SLD style of discrete intervals to apply to the image.
var sld_intervals =
'<RasterSymbolizer>' +
  '<ColorMap type="intervals" extended="false">' +
    '<ColorMapEntry color="#152106" quantity="1" label="Evergreen Needleleaf Forest"/>' +
    '<ColorMapEntry color="#225129" quantity="2" label="Evergreen Broadleaf Forest"/>' +
    '<ColorMapEntry color="#369b47" quantity="3" label="Deciduous Needleleaf Forest"/>' +
    '<ColorMapEntry color="#30eb5b" quantity="4" label="Deciduous Broadleaf Forest"/>' +
    '<ColorMapEntry color="#387242" quantity="5" label="Mixed Deciduous Forest"/>' +
    '<ColorMapEntry color="#6a2325" quantity="6" label="Closed Shrubland"/>' +
    '<ColorMapEntry color="#c3aa69" quantity="7" label="Open Shrubland"/>' +
    '<ColorMapEntry color="#b76031" quantity="8" label="Woody Savanna"/>' +
    '<ColorMapEntry color="#d9903d" quantity="9" label="Savanna"/>' +
    '<ColorMapEntry color="#91af40" quantity="10" label="Grassland"/>' +
    '<ColorMapEntry color="#111149" quantity="11" label="Permanent Wetland"/>' +
    '<ColorMapEntry color="#cdb33b" quantity="12" label="Cropland"/>' +
    '<ColorMapEntry color="#cc0013" quantity="13" label="Urban"/>' +
    '<ColorMapEntry color="#33280d" quantity="14" label="Crop, Natural Veg. Mosaic"/>' +
    '<ColorMapEntry color="#d7cdcc" quantity="15" label="Permanent Snow, Ice"/>' +
    '<ColorMapEntry color="#f7e084" quantity="16" label="Barren, Desert"/>' +
    '<ColorMapEntry color="#aec3d4" quantity="17" label="Water"/>' +
  '</ColorMap>' +
'</RasterSymbolizer>';
Map.addLayer(cover.sldStyle(sld_intervals), {}, 'IGBP classification styled');

הגדרה של Python

בדף סביבת Python מפורט מידע על API בשפת Python ועל השימוש ב-geemap לפיתוח אינטראקטיבי.

import ee
import geemap.core as geemap

Colab (Python)

cover = ee.Image('MODIS/061/MCD12Q1/2012_01_01').select('LC_Type1')

# Define an SLD style of discrete intervals to apply to the image.
sld_intervals = """
<RasterSymbolizer>
  <ColorMap  type="intervals" extended="false" >
    <ColorMapEntry color="#152106" quantity="1" label="Evergreen Needleleaf Forest"/>
    <ColorMapEntry color="#225129" quantity="2" label="Evergreen Broadleaf Forest"/>
    <ColorMapEntry color="#369b47" quantity="3" label="Deciduous Needleleaf Forest"/>
    <ColorMapEntry color="#30eb5b" quantity="4" label="Deciduous Broadleaf Forest"/>
    <ColorMapEntry color="#387242" quantity="5" label="Mixed Deciduous Forest"/>
    <ColorMapEntry color="#6a2325" quantity="6" label="Closed Shrubland"/>
    <ColorMapEntry color="#c3aa69" quantity="7" label="Open Shrubland"/>
    <ColorMapEntry color="#b76031" quantity="8" label="Woody Savanna"/>
    <ColorMapEntry color="#d9903d" quantity="9" label="Savanna"/>
    <ColorMapEntry color="#91af40" quantity="10" label="Grassland"/>
    <ColorMapEntry color="#111149" quantity="11" label="Permanent Wetland"/>
    <ColorMapEntry color="#cdb33b" quantity="12" label="Cropland"/>
    <ColorMapEntry color="#cc0013" quantity="13" label="Urban"/>
    <ColorMapEntry color="#33280d" quantity="14" label="Crop, Natural Veg. Mosaic"/>
    <ColorMapEntry color="#d7cdcc" quantity="15" label="Permanent Snow, Ice"/>
    <ColorMapEntry color="#f7e084" quantity="16" label="Barren, Desert"/>
    <ColorMapEntry color="#aec3d4" quantity="17" label="Water"/>
  </ColorMap>
</RasterSymbolizer>"""

# Apply the SLD style to the image.
cover_sld = cover.sldStyle(sld_intervals)

# Define a map centered on the United States.
map_sld_categorical = geemap.Map(center=[40.413, -99.229], zoom=5)

# Add the image layer to the map and display it.
map_sld_categorical.add_layer(cover_sld, None, 'IGBP classes styled')
display(map_sld_categorical)

כדי ליצור תמונה של תצוגה חזותית עם סולם צבעים, מגדירים את הסוג של ColorMap ל-ramp. בדוגמה הבאה מוצגת השוואה בין הסוגים interval ו-ramp לעיבוד של DEM:

Code Editor (JavaScript)

// Load SRTM Digital Elevation Model data.
var image = ee.Image('CGIAR/SRTM90_V4');

// Define an SLD style of discrete intervals to apply to the image. Use the
// opacity keyword to set pixels less than 0 as completely transparent. Pixels
// with values greater than or equal to the final entry quantity are set to
// fully transparent by default.
var sld_intervals =
  '<RasterSymbolizer>' +
    '<ColorMap type="intervals" extended="false" >' +
      '<ColorMapEntry color="#0000ff" quantity="0" label="0 ﹤ x" opacity="0" />' +
      '<ColorMapEntry color="#00ff00" quantity="100" label="0 ≤ x ﹤ 100" />' +
      '<ColorMapEntry color="#007f30" quantity="200" label="100 ≤ x ﹤ 200" />' +
      '<ColorMapEntry color="#30b855" quantity="300" label="200 ≤ x ﹤ 300" />' +
      '<ColorMapEntry color="#ff0000" quantity="400" label="300 ≤ x ﹤ 400" />' +
      '<ColorMapEntry color="#ffff00" quantity="900" label="400 ≤ x ﹤ 900" />' +
    '</ColorMap>' +
  '</RasterSymbolizer>';

// Define an sld style color ramp to apply to the image.
var sld_ramp =
  '<RasterSymbolizer>' +
    '<ColorMap type="ramp" extended="false" >' +
      '<ColorMapEntry color="#0000ff" quantity="0" label="0"/>' +
      '<ColorMapEntry color="#00ff00" quantity="100" label="100" />' +
      '<ColorMapEntry color="#007f30" quantity="200" label="200" />' +
      '<ColorMapEntry color="#30b855" quantity="300" label="300" />' +
      '<ColorMapEntry color="#ff0000" quantity="400" label="400" />' +
      '<ColorMapEntry color="#ffff00" quantity="500" label="500" />' +
    '</ColorMap>' +
  '</RasterSymbolizer>';

// Add the image to the map using both the color ramp and interval schemes.
Map.setCenter(-76.8054, 42.0289, 8);
Map.addLayer(image.sldStyle(sld_intervals), {}, 'SLD intervals');
Map.addLayer(image.sldStyle(sld_ramp), {}, 'SLD ramp');

הגדרה של Python

בדף סביבת Python מפורט מידע על API בשפת Python ועל השימוש ב-geemap לפיתוח אינטראקטיבי.

import ee
import geemap.core as geemap

Colab (Python)

# Load SRTM Digital Elevation Model data.
image = ee.Image('CGIAR/SRTM90_V4')

# Define an SLD style of discrete intervals to apply to the image.
sld_intervals = """
    <RasterSymbolizer>
      <ColorMap type="intervals" extended="false" >
        <ColorMapEntry color="#0000ff" quantity="0" label="0"/>
        <ColorMapEntry color="#00ff00" quantity="100" label="1-100" />
        <ColorMapEntry color="#007f30" quantity="200" label="110-200" />
        <ColorMapEntry color="#30b855" quantity="300" label="210-300" />
        <ColorMapEntry color="#ff0000" quantity="400" label="310-400" />
        <ColorMapEntry color="#ffff00" quantity="1000" label="410-1000" />
      </ColorMap>
    </RasterSymbolizer>"""

# Define an sld style color ramp to apply to the image.
sld_ramp = """
    <RasterSymbolizer>
      <ColorMap type="ramp" extended="false" >
        <ColorMapEntry color="#0000ff" quantity="0" label="0"/>
        <ColorMapEntry color="#00ff00" quantity="100" label="100" />
        <ColorMapEntry color="#007f30" quantity="200" label="200" />
        <ColorMapEntry color="#30b855" quantity="300" label="300" />
        <ColorMapEntry color="#ff0000" quantity="400" label="400" />
        <ColorMapEntry color="#ffff00" quantity="500" label="500" />
      </ColorMap>
    </RasterSymbolizer>"""

# Define a map centered on the United States.
map_sld_interval = geemap.Map(center=[40.413, -99.229], zoom=5)

# Add the image layers to the map and display it.
map_sld_interval.add_layer(
    image.sldStyle(sld_intervals), None, 'SLD intervals'
)
map_sld_interval.add_layer(image.sldStyle(sld_ramp), None, 'SLD ramp')
display(map_sld_interval)

אפשר להשתמש ב-SLD גם כדי למתוח ערכי פיקסלים ולשפר את התצוגה החזותית של נתונים רציפים. לדוגמה, הקוד הבא משווה בין התוצאות של מתיחה ליניארית שרירותית לבין "נורמליזציה" של מינימום-מקסימום והשוואה של "היסטוגרמה":

Code Editor (JavaScript)

// Load a Landsat 8 raw image.
var image = ee.Image('LANDSAT/LC08/C02/T1/LC08_044034_20140318');

// Define a RasterSymbolizer element with '_enhance_' for a placeholder.
var template_sld =
  '<RasterSymbolizer>' +
    '<ContrastEnhancement><_enhance_/></ContrastEnhancement>' +
    '<ChannelSelection>' +
      '<RedChannel>' +
        '<SourceChannelName>B5</SourceChannelName>' +
      '</RedChannel>' +
      '<GreenChannel>' +
        '<SourceChannelName>B4</SourceChannelName>' +
      '</GreenChannel>' +
      '<BlueChannel>' +
        '<SourceChannelName>B3</SourceChannelName>' +
      '</BlueChannel>' +
    '</ChannelSelection>' +
  '</RasterSymbolizer>';

// Get SLDs with different enhancements.
var equalize_sld = template_sld.replace('_enhance_', 'Histogram');
var normalize_sld = template_sld.replace('_enhance_', 'Normalize');

// Display the results.
Map.centerObject(image, 10);
Map.addLayer(image, {bands: ['B5', 'B4', 'B3'], min: 0, max: 15000}, 'Linear');
Map.addLayer(image.sldStyle(equalize_sld), {}, 'Equalized');
Map.addLayer(image.sldStyle(normalize_sld), {}, 'Normalized');

הגדרה של Python

בדף סביבת Python מפורט מידע על API בשפת Python ועל השימוש ב-geemap לפיתוח אינטראקטיבי.

import ee
import geemap.core as geemap

Colab (Python)

# Load a Landsat 8 raw image.
image = ee.Image('LANDSAT/LC08/C02/T1/LC08_044034_20140318')

# Define a RasterSymbolizer element with '_enhance_' for a placeholder.
template_sld = """
<RasterSymbolizer>
  <ContrastEnhancement><_enhance_/></ContrastEnhancement>
  <ChannelSelection>
    <RedChannel>
      <SourceChannelName>B5</SourceChannelName>
    </RedChannel>
    <GreenChannel>
      <SourceChannelName>B4</SourceChannelName>
    </GreenChannel>
    <BlueChannel>
      <SourceChannelName>B3</SourceChannelName>
    </BlueChannel>
  </ChannelSelection>
</RasterSymbolizer>"""

# Get SLDs with different enhancements.
equalize_sld = template_sld.replace('_enhance_', 'Histogram')
normalize_sld = template_sld.replace('_enhance_', 'Normalize')

# Define a map centered on San Francisco Bay.
map_sld_continuous = geemap.Map(center=[37.5010, -122.1899], zoom=10)

# Add the image layers to the map and display it.
map_sld_continuous.add_layer(
    image, {'bands': ['B5', 'B4', 'B3'], 'min': 0, 'max': 15000}, 'Linear'
)
map_sld_continuous.add_layer(image.sldStyle(equalize_sld), None, 'Equalized')
map_sld_continuous.add_layer(
    image.sldStyle(normalize_sld), None, 'Normalized'
)
display(map_sld_continuous)

נקודות שחשוב לשים לב אליהן כשמשתמשים ב-SLD ב-Earth Engine:

  • יש תמיכה ב-OGC SLD 1.0 וב-OGC SE 1.1.
  • מסמך ה-XML שמועבר יכול להיות שלם, או רק הרכיב RasterSymbolizer ומה שמתחתיו.
  • אפשר לבחור ערוצים לפי השמות שלהם ב-Earth Engine או לפי האינדקס ('1', '2' וכו').
  • מנגנוני מתיחת הניגודיות Histogram ו-Normalize לא נתמכים בתמונות עם נקודה צפה.
  • האטימות נלקחת בחשבון רק כשהיא 0.0 (שקוף). ערכי אטימות שאינם אפס נחשבים לאטומים לחלוטין.
  • המערכת מתעלמת כרגע מההגדרה של OverlapBehavior.
  • מנגנון ShadedRelief לא נתמך כרגע.
  • מנגנון ImageOutline לא נתמך כרגע.
  • המערכת מתעלמת מהרכיב Geometry.
  • אם מבקשים השוואה או נרמול של היסטוגרמה, לתמונת הפלט יהיו מטא-נתונים של histogram_bandname.

תמונות ממוזערות

משתמשים ב-ee.Image.getThumbURL() method כדי ליצור תמונה ממוזערת בפורמט PNG או JPEG לאובייקט ee.Image. הדפסת התוצאה של ביטוי שמסתיים בקריאה ל-getThumbURL() גורמת להדפסה של כתובת URL. כשנכנסים לכתובת ה-URL, השרתים של Earth Engine מתחילים ליצור את התמונה הממוזערת המבוקשת בזמן אמת. התמונה מוצגת בדפדפן כשהעיבוד מסתיים. כדי להוריד את התמונה, צריך לבחור את האפשרויות המתאימות בתפריט ההקשר שמופיע כשלוחצים לחיצה ימנית על התמונה.

thumbnail_in_browser
מודל גובה דיגיטלי של SRTM שמוצג כתמונה ממוזערת בפורמט PNG בדפדפן.

השיטה getThumbURL() כוללת פרמטרים, שמתוארים בטבלת הפרמטרים של התצוגה החזותית שלמעלה. בנוסף, אפשר להשתמש בארגומנטים האופציונליים dimensions,‏ region ו-crs כדי לשלוט בהיקף המרחבי, בגודל ובהיטל התצוגה של התמונה הממוזערת.

פרמטרים נוספים ל-ee.Image.getThumbURL() עם הערה לגבי הפורמט
פרמטר תיאור סוג
מאפיינים מידות התמונה הממוזערת בפיקסלים. אם מציינים מספר שלם אחד, הוא מגדיר את הגודל של המימד הגדול יותר של התמונה, והמימד הקטן יותר משתנה באופן פרופורציונלי. כברירת מחדל, המערכת משתמשת ב-512 פיקסלים למימד הגדול יותר של יחס הגובה-רוחב של התמונה. מספר שלם יחיד או מחרוזת בפורמט: 'WIDTHxHEIGHT'
region האזור הגיאוגרפי של התמונה שרוצים לעבד. כברירת מחדל, התמונה כולה, או הגבולות של הגיאומטריה שסופקה. ‫GeoJSON או רשימה דו-ממדית של לפחות שלוש קואורדינטות של נקודות שמגדירות טבעת ליניארית
crs ההיטל של היעד, למשל "EPSG:3857". ברירת המחדל היא WGS84 ('EPSG:4326'). מחרוזת
פורמט הגדרת הפורמט של התמונה הממוזערת כ-PNG או כ-JPEG. פורמט ברירת המחדל PNG מוטמע כ-RGBA, שבו ערוץ האלפא מייצג פיקסלים תקינים ולא תקינים, שמוגדרים על ידי mask() של התמונה. פיקסלים לא חוקיים הם שקופים. פורמט JPEG האופציונלי מיושם כ-RGB, שבו פיקסלים לא חוקיים של תמונה ממולאים באפסים בערוצי RGB. מחרוזת; png או jpg

תמונה עם פס אחד תוגדר כברירת מחדל לגווני אפור, אלא אם צוין ארגומנט palette. תמונה עם כמה פסים תוגדר כברירת מחדל להמחשה חזותית של RGB של שלושת הפסים הראשונים, אלא אם סופק ארגומנט bands. אם מספקים רק שתי רצועות, הרצועה הראשונה תמופה לאדום, השנייה לכחול, והערוץ הירוק יתמלא באפסים.

בהמשך מופיעות כמה דוגמאות שממחישות שילובים שונים של ארגומנטים של הפרמטר getThumbURL(). כדי לראות את התמונות הממוזערות, לוחצים על כתובות ה-URL שמופיעות כשמריצים את הסקריפט.

Code Editor (JavaScript)

// Fetch a digital elevation model.
var image = ee.Image('CGIAR/SRTM90_V4');

// Request a default thumbnail of the DEM with defined linear stretch.
// Set masked pixels (ocean) to 1000 so they map as gray.
var thumbnail1 = image.unmask(1000).getThumbURL({
  'min': 0,
  'max': 3000,
  'dimensions': 500,
});
print('Default extent:', thumbnail1);

// Specify region by rectangle, define palette, set larger aspect dimension size.
var thumbnail2 = image.getThumbURL({
  'min': 0,
  'max': 3000,
  'palette': ['00A600','63C600','E6E600','E9BD3A','ECB176','EFC2B3','F2F2F2'],
  'dimensions': 500,
  'region': ee.Geometry.Rectangle([-84.6, -55.9, -32.9, 15.7]),
});
print('Rectangle region and palette:', thumbnail2);

// Specify region by a linear ring and set display CRS as Web Mercator.
var thumbnail3 = image.getThumbURL({
  'min': 0,
  'max': 3000,
  'palette': ['00A600','63C600','E6E600','E9BD3A','ECB176','EFC2B3','F2F2F2'],
  'region': ee.Geometry.LinearRing([[-84.6, 15.7], [-84.6, -55.9], [-32.9, -55.9]]),
  'dimensions': 500,
  'crs': 'EPSG:3857'
});
print('Linear ring region and specified crs', thumbnail3);

הגדרה של Python

בדף סביבת Python מפורט מידע על API בשפת Python ועל השימוש ב-geemap לפיתוח אינטראקטיבי.

import ee
import geemap.core as geemap

Colab (Python)

# Fetch a digital elevation model.
image = ee.Image('CGIAR/SRTM90_V4')

# Request a default thumbnail of the DEM with defined linear stretch.
# Set masked pixels (ocean) to 1000 so they map as gray.
thumbnail_1 = image.unmask(1000).getThumbURL({
    'min': 0,
    'max': 3000,
    'dimensions': 500,
})
print('Default extent:', thumbnail_1)

# Specify region by rectangle, define palette, set larger aspect dimension size.
thumbnail_2 = image.getThumbURL({
    'min': 0,
    'max': 3000,
    'palette': [
        '00A600',
        '63C600',
        'E6E600',
        'E9BD3A',
        'ECB176',
        'EFC2B3',
        'F2F2F2',
    ],
    'dimensions': 500,
    'region': ee.Geometry.Rectangle([-84.6, -55.9, -32.9, 15.7]),
})
print('Rectangle region and palette:', thumbnail_2)

# Specify region by a linear ring and set display CRS as Web Mercator.
thumbnail_3 = image.getThumbURL({
    'min': 0,
    'max': 3000,
    'palette': [
        '00A600',
        '63C600',
        'E6E600',
        'E9BD3A',
        'ECB176',
        'EFC2B3',
        'F2F2F2',
    ],
    'region': ee.Geometry.LinearRing(
        [[-84.6, 15.7], [-84.6, -55.9], [-32.9, -55.9]]
    ),
    'dimensions': 500,
    'crs': 'EPSG:3857',
})
print('Linear ring region and specified crs:', thumbnail_3)