הודעה : כל הפרויקטים הלא מסחריים שנרשמו לשימוש ב-Earth Engine לפני
15 באפריל 2025 חייבים
לאמת את הזכאות לשימוש לא מסחרי כדי לשמור על הגישה. אם לא תאמתו את החשבון עד 26 בספטמבר 2025, יכול להיות שהגישה שלכם תושעה.
שליחת משוב
ee.FeatureCollection.cluster
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
מבצעת אשכול של כל תכונה באוסף, ומוסיפה לכל תכונה עמודה חדשה שמכילה את מספר האשכול שאליו היא שויכה.
שימוש החזרות FeatureCollection. cluster (clusterer, outputName )
FeatureCollection
ארגומנט סוג פרטים זה: features
FeatureCollection אוסף התכונות לאשכול. כל תכונה חייבת להכיל את כל המאפיינים בסכימה של הכלי לאשכולות. clusterer
Clusterer האלגוריתם לאשכולות שבו רוצים להשתמש. outputName
מחרוזת, ברירת מחדל: cluster השם של נכס הפלט שרוצים להוסיף.
דוגמאות
עורך הקוד (JavaScript)
// Import a Sentinel-2 surface reflectance image.
var image = ee . Image ( 'COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG' );
// Get the image geometry to define the geographical bounds of a point sample.
var imageBounds = image . geometry ();
// Sample the image at a set of random points; a feature collection is returned.
var pointSampleFc = image . sample (
{ region : imageBounds , scale : 20 , numPixels : 1000 , geometries : true });
// Instantiate a k-means clusterer and train it.
var clusterer = ee . Clusterer . wekaKMeans ( 5 ). train ( pointSampleFc );
// Cluster the input using the trained clusterer; optionally specify the name
// of the output cluster ID property.
var clusteredFc = pointSampleFc . cluster ( clusterer , 'spectral_cluster' );
print ( 'Note added "spectral_cluster" property for an example feature' ,
clusteredFc . first (). toDictionary ());
// Visualize the clusters by applying a unique color to each cluster ID.
var palette = ee . List ([ '8dd3c7' , 'ffffb3' , 'bebada' , 'fb8072' , '80b1d3' ]);
var clusterVis = clusteredFc . map ( function ( feature ) {
return feature . set ( 'style' , {
color : palette . get ( feature . get ( 'spectral_cluster' )),
});
}). style ({ styleProperty : 'style' });
// Display the points colored by cluster ID with the S2 image.
Map . setCenter ( - 122.35 , 37.47 , 9 );
Map . addLayer ( image , { bands : [ 'B4' , 'B3' , 'B2' ], min : 0 , max : 1500 }, 'S2 image' );
Map . addLayer ( clusterVis , null , 'Clusters' );
הגדרת Python
מידע על Python API ועל שימוש ב-geemap
לפיתוח אינטראקטיבי מופיע בדף
Python Environment .
import ee
import geemap.core as geemap
Colab (Python)
# Import a Sentinel-2 surface reflectance image.
image = ee . Image ( 'COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG' )
# Get the image geometry to define the geographical bounds of a point sample.
image_bounds = image . geometry ()
# Sample the image at a set of random points a feature collection is returned.
point_sample_fc = image . sample (
region = image_bounds , scale = 20 , numPixels = 1000 , geometries = True
)
# Instantiate a k-means clusterer and train it.
clusterer = ee . Clusterer . wekaKMeans ( 5 ) . train ( point_sample_fc )
# Cluster the input using the trained clusterer optionally specify the name
# of the output cluster ID property.
clustered_fc = point_sample_fc . cluster ( clusterer , 'spectral_cluster' )
display (
'Note added "spectral_cluster" property for an example feature' ,
clustered_fc . first () . toDictionary (),
)
# Visualize the clusters by applying a unique color to each cluster ID.
palette = ee . List ([ '8dd3c7' , 'ffffb3' , 'bebada' , 'fb8072' , '80b1d3' ])
cluster_vis = clustered_fc . map (
lambda feature : feature . set (
'style' , { 'color' : palette . get ( feature . get ( 'spectral_cluster' ))}
)
) . style ( styleProperty = 'style' )
# Display the points colored by cluster ID with the S2 image.
m = geemap . Map ()
m . set_center ( - 122.35 , 37.47 , 9 )
m . add_layer (
image , { 'bands' : [ 'B4' , 'B3' , 'B2' ], 'min' : 0 , 'max' : 1500 }, 'S2 image'
)
m . add_layer ( cluster_vis , None , 'Clusters' )
m
שליחת משוב
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 4.0 ודוגמאות הקוד הן ברישיון Apache 2.0 . לפרטים, ניתן לעיין במדיניות האתר Google Developers . Java הוא סימן מסחרי רשום של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-07-26 (שעון UTC).
רוצה לתת לנו משוב?
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 2025-07-26 (שעון UTC)."],[],[]]