عرض Feature وFeatureCollection

كما هو الحال مع الصور والأشكال الهندسية والعناصر، يمكن إضافة مجموعات العناصر إلى الخريطة مباشرةً باستخدام 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');

إعداد لغة Python

اطّلِع على صفحة بيئة Python للحصول على معلومات عن واجهة برمجة التطبيقات Python API واستخدام IDE geemap لتطوير التطبيقات التفاعلي.

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

للحصول على خيارات عرض إضافية، استخدِم featureCollection.draw(). على وجه التحديد، تتحكم المَعلمتان pointRadius وstrokeWidth في حجم النقاط والخطوط، على التوالي، في FeatureCollection المعروضة:

محرِّر الرموز البرمجية (JavaScript)

Map.addLayer(ecoregions.draw({color: '006600', strokeWidth: 5}), {}, 'drawn');

إعداد لغة Python

اطّلِع على صفحة بيئة Python للحصول على معلومات عن واجهة برمجة التطبيقات Python API واستخدام IDE geemap لتطوير التطبيقات التفاعلي.

import ee
import geemap.core as geemap

Colab (Python)

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');

إعداد لغة Python

اطّلِع على صفحة بيئة Python للحصول على معلومات عن واجهة برمجة التطبيقات Python API واستخدام IDE geemap لتطوير التطبيقات التفاعلي.

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')

يُرجى العِلم أنّه يجب بثّ الصورة الفارغة التي ترسم عليها الميزات قبل الرسم. ويعود السبب في ذلك إلى أنّ الصورة الثابتة تتصرف كقيمة ثابتة: يتم تثبيتها على قيمة الإعداد. لتلوين حواف العناصر باستخدام قيم تم ضبطها من سمة العناصر، اضبط مَعلمة اللون على اسم السمة باستخدام قيم رقمية:

محرِّر الرموز البرمجية (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');

إعداد لغة Python

اطّلِع على صفحة بيئة Python للحصول على معلومات عن واجهة برمجة التطبيقات Python API واستخدام IDE geemap لتطوير التطبيقات التفاعلي.

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')

يمكن ضبط اللون والعرض اللذَين يتم رسم الحدود بهما باستخدام السمات. على سبيل المثال:

محرِّر الرموز البرمجية (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');

إعداد لغة Python

اطّلِع على صفحة بيئة Python للحصول على معلومات عن واجهة برمجة التطبيقات Python API واستخدام IDE geemap لتطوير التطبيقات التفاعلي.

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'
)

في حال عدم تقديم المَعلمة 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');

إعداد لغة Python

اطّلِع على صفحة بيئة Python للحصول على معلومات عن واجهة برمجة التطبيقات Python API واستخدام IDE geemap لتطوير التطبيقات التفاعلي.

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')

لعرض كلّ من الأجزاء الداخلية لحواف العناصر وحوافها، ادهن الصورة الفارغة مرّتين:

محرِّر الرموز البرمجية (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');

إعداد لغة Python

اطّلِع على صفحة بيئة Python للحصول على معلومات عن واجهة برمجة التطبيقات Python API واستخدام IDE geemap لتطوير التطبيقات التفاعلي.

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',
)