ee.Geometry

建立幾何圖形。

用量傳回
ee.Geometry(geoJson, proj, geodesic, evenOdd)幾何圖形
引數類型詳細資料
geoJson物件描述幾何的 GeoJSON 物件,或要重新解讀為 Geometry 的 ComputedObject。支援 GeoJSON 規格的 CRS 規格,但只允許具名 (而非「連結」的 CRS)。如果這包含「測地線」欄位,且未指定 opt_geodesic,則會將其做為 opt_geodesic 使用。
proj投影 (選用)投影規格 (選用),可以是 CRS ID 程式碼或 WKT 字串。如果指定,則會覆寫 geoJson 參數中找到的任何 CRS。如果未指定,且 geoJson 未宣告 CRS,則預設為「EPSG:4326」(x=經度,y=緯度)。
geodesic布林值 (選填)是否應將線段解讀為球形測地線。如果為 false,表示線段應解讀為指定 CRS 中的平面線。如果未提供,則預設值為 true (如果 CRS 為地理座標系統,包括預設的 EPSG:4326),或 false (如果 CRS 為投影座標系統)。
evenOdd布林值 (選填)如果為 true,多邊形內部會依據偶數/奇數規則判斷,也就是說,如果某個點要抵達無限遠的點,必須穿過奇數個邊緣,該點就會位於多邊形內部。否則,多邊形會使用左側內部規則,也就是沿著頂點以指定順序移動時,內部位於外殼邊緣的左側。如未指定,則預設為 true。

範例

程式碼編輯器 (JavaScript)

// A GeoJSON object for a triangular polygon.
var geojsonObject = {
  "type": "Polygon",
  "coordinates": [
    [
      [
        -122.085,
        37.423
      ],
      [
        -122.092,
        37.424
      ],
      [
        -122.085,
        37.418
      ],
      [
        -122.085,
        37.423
      ]
    ]
  ]
};
print('ee.Geometry accepts a GeoJSON object', ee.Geometry(geojsonObject));

// GeoJSON strings need to be converted to an object.
var geojsonString = JSON.stringify(geojsonObject);
print('A GeoJSON string needs to be converted to an object',
      ee.Geometry(JSON.parse(geojsonString)));

// Use ee.Geometry to cast computed geometry objects into the ee.Geometry
// class to access their methods. In the following example an ee.Geometry
// object is stored as a ee.Feature property. When it is retrieved with the
// .get() function, a computed geometry object is returned. Cast the computed
// object as a ee.Geometry to get the geometry's bounds, for instance.
var feature = ee.Feature(null, {geom: ee.Geometry(geojsonObject)});
print('Cast computed geometry objects to ee.Geometry class',
      ee.Geometry(feature.get('geom')).bounds());

Python 設定

請參閱 Python 環境頁面,瞭解 Python API 和如何使用 geemap 進行互動式開發。

import ee
import geemap.core as geemap

Colab (Python)

import json

# A GeoJSON object for a triangular polygon.
geojson_object = {
    'type': 'Polygon',
    'coordinates': [
        [
            [
                -122.085,
                37.423
            ],
            [
                -122.092,
                37.424
            ],
            [
                -122.085,
                37.418
            ],
            [
                -122.085,
                37.423
                ]
            ]
        ]
}
print(
    'ee.Geometry accepts a GeoJSON object:',
    ee.Geometry(geojson_object).getInfo()
)

# GeoJSON strings need to be converted to an object.
geojson_string = json.dumps(geojson_object)
print('A GeoJSON string needs to be converted to an object:',
      ee.Geometry(json.loads(geojson_string)).getInfo())

# Use ee.Geometry to cast computed geometry objects into the ee.Geometry
# class to access their methods. In the following example an ee.Geometry
# object is stored as a ee.Feature property. When it is retrieved with the
# .get() function, a computed geometry object is returned. Cast the computed
# object as a ee.Geometry to get the geometry's bounds, for instance.
feature = ee.Feature(None, {'geom': ee.Geometry(geojson_object)})
print('Cast computed geometry objects to ee.Geometry class:',
      ee.Geometry(feature.get('geom')).bounds().getInfo())