お知らせ :
2025 年 4 月 15 日 より前に Earth Engine の使用を登録したすべての非商用プロジェクトは、Earth Engine へのアクセスを維持するために
非商用目的での利用資格を確認 する必要があります。
フィードバックを送信
ee.Image.sample
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
画像のピクセルをサンプリングし、FeatureCollection として返します。各特徴量には、入力画像のバンドごとに 1 つのプロパティがあります。デフォルトの動作では、マスクされたピクセルと交差する特徴が削除され、null 値のプロパティが生成されます(dropNulls 引数をご覧ください)。
用途 戻り値 Image. sample (region , scale , projection , factor , numPixels , seed , dropNulls , tileScale , geometries )
FeatureCollection
引数 タイプ 詳細 これ: image
画像 サンプリングする画像。 region
Geometry、デフォルト: null サンプリング元のリージョン。指定しない場合、イメージのフットプリント全体が使用されます。 scale
浮動小数点数、デフォルト: null サンプリングする投影のメートル単位の名義尺度。 projection
Projection、デフォルト: null サンプリングする投影。指定しない場合、イメージの最初のバンドの投影が使用されます。スケールに加えて指定された場合、指定されたスケールに再スケーリングされます。 factor
浮動小数点数、デフォルト: null サブサンプリング係数(0 より大きく 1 以下の値)。指定する場合、numPixels は指定できません。デフォルトはサブサンプリングなしです。 numPixels
Long、デフォルト: null サンプリングするおおよそのピクセル数。指定した場合、「factor」は指定できません。 seed
整数、デフォルト: 0 サブサンプリングに使用するランダム化シード。 dropNulls
ブール値。デフォルト値は true です。 結果をフィルタして、null 値のプロパティを持つフィーチャーを削除します。 tileScale
浮動小数点数、デフォルト: 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 環境 のページをご覧ください。
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 ())
フィードバックを送信
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 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。"],[[["\u003cp\u003e\u003ccode\u003eImage.sample()\u003c/code\u003e extracts pixel values from an image and converts them into a FeatureCollection, with each feature representing a pixel and its properties corresponding to the band values.\u003c/p\u003e\n"],["\u003cp\u003eYou can define a region of interest, control the sampling scale and projection, and adjust the number of sampled pixels using arguments like \u003ccode\u003eregion\u003c/code\u003e, \u003ccode\u003escale\u003c/code\u003e, \u003ccode\u003eprojection\u003c/code\u003e, \u003ccode\u003efactor\u003c/code\u003e, and \u003ccode\u003enumPixels\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eSampled features can optionally include point geometries representing pixel centers using the \u003ccode\u003egeometries\u003c/code\u003e argument.\u003c/p\u003e\n"],["\u003cp\u003eBy default, features associated with masked pixels (resulting in null-valued properties) are excluded, which can be controlled using the \u003ccode\u003edropNulls\u003c/code\u003e argument.\u003c/p\u003e\n"]]],[],null,[]]