Cũng như hình ảnh, hình học và đối tượng, bạn có thể thêm trực tiếp bộ sưu tập đối tượng vào bản đồ bằng Map.addLayer()
. Hình ảnh trực quan mặc định sẽ hiển thị các vectơ có đường màu đen đậm và màu đen bán mờ. Để kết xuất vectơ có màu, hãy chỉ định tham số color
. Hình sau đây hiển thị các khu vực sinh thái "RESOLVE" (Dinerstein et al. 2017) dưới dạng hình ảnh trực quan mặc định và màu đỏ:
Trình soạn thảo mã (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
Để biết thêm các tuỳ chọn hiển thị, hãy sử dụng featureCollection.draw()
. Cụ thể, tham số pointRadius
và strokeWidth
lần lượt kiểm soát kích thước của các điểm và đường trong FeatureCollection
được kết xuất:
Trình soạn thảo mã (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')
Kết quả của draw()
là một hình ảnh có các dải màu đỏ, xanh lục và xanh dương được đặt theo tham số color
đã chỉ định.
Để kiểm soát tốt hơn cách hiển thị FeatureCollection
, hãy sử dụng image.paint()
với FeatureCollection
làm đối số. Không giống như draw()
, xuất ra hình ảnh hiển thị 3 băng, 8 bit, image.paint()
xuất ra hình ảnh có giá trị số được chỉ định "vẽ" vào hình ảnh đó. Ngoài ra, bạn có thể cung cấp tên của một thuộc tính trong FeatureCollection
chứa các số cần vẽ. Tham số width
hoạt động theo cách tương tự: tham số này có thể là một hằng số hoặc tên của một thuộc tính có số cho chiều rộng đường kẻ. Ví dụ:
Trình soạn thảo mã (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')
Xin lưu ý rằng hình ảnh trống mà bạn vẽ các tính năng cần được truyền trước khi vẽ. Điều này là do hình ảnh không đổi hoạt động như một hằng số: hình ảnh này được cố định theo giá trị khởi tạo. Để tô màu các cạnh của đối tượng bằng các giá trị được đặt từ một thuộc tính của đối tượng, hãy đặt tham số màu thành tên của thuộc tính có giá trị dạng số:
Trình soạn thảo mã (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')
Bạn có thể đặt cả màu và chiều rộng để vẽ ranh giới bằng các thuộc tính. Ví dụ:
Trình soạn thảo mã (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' )
Nếu bạn không cung cấp tham số width
, thì nội thất của các tính năng sẽ được sơn:
Trình soạn thảo mã (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')
Để kết xuất cả nội thất và các cạnh của các tính năng, hãy vẽ hình ảnh trống hai lần:
Trình soạn thảo mã (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', )