ee.FeatureCollection.style

Dessinez une collection de vecteurs pour la visualisation à l'aide d'un langage de style simple.

UtilisationRenvoie
FeatureCollection.style(color, pointSize, pointShape, width, fillColor, styleProperty, neighborhood, lineType)Image
ArgumentTypeDétails
ceci : collectionFeatureCollectionCollection à dessiner.
colorChaîne, valeur par défaut : "black"Couleur par défaut (valeur de couleur CSS 3.0, par exemple 'FF0000' ou 'red') à utiliser pour dessiner les caractéristiques. Compatible avec l'opacité (par exemple, 'FF000088' pour un rouge transparent à 50 %).
pointSizeEntier, par défaut : 3Taille par défaut (en pixels) des repères de points.
pointShapeChaîne, valeur par défaut : "circle"Forme par défaut du repère à dessiner à chaque point. Valeur parmi : `circle`, `square`, `diamond`, `cross`, `plus`, `pentagram`, `hexagram`, `triangle`, `triangle_up`, `triangle_down`, `triangle_left`, `triangle_right`, `pentagon`, `hexagon`, `star5`, `star6`. Cet argument accepte également les abréviations de marqueurs Matlab suivantes : `o`, `s`, `d`, `x`, `+`, `p`, `h`, `^`, `v`, `<`, `>`.
widthFloat, valeur par défaut : 2Largeur de ligne par défaut pour les lignes et les contours des polygones et des formes de points.
fillColorChaîne, valeur par défaut : nullCouleur de remplissage des polygones et des formes de points. La valeur par défaut est "color" avec une opacité de 0,66.
stylePropertyChaîne, valeur par défaut : nullPropriété par fonctionnalité censée contenir un dictionnaire. Les valeurs du dictionnaire remplacent les valeurs par défaut de cette fonctionnalité.
neighborhoodEntier, par défaut : 5Si styleProperty est utilisé et qu'une fonctionnalité a une taille de point ou une largeur supérieure à celles par défaut, des artefacts de mosaïque peuvent se produire. Spécifie le voisinage maximal (pointSize + width) nécessaire pour toute fonctionnalité.
lineTypeChaîne, valeur par défaut : "solid"Style de ligne par défaut pour les lignes et les contours des polygones et des formes de points. La valeur par défaut est "solid". Au choix : solide, en pointillés ou en tirets.

Exemples

Éditeur de code (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');

Configuration de Python

Consultez la page Environnement Python pour en savoir plus sur l'API Python et sur l'utilisation de geemap pour le développement interactif.

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