Как и в случае с изображениями, геометрией и объектами, коллекции объектов можно добавлять на карту непосредственно с помощью Map.addLayer()
. Визуализация по умолчанию будет отображать векторы сплошными черными линиями и полупрозрачной черной заливкой. Чтобы визуализировать векторы в цвете, укажите параметр color
. Ниже показаны экорегионы «RESOLVE» ( Dinerstein et al. 2017 ) в качестве визуализации по умолчанию и выделены красным цветом:
Редактор кода (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
Колаб (Питон)
# 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
Для дополнительных параметров отображения используйте featureCollection.draw()
. В частности, параметры pointRadius
strokeWidth
управляют размером точек и линий соответственно в визуализированной FeatureCollection
:
Редактор кода (JavaScript)
Map.addLayer(ecoregions.draw({color: '006600', strokeWidth: 5}), {}, 'drawn');
import ee import geemap.core as geemap
Колаб (Питон)
m.add_layer(ecoregions.draw(color='006600', strokeWidth=5), {}, 'drawn')
Результатом draw()
является изображение с красными, зелеными и синими полосами, установленными в соответствии с указанным color
параметром.
Для большего контроля над отображением FeatureCollection
используйте image.paint()
с FeatureCollection
в качестве аргумента. В отличие от draw()
, который выводит трехполосное 8-битное изображение, image.paint()
выводит изображение с указанным числовым значением, «нарисованным» в нем. Альтернативно вы можете указать имя свойства в FeatureCollection
, которое содержит числа для рисования. Параметр width
ведет себя аналогично: это может быть константа или имя свойства с числом ширины линии. Например:
Редактор кода (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
Колаб (Питон)
# 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')
Обратите внимание, что пустое изображение, в которое вы рисуете объекты, необходимо преобразовать перед рисованием. Это связано с тем, что постоянное изображение ведет себя как константа: оно привязано к значению инициализации. Чтобы окрасить края объекта значениями, заданными из свойства объекта, задайте для параметра цвета имя свойства с числовыми значениями:
Редактор кода (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
Колаб (Питон)
# 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')
Цвет и ширину границ можно задать с помощью свойств. Например:
Редактор кода (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
Колаб (Питон)
# 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' )
Если параметр width
не указан, окрашивается внутренняя часть объектов:
Редактор кода (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
Колаб (Питон)
# 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')
Чтобы визуализировать как внутреннюю часть, так и края объектов, дважды закрасьте пустое изображение:
Редактор кода (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
Колаб (Питон)
# 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', )
Как и в случае с изображениями, геометрией и объектами, коллекции объектов можно добавлять на карту непосредственно с помощью Map.addLayer()
. Визуализация по умолчанию будет отображать векторы сплошными черными линиями и полупрозрачной черной заливкой. Чтобы визуализировать векторы в цвете, укажите параметр color
. Ниже показаны экорегионы «RESOLVE» ( Dinerstein et al. 2017 ) в качестве визуализации по умолчанию и выделены красным цветом:
Редактор кода (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
Колаб (Питон)
# 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
Для дополнительных параметров отображения используйте featureCollection.draw()
. В частности, параметры pointRadius
strokeWidth
управляют размером точек и линий соответственно в визуализированной FeatureCollection
:
Редактор кода (JavaScript)
Map.addLayer(ecoregions.draw({color: '006600', strokeWidth: 5}), {}, 'drawn');
import ee import geemap.core as geemap
Колаб (Питон)
m.add_layer(ecoregions.draw(color='006600', strokeWidth=5), {}, 'drawn')
Результатом draw()
является изображение с красными, зелеными и синими полосами, установленными в соответствии с указанным color
параметром.
Для большего контроля над отображением FeatureCollection
используйте image.paint()
с FeatureCollection
в качестве аргумента. В отличие от draw()
, который выводит трехполосное 8-битное изображение, image.paint()
выводит изображение с указанным числовым значением, «нарисованным» в нем. Альтернативно вы можете указать имя свойства в FeatureCollection
, которое содержит числа для рисования. Параметр width
ведет себя аналогично: это может быть константа или имя свойства с числом ширины линии. Например:
Редактор кода (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
Колаб (Питон)
# 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')
Обратите внимание, что пустое изображение, в которое вы рисуете объекты, необходимо преобразовать перед рисованием. Это связано с тем, что постоянное изображение ведет себя как константа: оно привязано к значению инициализации. Чтобы окрасить края объекта значениями, заданными из свойства объекта, задайте для параметра цвета имя свойства с числовыми значениями:
Редактор кода (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
Колаб (Питон)
# 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')
Цвет и ширину границ можно задать с помощью свойств. Например:
Редактор кода (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
Колаб (Питон)
# 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' )
Если параметр width
не указан, окрашивается внутренняя часть объектов:
Редактор кода (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
Колаб (Питон)
# 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')
Чтобы визуализировать как внутреннюю часть, так и края объектов, дважды закрасьте пустое изображение:
Редактор кода (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
Колаб (Питон)
# 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', )