Thông báo: Tất cả dự án phi thương mại đã đăng ký sử dụng Earth Engine trước
ngày 15 tháng 4 năm 2025 phải
xác minh điều kiện sử dụng phi thương mại để duy trì quyền truy cập. Nếu bạn chưa xác minh trước ngày 26 tháng 9 năm 2025, quyền truy cập của bạn có thể bị tạm ngưng.
ee.FeatureCollection.style
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Vẽ một bộ sưu tập vectơ để trực quan hoá bằng ngôn ngữ kiểu đơn giản.
| Cách sử dụng | Giá trị trả về |
|---|
FeatureCollection.style(color, pointSize, pointShape, width, fillColor, styleProperty, neighborhood, lineType) | Hình ảnh |
| Đối số | Loại | Thông tin chi tiết |
|---|
this: collection | FeatureCollection | Bộ sưu tập cần vẽ. |
color | Chuỗi, mặc định: "black" | Màu mặc định (giá trị màu CSS 3.0, ví dụ: "FF0000" hoặc "red") để dùng cho việc vẽ các đối tượng. Hỗ trợ độ mờ (ví dụ: "FF000088" cho màu đỏ trong suốt 50%). |
pointSize | Số nguyên, mặc định: 3 | Kích thước mặc định tính bằng pixel của điểm đánh dấu. |
pointShape | Chuỗi, mặc định: "circle" | Hình dạng mặc định của điểm đánh dấu cần vẽ tại mỗi vị trí điểm. Một trong các giá trị: "circle", "square", "diamond", "cross", "plus", "pentagram", "hexagram", "triangle", "triangle_up", "triangle_down", "triangle_left", "triangle_right", "pentagon", "hexagon", "star5", "star6". Đối số này cũng hỗ trợ các chữ viết tắt sau của điểm đánh dấu Matlab: "o", "s", "d", "x", "+", "p", "h", "^", "v", "<", ">". |
width | Độ chính xác đơn, mặc định: 2 | Chiều rộng đường kẻ mặc định cho các đường kẻ và đường viền của đa giác và hình dạng điểm. |
fillColor | Chuỗi, mặc định: null | Màu để tô đa giác và hình dạng điểm. Mặc định là "color" (màu) ở độ mờ 0,66. |
styleProperty | Chuỗi, mặc định: null | Một thuộc tính cho mỗi đối tượng dự kiến sẽ chứa một từ điển. Các giá trị trong từ điển sẽ ghi đè mọi giá trị mặc định cho tính năng đó. |
neighborhood | Số nguyên, mặc định: 5 | Nếu bạn sử dụng styleProperty và bất kỳ đối tượng nào có pointSize hoặc chiều rộng lớn hơn giá trị mặc định, thì có thể xảy ra hiện tượng tạo ô giả. Chỉ định vùng lân cận tối đa (pointSize + width) cần thiết cho mọi đối tượng. |
lineType | Chuỗi, mặc định: "solid" | Kiểu đường mặc định cho đường kẻ và đường viền của đa giác và hình dạng điểm. Giá trị mặc định là "solid". Một trong các lựa chọn sau: liền, chấm, nét đứt. |
Ví dụ
Trình soạn thảo mã (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');
Thiết lập Python
Hãy xem trang
Môi trường Python để biết thông tin về API Python và cách sử dụng geemap cho quá trình phát triển tương tác.
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
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-07-26 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-07-26 UTC."],[],[]]