Seperti gambar, geometri, dan fitur, koleksi fitur dapat ditambahkan ke peta secara langsung dengan Map.addLayer()
. Visualisasi default akan menampilkan vektor dengan garis hitam solid dan isian hitam semi-buram. Untuk merender vektor dalam warna,
tentukan parameter color
. Gambar berikut menampilkan ekorigion 'RESOLVE'
(Dinerstein
et al. 2017) sebagai visualisasi default dan berwarna merah:
Editor Kode (JavaScript)
// Load a FeatureCollection from a table dataset: 'RESOLVE' ecoregions. var ecoregions = ee.FeatureCollection('RESOLVE/ECOREGIONS/2017'); // Display as default and with a custom color. Map.addLayer(ecoregions, {}, 'default display'); Map.addLayer(ecoregions, {color: 'FF0000'}, 'colored');
import ee import geemap.core as geemap
Colab (Python)
# Load a FeatureCollection from a table dataset: 'RESOLVE' ecoregions. ecoregions = ee.FeatureCollection('RESOLVE/ECOREGIONS/2017') # Display as default and with a custom color. m = geemap.Map() m.set_center(-76.2486, 44.8988, 8) m.add_layer(ecoregions, {}, 'default display') m.add_layer(ecoregions, {'color': 'FF0000'}, 'colored') m
Untuk opsi tampilan tambahan, gunakan featureCollection.draw()
. Secara khusus,
parameter pointRadius
dan strokeWidth
mengontrol ukuran titik
dan garis, masing-masing, dalam FeatureCollection
yang dirender:
Editor Kode (JavaScript)
Map.addLayer(ecoregions.draw({color: '006600', strokeWidth: 5}), {}, 'drawn');
import ee import geemap.core as geemap
Colab (Python)
m.add_layer(ecoregions.draw(color='006600', strokeWidth=5), {}, 'drawn')
Output draw()
adalah gambar dengan band merah, hijau, dan biru yang ditetapkan sesuai
dengan parameter color
yang ditentukan.
Untuk kontrol lebih besar atas cara FeatureCollection
ditampilkan, gunakan
image.paint()
dengan FeatureCollection
sebagai argumen. Tidak seperti
draw()
, yang menghasilkan gambar tampilan tiga band 8-bit,
image.paint()
menghasilkan gambar dengan nilai numerik yang ditentukan yang 'digambar'
ke dalamnya. Atau, Anda dapat memberikan nama properti di
FeatureCollection
yang berisi angka yang akan dicat. Parameter width
berperilaku dengan cara yang sama: dapat berupa konstanta atau nama properti dengan
angka untuk lebar garis. Contoh:
Editor Kode (JavaScript)
// Create an empty image into which to paint the features, cast to byte. var empty = ee.Image().byte(); // Paint all the polygon edges with the same number and width, display. var outline = empty.paint({ featureCollection: ecoregions, color: 1, width: 3 }); Map.addLayer(outline, {palette: 'FF0000'}, 'edges');
import ee import geemap.core as geemap
Colab (Python)
# Create an empty image into which to paint the features, cast to byte. empty = ee.Image().byte() # Paint all the polygon edges with the same number and width, display. outline = empty.paint(featureCollection=ecoregions, color=1, width=3) m.add_layer(outline, {'palette': 'FF0000'}, 'edges')
Perhatikan bahwa gambar kosong tempat Anda melukis fitur harus ditampilkan sebelum proses pengecatan. Hal ini karena gambar konstan berperilaku sebagai konstanta: gambar ini dikencangkan ke nilai inisialisasi. Untuk mewarnai tepi fitur dengan nilai yang ditetapkan dari properti fitur, tetapkan parameter warna ke nama properti dengan nilai numerik:
Editor Kode (JavaScript)
// Paint the edges with different colors, display. var outlines = empty.paint({ featureCollection: ecoregions, color: 'BIOME_NUM', width: 4 }); var palette = ['FF0000', '00FF00', '0000FF']; Map.addLayer(outlines, {palette: palette, max: 14}, 'different color edges');
import ee import geemap.core as geemap
Colab (Python)
# Paint the edges with different colors, display. outlines = empty.paint(featureCollection=ecoregions, color='BIOME_NUM', width=4) palette = ['FF0000', '00FF00', '0000FF'] m.add_layer(outlines, {'palette': palette, 'max': 14}, 'different color edges')
Warna dan lebar yang digunakan untuk menggambar batas dapat ditetapkan dengan properti. Contoh:
Editor Kode (JavaScript)
// Paint the edges with different colors and widths. var outlines = empty.paint({ featureCollection: ecoregions, color: 'BIOME_NUM', width: 'NNH' }); Map.addLayer(outlines, {palette: palette, max: 14}, 'different color, width edges');
import ee import geemap.core as geemap
Colab (Python)
# Paint the edges with different colors and widths. outlines = empty.paint( featureCollection=ecoregions, color='BIOME_NUM', width='NNH' ) m.add_layer( outlines, {'palette': palette, 'max': 14}, 'different color, width edges' )
Jika parameter width
tidak diberikan, bagian dalam fitur akan
digambar:
Editor Kode (JavaScript)
// Paint the interior of the polygons with different colors. var fills = empty.paint({ featureCollection: ecoregions, color: 'BIOME_NUM', }); Map.addLayer(fills, {palette: palette, max: 14}, 'colored fills');
import ee import geemap.core as geemap
Colab (Python)
# Paint the interior of the polygons with different colors. fills = empty.paint(featureCollection=ecoregions, color='BIOME_NUM') m.add_layer(fills, {'palette': palette, 'max': 14}, 'colored fills')
Untuk merender interior dan tepi fitur, cat gambar kosong dua kali:
Editor Kode (JavaScript)
// Paint both the fill and the edges. var filledOutlines = empty.paint(ecoregions, 'BIOME_NUM').paint(ecoregions, 0, 2); Map.addLayer(filledOutlines, {palette: ['000000'].concat(palette), max: 14}, 'edges and fills');
import ee import geemap.core as geemap
Colab (Python)
# Paint both the fill and the edges. filled_outlines = empty.paint(ecoregions, 'BIOME_NUM').paint(ecoregions, 0, 2) m.add_layer( filled_outlines, {'palette': ['000000'] + palette, 'max': 14}, 'edges and fills', )