ee.Geometry

创建几何图形。

用法返回
ee.Geometry(geoJson, proj, geodesic, evenOdd)几何图形
参数类型详细信息
geoJson对象描述几何图形的 GeoJSON 对象或要重新解释为几何图形的 ComputedObject。支持 GeoJSON 规范中的 CRS 规范,但仅允许命名 CRS(而非“链接”CRS)。如果此参数包含“测地线”字段,并且未指定 opt_geodesic,则此字段将用作 opt_geodesic。
proj投影,可选可选的投影规范,可以是 CRS ID 代码,也可以是 WKT 字符串。如果指定,则会替换 geoJson 参数中找到的所有 CRS。如果未指定,且 geoJson 未声明 CRS,则默认为“EPSG:4326”(x=经度,y=纬度)。
geodesic布尔值,可选是否应将线段解读为球面测地线。如果为 false,表示应将线段解释为指定 CRS 中的平面线。如果未指定,则当 CRS 为地理坐标系(包括默认的 EPSG:4326)时,默认值为 true;当 CRS 为投影坐标系时,默认值为 false。
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 API 和如何使用 geemap 进行交互式开发,请参阅 Python 环境页面。

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())