ee.FeatureCollection.style

使用简单的样式语言绘制矢量集合以进行可视化。

用法返回
FeatureCollection.style(color, pointSize, pointShape, width, fillColor, styleProperty, neighborhood, lineType)图片
参数类型详细信息
此:collectionFeatureCollection要绘制的集合。
color字符串,默认值:“black”默认颜色(CSS 3.0 颜色值,例如 'FF0000' 或 'red')来绘制特征。支持不透明度(例如,'FF000088' 表示 50% 透明度的红色)。
pointSize整数,默认值:3点标记的默认大小(以像素为单位)。
pointShape字符串,默认值:“circle”要在每个点位置绘制的标记的默认形状。以下之一:`circle`、`square`、`diamond`、`cross`、`plus`、`pentagram`、`hexagram`、`triangle`、`triangle_up`、`triangle_down`、`triangle_left`、`triangle_right`、`pentagon`、`hexagon`、`star5`、`star6`。此实参还支持以下 Matlab 标记缩写:`o`、`s`、`d`、`x`、`+`、`p`、`h`、`^`、`v`、`<`、`>。
width浮点数,默认值:2线条以及多边形和点状形状的轮廓的默认线宽。
fillColor字符串,默认值:null用于填充多边形和点形状的颜色。默认值为不透明度为 0.66 的“color”。
styleProperty字符串,默认值:null一种按功能划分的属性,预计包含一个字典。字典中的值会覆盖相应功能的任何默认值。
neighborhood整数,默认值:5如果使用了 styleProperty,并且任何要素的点大小或宽度大于默认值,则可能会出现平铺伪影。指定任何特征所需的最大邻域(pointSize + width)。
lineType字符串,默认值:“solid”线条以及多边形和点状形状轮廓的默认线条样式。默认值为“实线”。以下各项之一:实线、点划线、虚线。

示例

代码编辑器 (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');

Python 设置

如需了解 Python API 和如何使用 geemap 进行交互式开发,请参阅 Python 环境页面。

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