ประกาศ : โปรเจ็กต์ที่ไม่ใช่เชิงพาณิชย์ทั้งหมดที่ลงทะเบียนเพื่อใช้ Earth Engine ก่อนวันที่
15 เมษายน 2025 ต้อง
ยืนยันการมีสิทธิ์ที่ไม่ใช่เชิงพาณิชย์ เพื่อรักษาสิทธิ์เข้าถึง หากคุณไม่ยืนยันภายในวันที่ 26 กันยายน 2025 ระบบอาจระงับสิทธิ์เข้าถึงของคุณ
ส่งความคิดเห็น
ee.Image.sampleRegions
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
แปลงแต่ละพิกเซลของรูปภาพ (ที่ระดับการซูมที่กำหนด) ซึ่งตัดกับภูมิภาคอย่างน้อย 1 ภูมิภาคเป็นฟีเจอร์ แล้วส่งกลับเป็น FeatureCollection ฟีเจอร์เอาต์พุตแต่ละรายการจะมีพร็อพเพอร์ตี้ 1 รายการต่อแถบของรูปภาพอินพุต รวมถึงพร็อพเพอร์ตี้ที่ระบุซึ่งคัดลอกจากฟีเจอร์อินพุต
โปรดทราบว่ารูปทรงเรขาคณิตจะสแนปกับจุดกึ่งกลางของพิกเซล
การใช้งาน การคืนสินค้า Image. sampleRegions (collection, properties , scale , projection , tileScale , geometries )
FeatureCollection
อาร์กิวเมนต์ ประเภท รายละเอียด ดังนี้ image
รูปภาพ รูปภาพที่จะสุ่มตัวอย่าง collection
FeatureCollection ภูมิภาคที่จะสุ่มตัวอย่าง properties
รายการ (ค่าเริ่มต้น: null) รายการพร็อพเพอร์ตี้ที่จะคัดลอกจากฟีเจอร์อินพุตแต่ละรายการ ค่าเริ่มต้นคือพร็อพเพอร์ตี้ที่ไม่ใช่ระบบทั้งหมด scale
ลอย ค่าเริ่มต้น: null มาตราส่วนที่ระบุเป็นเมตรของภาพฉายที่จะสุ่มตัวอย่าง หากไม่ได้ระบุ ระบบจะใช้สเกลของแถบแรกของรูปภาพ projection
การฉายภาพ ค่าเริ่มต้น: null การฉายภาพที่จะสุ่มตัวอย่าง หากไม่ได้ระบุ ระบบจะใช้การฉายภาพของแถบแรกของรูปภาพ หากระบุเพิ่มเติมจากสเกล ระบบจะปรับขนาดใหม่เป็นสเกลที่ระบุ tileScale
Float, ค่าเริ่มต้น: 1 ปัจจัยการปรับขนาดที่ใช้เพื่อลดขนาดไทล์การรวม การใช้ tileScale ที่ใหญ่ขึ้น (เช่น 2 หรือ 4) อาจเปิดใช้การคำนวณที่หน่วยความจำหมดด้วยค่าเริ่มต้น geometries
บูลีน ค่าเริ่มต้น: false หากเป็นจริง ผลลัพธ์จะมีเรขาคณิตของจุดต่อพิกเซลที่สุ่มตัวอย่าง ไม่เช่นนั้น ระบบจะละเว้นรูปทรงเรขาคณิต (ประหยัดหน่วยความจำ)
ตัวอย่าง
โปรแกรมแก้ไขโค้ด (JavaScript)
// A Sentinel-2 surface reflectance image.
var img = ee . Image ( 'COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG' );
Map . setCenter ( - 122.503881 , 37.765588 , 18 );
Map . addLayer ( img , { bands : [ 'B11' , 'B8' , 'B3' ], min : 100 , max : 4500 }, 'img' );
// A feature collection with two polygon regions each intersecting 36
// pixels at 10 m scale.
var fcPolygon = ee . FeatureCollection ([
ee . Feature ( ee . Geometry . Rectangle (
- 122.50620929 , 37.76502806 , - 122.50552264 , 37.76556663 ), { id : 0 }),
ee . Feature ( ee . Geometry . Rectangle (
- 122.50530270 , 37.76565568 , - 122.50460533 , 37.76619425 ), { id : 1 })
]);
Map . addLayer ( fcPolygon , { color : 'yellow' }, 'fcPolygon' );
var fcPolygonSamp = img . sampleRegions ({
collection : fcPolygon ,
scale : 10 ,
geometries : true
});
// Note that 7 pixels are missing from the sample. If a pixel contains a masked
// band value it will be excluded from the sample. In this case, the TCI_B band
// is masked for each unsampled pixel.
print ( 'A feature per pixel (at given scale) in each region' , fcPolygonSamp );
Map . addLayer ( fcPolygonSamp , { color : 'purple' }, 'fcPolygonSamp' );
// A feature collection with two points intersecting two different pixels.
// This example is included to show the behavior for point geometries. In
// practice, if the feature collection is all points, ee.Image.reduceRegions
// should be used instead to save memory.
var fcPoint = ee . FeatureCollection ([
ee . Feature ( ee . Geometry . Point ([ - 122.50309256 , 37.76605006 ]), { id : 0 }),
ee . Feature ( ee . Geometry . Point ([ - 122.50344661 , 37.76560903 ]), { id : 1 })
]);
Map . addLayer ( fcPoint , { color : 'cyan' }, 'fcPoint' );
var fcPointSamp = img . sampleRegions ({
collection : fcPoint ,
scale : 10
});
print ( 'A feature per point' , fcPointSamp );
การตั้งค่า Python
ดูข้อมูลเกี่ยวกับ Python API และการใช้ geemap
เพื่อการพัฒนาแบบอินเทอร์แอกทีฟได้ที่หน้า
สภาพแวดล้อม Python
import ee
import geemap.core as geemap
Colab (Python)
# A Sentinel-2 surface reflectance image.
img = ee . Image ( 'COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG' )
m = geemap . Map ()
m . set_center ( - 122.503881 , 37.765588 , 18 )
m . add_layer (
img , { 'bands' : [ 'B11' , 'B8' , 'B3' ], 'min' : 100 , 'max' : 4500 }, 'img'
)
display ( m )
# A feature collection with two polygon regions each intersecting 36
# pixels at 10 m scale.
fc_polygon = ee . FeatureCollection ([
ee . Feature (
ee . Geometry . Rectangle (
- 122.50620929 , 37.76502806 , - 122.50552264 , 37.76556663
),
{ 'id' : 0 },
),
ee . Feature (
ee . Geometry . Rectangle (
- 122.50530270 , 37.76565568 , - 122.50460533 , 37.76619425
),
{ 'id' : 1 },
),
])
m . add_layer ( fc_polygon , { 'color' : 'yellow' }, 'fc_polygon' )
fc_polygon_samp = img . sampleRegions (
collection = fc_polygon , scale = 10 , geometries = True
)
# Note that 7 pixels are missing from the sample. If a pixel contains a masked
# band value it will be excluded from the sample. In this case, the TCI_B band
# is masked for each unsampled pixel.
display ( 'A feature per pixel (at given scale) in each region' , fc_polygon_samp )
m . add_layer ( fc_polygon_samp , { 'color' : 'purple' }, 'fc_polygon_samp' )
# A feature collection with two points intersecting two different pixels.
# This example is included to show the behavior for point geometries. In
# practice, if the feature collection is all points, ee.Image.reduceRegions
# should be used instead to save memory.
fc_point = ee . FeatureCollection ([
ee . Feature ( ee . Geometry . Point ([ - 122.50309256 , 37.76605006 ]), { 'id' : 0 }),
ee . Feature ( ee . Geometry . Point ([ - 122.50344661 , 37.76560903 ]), { 'id' : 1 }),
])
m . add_layer ( fc_point , { 'color' : 'cyan' }, 'fc_point' )
fc_point_samp = img . sampleRegions ( collection = fc_point , scale = 10 )
display ( 'A feature per point' , fc_point_samp )
ส่งความคิดเห็น
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 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"],[],["The `Image.sampleRegions` method converts image pixels intersecting specified regions into a `FeatureCollection`. Each output feature contains properties from the input image bands and any designated input feature properties. Geometries are snapped to pixel centers. The sampling scale and projection can be specified; otherwise, the image's first band defaults are used. Optionally, geometries of the sampled pixels can be included, and tile scaling can be used for memory management.\n"]]