Visualisasi Gambar

Ada sejumlah metode ee.Image yang menghasilkan representasi visual RGB data gambar, misalnya: visualize(), getThumbURL(), getMap(), getMapId() (digunakan dalam tampilan peta Folium Colab) dan, Map.addLayer() (digunakan dalam tampilan peta Code Editor, tidak tersedia untuk Python). Secara default, metode ini menetapkan tiga band pertama ke merah, hijau, dan biru. Peregangan default didasarkan pada jenis data dalam band (misalnya, float diregangkan dalam [0, 1], data 16-bit diregangkan ke rentang penuh kemungkinan nilai), yang mungkin cocok atau tidak. Untuk mendapatkan efek visualisasi yang diinginkan, Anda dapat memberikan parameter visualisasi:

Parameter visualisasi gambar
Parameter Deskripsi Jenis
band Daftar tiga nama band yang dipisahkan koma yang akan dipetakan ke RGB list
mnt Nilai yang akan dipetakan ke 0 angka atau daftar tiga angka, satu untuk setiap band
max Nilai yang akan dipetakan ke 255 angka atau daftar tiga angka, satu untuk setiap band
gain Nilai yang akan digunakan untuk mengalikan setiap nilai piksel angka atau daftar tiga angka, satu untuk setiap band
bias Nilai yang akan ditambahkan ke setiap DN angka atau daftar tiga angka, satu untuk setiap band
gamma Faktor koreksi gamma angka atau daftar tiga angka, satu untuk setiap band
palette Daftar string warna gaya CSS (khusus gambar band tunggal) daftar string hex yang dipisahkan koma
opasitas Opasitas lapisan (0,0 sepenuhnya transparan dan 1,0 sepenuhnya buram) angka
format "jpg" atau "png" string

Komposit RGB

Berikut ini ilustrasi penggunaan parameter untuk menata gaya gambar Landsat 8 sebagai komposit warna palsu:

Editor Kode (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');

Penyiapan Python

Lihat halaman Lingkungan Python untuk mengetahui informasi tentang Python API dan penggunaan geemap untuk pengembangan interaktif.

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)

Dalam contoh ini, band 'B5' ditetapkan ke merah, 'B4' ditetapkan ke hijau, dan 'B3' ditetapkan ke biru.

false_color_sf
Komposit warna palsu Landsat 8 dari area Teluk San Francisco, California, AS.

Palet warna

Untuk menampilkan satu band gambar dalam warna, tetapkan parameter palette dengan gradien warna yang diwakili oleh daftar string warna bergaya CSS. (Lihat referensi ini untuk informasi selengkapnya). Contoh berikut mengilustrasikan cara menggunakan warna dari cyan ('00FFFF') ke biru ('0000FF') untuk merender gambar Normalized Difference Water Index (NDWI):

Editor Kode (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);

Penyiapan Python

Lihat halaman Lingkungan Python untuk mengetahui informasi tentang Python API dan penggunaan geemap untuk pengembangan interaktif.

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)

Dalam contoh ini, perhatikan bahwa parameter min dan max menunjukkan rentang nilai piksel tempat palet harus diterapkan. Nilai perantara diregangkan secara linear.

Perhatikan juga bahwa parameter show ditetapkan ke false dalam contoh Code Editor. Hal ini menyebabkan visibilitas lapisan dinonaktifkan saat ditambahkan ke peta. Lapisan ini dapat diaktifkan kembali menggunakan Pengelola Lapisan di pojok kanan atas peta Editor Kode.

ndwi_sf
Landsat 8 NDWI, San Francisco Bay Area, Amerika Serikat. Cyan adalah nilai rendah, biru adalah nilai tinggi.

Menyimpan palet warna default

Untuk menyimpan palet warna pada gambar klasifikasi sehingga tidak perlu mengingat untuk menerapkannya, Anda dapat menetapkan dua properti gambar string yang diberi nama khusus untuk setiap band klasifikasi.

Misalnya, jika gambar Anda memiliki band bernama 'landcover' dengan tiga nilai 0, 1, dan 2 yang sesuai dengan class 'air', 'hutan', dan 'lainnya', Anda dapat menetapkan properti berikut agar visualisasi default menampilkan warna yang ditentukan untuk setiap class (nilai yang digunakan dalam analisis tidak akan terpengaruh):

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

Lihat halaman mengelola aset untuk mempelajari cara menetapkan metadata aset.

Penyamaran

Anda dapat menggunakan image.updateMask() untuk menetapkan opasitas setiap piksel berdasarkan lokasi piksel dalam gambar mask yang bukan nol. Piksel yang sama dengan nol dalam mask dikecualikan dari komputasi dan opasitas ditetapkan ke 0 untuk ditampilkan. Contoh berikut menggunakan nilai minimum NDWI (lihat bagian Operasi Relasional untuk informasi tentang nilai minimum) guna memperbarui mask pada lapisan NDWI yang dibuat sebelumnya:

Editor Kode (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');

Penyiapan Python

Lihat halaman Lingkungan Python untuk mengetahui informasi tentang Python API dan penggunaan geemap untuk pengembangan interaktif.

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)

Gambar visualisasi

Gunakan metode image.visualize() untuk mengonversi gambar menjadi gambar RGB 8-bit untuk ditampilkan atau diekspor. Misalnya, untuk mengonversi komposit warna palsu dan NDWI menjadi gambar tampilan 3 band, gunakan:

Editor Kode (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']
});

Penyiapan Python

Lihat halaman Lingkungan Python untuk mengetahui informasi tentang Python API dan penggunaan geemap untuk pengembangan interaktif.

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'])

Pembuatan mosaik

Anda dapat menggunakan masking dan imageCollection.mosaic() (lihat bagian Mosaik untuk informasi tentang mosaik) untuk mendapatkan berbagai efek kartografis. Metode mosaic() merender lapisan dalam gambar output sesuai dengan urutannya dalam koleksi input. Contoh berikut menggunakan mosaic() untuk menggabungkan NDWI yang disamarkan dan komposit warna palsu serta mendapatkan visualisasi baru:

Editor Kode (JavaScript)

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

Penyiapan Python

Lihat halaman Lingkungan Python untuk mengetahui informasi tentang Python API dan penggunaan geemap untuk pengembangan interaktif.

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)

Dalam contoh ini, amati bahwa daftar dua gambar visualisasi disediakan ke konstruktor ImageCollection. Urutan daftar menentukan urutan render gambar di peta.

mosaic_sf
Mosaik komposit warna palsu Landsat 8 dan NDWI. Wilayah Teluk San Francisco, Amerika Serikat.

Pemangkasan

Metode image.clip() berguna untuk mencapai efek kartografis. Contoh berikut memotong mosaik yang dibuat sebelumnya ke zona penyangga arbitrer di sekitar kota San Francisco:

Editor Kode (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');

Penyiapan Python

Lihat halaman Lingkungan Python untuk mengetahui informasi tentang Python API dan penggunaan geemap untuk pengembangan interaktif.

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)

Pada contoh sebelumnya, perhatikan bahwa koordinat diberikan ke konstruktor Geometry dan panjang buffering ditentukan sebagai 20.000 meter. Pelajari geometri lebih lanjut di halaman Geometri.

clipped_sf
Mosaik yang ditampilkan di atas, dipangkas ke buffer di sekitar San Francisco, California, AS.

Merender peta kategori

Palet juga berguna untuk merender peta nilai diskret, misalnya peta tutupan lahan. Jika ada beberapa class, gunakan palet untuk menyediakan warna yang berbeda untuk setiap class. (Metode image.remap() mungkin berguna dalam konteks ini, untuk mengonversi label arbitrer menjadi bilangan bulat berurutan). Contoh berikut menggunakan palet untuk merender kategori tutupan lahan:

Editor Kode (JavaScript)

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

// Define a palette for the 18 distinct land cover classes.
var igbpPalette = [
  'aec3d4', // water
  '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
  '6f6f6f'  // tundra
];

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

Penyiapan Python

Lihat halaman Lingkungan Python untuk mengetahui informasi tentang Python API dan penggunaan geemap untuk pengembangan interaktif.

import ee
import geemap.core as geemap

Colab (Python)

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

# Define a palette for the 18 distinct land cover classes.
igbp_palette = [
    'aec3d4',  # water
    '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
    '6f6f6f',  # tundra
]

# 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': 0, 'max': 17, 'palette': igbp_palette}, 'IGBP classes'
)
display(map_palette)
landcover_palettized
Penutup lahan MODIS 2012 menggunakan klasifikasi IGBP.

Deskripsi Lapisan Bergaya

Anda dapat menggunakan Deskripsi Lapisan Bergaya (SLD) untuk merender gambar untuk ditampilkan. Berikan image.sldStyle() dengan deskripsi XML tentang simbolisasi dan pewarnaan gambar, khususnya elemen RasterSymbolizer. Pelajari elemen RasterSymbolizer lebih lanjut di sini. Misalnya, untuk merender peta tutupan lahan yang dijelaskan di bagian Merender peta kategoris dengan SLD, gunakan:

Editor Kode (JavaScript)

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

// Define an SLD style of discrete intervals to apply to the image.
var sld_intervals =
'<RasterSymbolizer>' +
  '<ColorMap type="intervals" extended="false">' +
    '<ColorMapEntry color="#aec3d4" quantity="0" label="Water"/>' +
    '<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="#6f6f6f" quantity="17" label="Tundra"/>' +
  '</ColorMap>' +
'</RasterSymbolizer>';
Map.addLayer(cover.sldStyle(sld_intervals), {}, 'IGBP classification styled');

Penyiapan Python

Lihat halaman Lingkungan Python untuk mengetahui informasi tentang Python API dan penggunaan geemap untuk pengembangan interaktif.

import ee
import geemap.core as geemap

Colab (Python)

cover = ee.Image('MODIS/051/MCD12Q1/2012_01_01').select('Land_Cover_Type_1')

# Define an SLD style of discrete intervals to apply to the image.
sld_intervals = """
<RasterSymbolizer>
  <ColorMap  type="intervals" extended="false" >
    <ColorMapEntry color="#aec3d4" quantity="0" label="Water"/>
    <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="#6f6f6f" quantity="17" label="Tundra"/>
  </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)

Untuk membuat gambar visualisasi dengan gradien warna, tetapkan jenis ColorMap ke 'ramp'. Contoh berikut membandingkan jenis 'interval' dan 'ramp' untuk merender DEM:

Editor Kode (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');

Penyiapan Python

Lihat halaman Lingkungan Python untuk mengetahui informasi tentang Python API dan penggunaan geemap untuk pengembangan interaktif.

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 juga berguna untuk meregangkan nilai piksel guna meningkatkan visualisasi data berkelanjutan. Misalnya, kode berikut membandingkan hasil peregangan linear arbitrer dengan 'Normalisasi' min-maks dan equalisasi 'Histogram':

Editor Kode (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');

Penyiapan Python

Lihat halaman Lingkungan Python untuk mengetahui informasi tentang Python API dan penggunaan geemap untuk pengembangan interaktif.

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)

Poin penting terkait penggunaan SLD di Earth Engine:

  • OGC SLD 1.0 dan OGC SE 1.1 didukung.
  • Dokumen XML yang diteruskan dapat lengkap, atau hanya elemen RasterSymbolizer dan seterusnya.
  • Band dapat dipilih berdasarkan nama atau indeks Earth Engine ('1', '2', ...).
  • Mekanisme peregangan kontras Histogram dan Normalize tidak didukung untuk gambar titik mengambang.
  • Opasitas hanya dipertimbangkan jika 0,0 (transparan). Nilai opasitas selain nol diperlakukan sebagai sepenuhnya buram.
  • Definisi OverlapBehavior saat ini diabaikan.
  • Mekanisme ShadedRelief saat ini tidak didukung.
  • Mekanisme ImageOutline saat ini tidak didukung.
  • Elemen Geometri diabaikan.
  • Gambar output akan memiliki metadata histogram_bandname jika normalisasi atau pemerataan histogram diminta.

Gambar thumbnail

Gunakan metode ee.Image.getThumbURL() untuk membuat gambar thumbnail PNG atau JPEG untuk objek ee.Image. Mencetak hasil ekspresi yang diakhiri dengan panggilan ke getThumbURL() akan menghasilkan URL yang dicetak. Mengunjungi URL akan menetapkan server Earth Engine untuk membuat thumbnail yang diminta secara langsung. Gambar ditampilkan di browser saat pemrosesan selesai. File ini dapat didownload dengan memilih opsi yang sesuai dari menu konteks klik kanan gambar.

thumbnail_in_browser
Model elevasi digital SRTM ditampilkan sebagai thumbnail PNG di browser.

Metode getThumbURL() menyertakan parameter, yang dijelaskan dalam tabel parameter visualisasi di atas. Selain itu, metode ini memerlukan argumen dimensions, region, dan crs opsional yang mengontrol cakupan spasial, ukuran, dan proyeksi tampilan thumbnail.

Parameter tambahan untuk ee.Image.getThumbURL() dengan catatan pada format
Parameter Deskripsi Jenis
dimensi Dimensi thumbnail dalam satuan piksel. Jika satu bilangan bulat diberikan, bilangan tersebut akan menentukan ukuran dimensi aspek gambar yang lebih besar dan menskalakan dimensi yang lebih kecil secara proporsional. Setelan default-nya adalah 512 piksel untuk dimensi aspek gambar yang lebih besar. Satu bilangan bulat atau string dalam format: 'LEBARxTINGGI'
region Wilayah geospasial gambar yang akan dirender. Seluruh gambar secara default, atau batas geometri yang diberikan. GeoJSON atau daftar 2D yang berisi minimal tiga koordinat titik yang menentukan cincin linear
crs Proyeksi target, misalnya 'EPSG:3857'. Defaultnya adalah WGS84 ('EPSG:4326'). String
format Menentukan format thumbnail sebagai PNG atau JPEG. Format PNG default diterapkan sebagai RGBA, dengan saluran alfa mewakili piksel yang valid dan tidak valid, yang ditentukan oleh mask() gambar. Piksel yang tidak valid bersifat transparan. Format JPEG opsional diimplementasikan sebagai RGB, dengan piksel gambar yang tidak valid diisi nol di seluruh saluran RGB. String; 'png' atau 'jpg'

Gambar satu band akan ditetapkan secara default ke hitam putih kecuali jika argumen palette disediakan. Gambar multi-band akan ditetapkan secara default ke visualisasi RGB dari tiga band pertama, kecuali jika argumen bands disediakan. Jika hanya dua band yang disediakan, band pertama akan dipetakan ke merah, band kedua ke biru, dan saluran hijau akan diisi nol.

Berikut adalah serangkaian contoh yang menunjukkan berbagai kombinasi argumen parameter getThumbURL(). Klik URL yang dicetak saat Anda menjalankan skrip ini untuk melihat thumbnail.

Editor Kode (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);

Penyiapan Python

Lihat halaman Lingkungan Python untuk mengetahui informasi tentang Python API dan penggunaan geemap untuk pengembangan interaktif.

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)