בדומה לתמונות, לגיאומטריות ולתכונות, אפשר להוסיף אוספים של תכונות למפה ישירות באמצעות Map.addLayer(). בתצוגה הוויזואלית שמוגדרת כברירת מחדל, הוקטורים יוצגו עם קווים שחורים מוצקים ומילוי שחור חצי שקוף. כדי להציג את הווקטורים בצבע, מציינים את הפרמטר color. בתרשים הבא מוצגים אזורי האקולוגיה של 'RESOLVE' (Dinerstein et al. 2017) כתצוגה חזותית שמוגדרת כברירת מחדל ובאדום:
Code Editor (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
כדי לקבל אפשרויות תצוגה נוספות, משתמשים ב-featureCollection.draw(). באופן ספציפי, הפרמטרים pointRadius ו-strokeWidth קובעים את הגודל של הנקודות והקווים, בהתאמה, ב-FeatureCollection שעבר רינדור:
Code Editor (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')
הפלט של draw() הוא תמונה עם פסים אדומים, ירוקים וכחולים שמוגדרים בהתאם לפרמטר color שצוין.
כדי לשלוט יותר באופן שבו FeatureCollection מוצג, משתמשים ב-image.paint() עם FeatureCollection כארגומנטים. בניגוד ל-draw(), שמפיק תמונה תצוגה בת שלושה פסים של 8 ביט, הפונקציה image.paint() מפיקה תמונה עם הערך המספרי שצוין 'מצויר' בה. לחלופין, אפשר לציין את השם של נכס ב-FeatureCollection שמכיל את המספרים שרוצים לצבוע. הפרמטר width מתנהג באותו אופן: הוא יכול להיות קבוע או שם של מאפיין עם מספר ברוחב הקו. לדוגמה:
Code Editor (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')
חשוב לזכור שצריך לבצע הטמעה (cast) של התמונה הריקה שבה מציירים את התכונות לפני שמתחילים לצייר. הסיבה לכך היא שתמונה קבועה מתנהגת כקבועה: היא מוצמדת לערך האיפוס. כדי לצבוע את הקצוות של התכונות בערכים שהוגדרו ממאפיין של התכונות, מגדירים את פרמטר הצבע לשם המאפיין עם ערכים מספריים:
Code Editor (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')
אפשר להגדיר את הצבע והרוחב שבהם יתוארו הגבולות באמצעות מאפיינים. לדוגמה:
Code Editor (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' )
אם לא מציינים את הפרמטר width, החלק הפנימי של התכונות ממולא:
Code Editor (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')
כדי ליצור רינדור גם של הפנים וגם של הקצוות של התכונות, מציירים את התמונה הריקה פעמיים:
Code Editor (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', )