הודעה: כל הפרויקטים הלא מסחריים שנרשמו לשימוש ב-Earth Engine לפני
15 באפריל 2025 חייבים
לאמת את הזכאות לשימוש לא מסחרי כדי לשמור על הגישה. אם לא תאמתו את החשבון עד 26 בספטמבר 2025, יכול להיות שהגישה שלכם תושעה.
ee.Image.sample
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
דוגם את הפיקסלים של תמונה ומחזיר אותם כ-FeatureCollection. לכל תכונה תהיה מאפיין אחד לכל פס בתמונת הקלט. שימו לב: התנהגות ברירת המחדל היא השמטה של תכונות שחופפות לפיקסלים מוסתרים, וכתוצאה מכך מאפיינים עם ערך null (ראו את הארגומנט dropNulls).
שימוש | החזרות |
---|
Image.sample(region, scale, projection, factor, numPixels, seed, dropNulls, tileScale, geometries) | FeatureCollection |
ארגומנט | סוג | פרטים |
---|
זה: image | תמונה | התמונה לדגימה. |
region | גיאומטריה, ברירת מחדל: null | האזור שממנו נדגום. אם לא מציינים ערך, המערכת משתמשת בכל שטח התמונה. |
scale | מספר ממשי (float), ברירת מחדל: null | קנה מידה נומינלי במטרים של ההטלה לדגימה. |
projection | תחזית, ברירת מחדל: null | ההטלה שבה יתבצע הדגימה. אם לא מציינים, נעשה שימוש בהטלה של הפס הראשון של התמונה. אם מציינים את הארגומנט הזה בנוסף לארגומנט scale, הערך ישונה בהתאם לערך של scale. |
factor | מספר ממשי (float), ברירת מחדל: null | גורם דילול, בטווח (0, 1]. אם מציינים את המאפיין הזה, אסור לציין את המאפיין numPixels. ברירת המחדל היא ללא דגימת משנה. |
numPixels | Long, ברירת מחדל: null | המספר המשוער של הפיקסלים לדגימה. אם מציינים את המאפיין הזה, אסור לציין את המאפיין factor. |
seed | מספר שלם, ברירת מחדל: 0 | ערך התחלתי אקראי לשימוש בדגימת משנה. |
dropNulls | בוליאני, ברירת מחדל: true | מסננים את התוצאה כדי להסיר מאפיינים עם מאפיינים בעלי ערך null. |
tileScale | מספר ממשי (float), ברירת מחדל: 1 | גורם לקביעת קנה מידה שמשמש להקטנת הגודל של משבצת צבירה. אם משתמשים בערך גדול יותר של tileScale (למשל, 2 או 4) עשויים לאפשר חישובים שגורמים לחריגה מזיכרון עם ברירת המחדל. |
geometries | בוליאני, ברירת מחדל: false | אם הערך הוא True, מרכז הפיקסל שנדגם מתווסף כמאפיין הגיאומטריה של תכונת הפלט. אחרת, צורות גיאומטריות יושמטו (כדי לחסוך בזיכרון). |
דוגמאות
עורך הקוד (JavaScript)
// Demonstrate extracting pixels from an image as features with
// ee.Image.sample(), and show how the features are aligned with the pixels.
// An image with one band of elevation data.
var image = ee.Image('CGIAR/SRTM90_V4');
var VIS_MIN = 1620;
var VIS_MAX = 1650;
Map.addLayer(image, {min: VIS_MIN, max: VIS_MAX}, 'SRTM');
// Region to sample.
var region = ee.Geometry.Polygon(
[[[-110.006, 40.002],
[-110.006, 39.999],
[-109.995, 39.999],
[-109.995, 40.002]]], null, false);
// Show region on the map.
Map.setCenter(-110, 40, 16);
Map.addLayer(ee.FeatureCollection([region]).style({"color": "00FF0022"}));
// Perform sampling; convert image pixels to features.
var samples = image.sample({
region: region,
// Default (false) is no geometries in the output.
// When set to true, each feature has a Point geometry at the center of the
// image pixel.
geometries: true,
// The scale is not specified, so the resolution of the image will be used,
// and there is a feature for every pixel. If we give a scale parameter, the
// image will be resampled and there will be more or fewer features.
//
// scale: 200,
});
// Visualize sample data using ee.FeatureCollection.style().
var styled = samples
.map(function (feature) {
return feature.set('style', {
pointSize: feature.getNumber('elevation').unitScale(VIS_MIN, VIS_MAX)
.multiply(15),
});
})
.style({
color: '000000FF',
fillColor: '00000000',
styleProperty: 'style',
neighborhood: 6, // increase to correctly draw large points
});
Map.addLayer(styled);
// Each sample feature has a point geometry and a property named 'elevation'
// corresponding to the band named 'elevation' of the image. If there are
// multiple bands they will become multiple properties. This will print:
//
// geometry: Point (-110.01, 40.00)
// properties:
// elevation: 1639
print(samples.first());
הגדרת Python
מידע על Python API ועל שימוש ב-geemap
לפיתוח אינטראקטיבי מופיע בדף
Python Environment.
import ee
import geemap.core as geemap
Colab (Python)
# Demonstrate extracting pixels from an image as features with
# ee.Image.sample(), and show how the features are aligned with the pixels.
# An image with one band of elevation data.
image = ee.Image('CGIAR/SRTM90_V4')
vis_min = 1620
vis_max = 1650
m = geemap.Map()
m.add_layer(image, {'min': vis_min, 'max': vis_max}, 'SRTM')
# Region to sample.
region = ee.Geometry.Polygon(
[[
[-110.006, 40.002],
[-110.006, 39.999],
[-109.995, 39.999],
[-109.995, 40.002],
]],
None,
False,
)
# Show region on the map.
m.set_center(-110, 40, 16)
m.add_layer(ee.FeatureCollection([region]).style(color='00FF0022'))
# Perform sampling convert image pixels to features.
samples = image.sample(
region=region,
# Default (False) is no geometries in the output.
# When set to True, each feature has a Point geometry at the center of the
# image pixel.
geometries=True,
# The scale is not specified, so the resolution of the image will be used,
# and there is a feature for every pixel. If we give a scale parameter, the
# image will be resampled and there will be more or fewer features.
#
# scale=200,
)
def scale_point_size(feature):
elevation = feature.getNumber('elevation')
point_size = elevation.unitScale(vis_min, vis_max).multiply(15)
feature.set('style', {'pointSize': point_size})
return feature
# Visualize sample data using ee.FeatureCollection.style().
styled = samples.map(scale_point_size).style(
color='000000FF',
fillColor='00000000',
styleProperty='style',
neighborhood=6, # increase to correctly draw large points
)
m.add_layer(styled)
display(m)
# Each sample feature has a point geometry and a property named 'elevation'
# corresponding to the band named 'elevation' of the image. If there are
# multiple bands they will become multiple properties. This will print:
#
# geometry: Point (-110.01, 40.00)
# properties:
# elevation: 1639
display(samples.first())
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 4.0 ודוגמאות הקוד הן ברישיון Apache 2.0. לפרטים, ניתן לעיין במדיניות האתר Google Developers. Java הוא סימן מסחרי רשום של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-07-26 (שעון UTC).
[null,null,["עדכון אחרון: 2025-07-26 (שעון UTC)."],[],[]]