ee.FeatureCollection.style

Menggambar koleksi vektor untuk visualisasi menggunakan bahasa gaya sederhana.

PenggunaanHasil
FeatureCollection.style(color, pointSize, pointShape, width, fillColor, styleProperty, neighborhood, lineType)Gambar
ArgumenJenisDetail
ini: collectionFeatureCollectionKoleksi yang akan digambar.
colorString, default: "black"Warna default (nilai warna CSS 3.0, misalnya, 'FF0000' atau 'red') untuk digunakan dalam menggambar fitur. Mendukung keburaman (misalnya, 'FF000088' untuk merah transparan 50%).
pointSizeBilangan bulat, default: 3Ukuran default penanda titik dalam piksel.
pointShapeString, default: "circle"Bentuk default penanda yang akan digambar di setiap lokasi titik. Salah satu dari: `circle`, `square`, `diamond`, `cross`, `plus`, `pentagram`, `hexagram`, `triangle`, `triangle_up`, `triangle_down`, `triangle_left`, `triangle_right`, `pentagon`, `hexagon`, `star5`, `star6`. Argumen ini juga mendukung singkatan penanda Matlab berikut: `o`, `s`, `d`, `x`, `+`, `p`, `h`, `^`, `v`, `<`, `>`.
widthFloat, default: 2Lebar garis default untuk garis dan garis luar untuk poligon dan bentuk titik.
fillColorString, default: nullWarna untuk mengisi poligon dan bentuk titik. Defaultnya adalah 'color' dengan opasitas 0,66.
stylePropertyString, default: nullProperti per fitur yang diharapkan berisi kamus. Nilai dalam kamus menggantikan nilai default untuk fitur tersebut.
neighborhoodBilangan bulat, default: 5Jika styleProperty digunakan dan ada fitur yang memiliki pointSize atau lebar lebih besar dari default, artefak ubin dapat terjadi. Menentukan lingkungan maksimum (pointSize + width) yang diperlukan untuk fitur apa pun.
lineTypeString, default: "solid"Gaya garis default untuk garis dan garis batas poligon dan bentuk titik. Nilai defaultnya adalah 'solid'. Salah satu dari: solid, putus-putus, garis putus-putus.

Contoh

Code Editor (JavaScript)

// FeatureCollection of power plants in Belgium.
var fc = ee.FeatureCollection('WRI/GPPD/power_plants')
            .filter('country_lg == "Belgium"');

// Paint FeatureCollection to an image using collection-wide style arguments.
var fcVis = fc.style({
  color: '1e90ff',
  width: 2,
  fillColor: 'ff475788',  // with alpha set for partial transparency
  lineType: 'dotted',
  pointSize: 10,
  pointShape: 'circle'
});

// Display the FeatureCollection visualization (ee.Image) on the map.
Map.setCenter(4.326, 50.919, 9);
Map.addLayer(fcVis, null, 'Collection-wide style');

// Paint FeatureCollection to an image using feature-specific style arguments.
// A dictionary of style properties per power plant fuel type.
var fuelStyles = ee.Dictionary({
  Wind: {color: 'blue', pointSize: 5, pointShape: 'circle'},
  Gas: {color: 'yellow', pointSize: 6, pointShape: 'square'},
  Oil: {color: 'green', pointSize: 3, pointShape: 'diamond'},
  Coal: {color: 'red', pointSize: 3, pointShape: 'cross'},
  Hydro: {color: 'brown', pointSize: 3, pointShape: 'star5'},
  Biomass: {color: 'orange', pointSize: 4, pointShape: 'triangle'},
  Nuclear: {color: 'purple', pointSize: 6, pointShape: 'hexagram'},
});

// Add feature-specific style properties to each feature based on fuel type.
fc = fc.map(function(feature) {
  return feature.set('style', fuelStyles.get(feature.get('fuel1')));
});

// Style the FeatureCollection according to each feature's "style" property.
var fcVisCustom = fc.style({
  styleProperty: 'style',
  neighborhood: 8  // maximum "pointSize" + "width" among features
});

// Display the FeatureCollection visualization (ee.Image) on the map.
Map.addLayer(fcVisCustom, null, 'Feature-specific style');

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)

# FeatureCollection of power plants in Belgium.
fc = ee.FeatureCollection('WRI/GPPD/power_plants').filter(
    'country_lg == "Belgium"'
)

# Paint FeatureCollection to an image using collection-wide style arguments.
fc_vis = fc.style(
    color='1e90ff',
    width=2,
    fillColor='ff475788',  # with alpha set for partial transparency
    lineType='dotted',
    pointSize=10,
    pointShape='circle',
)

# Display the FeatureCollection visualization (ee.Image) on the map.
m = geemap.Map()
m.set_center(4.326, 50.919, 9)
m.add_layer(fc_vis, None, 'Collection-wide style')

# Paint FeatureCollection to an image using feature-specific style arguments.
# A dictionary of style properties per power plant fuel type.
fuel_styles = ee.Dictionary({
    'Wind': {'color': 'blue', 'pointSize': 5, 'pointShape': 'circle'},
    'Gas': {'color': 'yellow', 'pointSize': 6, 'pointShape': 'square'},
    'Oil': {'color': 'green', 'pointSize': 3, 'pointShape': 'diamond'},
    'Coal': {'color': 'red', 'pointSize': 3, 'pointShape': 'cross'},
    'Hydro': {'color': 'brown', 'pointSize': 3, 'pointShape': 'star5'},
    'Biomass': {'color': 'orange', 'pointSize': 4, 'pointShape': 'triangle'},
    'Nuclear': {'color': 'purple', 'pointSize': 6, 'pointShape': 'hexagram'},
})

# Add feature-specific style properties to each feature based on fuel type.
fc = fc.map(
    lambda feature: feature.set('style', fuel_styles.get(feature.get('fuel1')))
)

# Style the FeatureCollection according to each feature's "style" property.
fc_vis_custom = fc.style(
    styleProperty='style',
    neighborhood=8,  # maximum "pointSize" + "width" among features
)

# Display the FeatureCollection visualization (ee.Image) on the map.
m.add_layer(fc_vis_custom, None, 'Feature-specific style')
m