公告:所有在
2025 年 4 月 15 日之前注册使用 Earth Engine 的非商业项目都必须
验证是否符合非商业性质的资格条件,才能继续使用 Earth Engine。
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())
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003eCreates a geometry from a GeoJSON object, optionally specifying projection, geodesic handling, and polygon winding rule.\u003c/p\u003e\n"],["\u003cp\u003eAccepts GeoJSON objects or strings (which must be parsed into objects).\u003c/p\u003e\n"],["\u003cp\u003eEnables casting of computed geometry objects (like those in Feature properties) to the \u003ccode\u003eee.Geometry\u003c/code\u003e class for method access.\u003c/p\u003e\n"],["\u003cp\u003eSupports both JavaScript and Python environments within Google Earth Engine.\u003c/p\u003e\n"]]],[],null,["# ee.Geometry\n\n\u003cbr /\u003e\n\nCreates a geometry.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|---------------------------------------------------------------|----------|\n| `ee.Geometry(geoJson, `*proj* `, `*geodesic* `, `*evenOdd*`)` | Geometry |\n\n| Argument | Type | Details |\n|------------|----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `geoJson` | Object | The GeoJSON object describing the geometry or a ComputedObject to be reinterpreted as a Geometry. Supports CRS specifications as per the GeoJSON spec, but only allows named (rather than \"linked\" CRSs). If this includes a 'geodesic' field, and opt_geodesic is not specified, it will be used as opt_geodesic. |\n| `proj` | Projection, optional | An optional projection specification, either as a CRS ID code or as a WKT string. If specified, overrides any CRS found in the geoJson parameter. If unspecified and the geoJson does not declare a CRS, defaults to \"EPSG:4326\" (x=longitude, y=latitude). |\n| `geodesic` | Boolean, optional | Whether line segments should be interpreted as spherical geodesics. If false, indicates that line segments should be interpreted as planar lines in the specified CRS. If absent, defaults to true if the CRS is geographic (including the default EPSG:4326), or to false if the CRS is projected. |\n| `evenOdd` | Boolean, optional | If true, polygon interiors will be determined by the even/odd rule, where a point is inside if it crosses an odd number of edges to reach a point at infinity. Otherwise polygons use the left- inside rule, where interiors are on the left side of the shell's edges when walking the vertices in the given order. If unspecified, defaults to true. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// A GeoJSON object for a triangular polygon.\nvar geojsonObject = {\n \"type\": \"Polygon\",\n \"coordinates\": [\n [\n [\n -122.085,\n 37.423\n ],\n [\n -122.092,\n 37.424\n ],\n [\n -122.085,\n 37.418\n ],\n [\n -122.085,\n 37.423\n ]\n ]\n ]\n};\nprint('ee.Geometry accepts a GeoJSON object', ee.Geometry(geojsonObject));\n\n// GeoJSON strings need to be converted to an object.\nvar geojsonString = JSON.stringify(geojsonObject);\nprint('A GeoJSON string needs to be converted to an object',\n ee.Geometry(JSON.parse(geojsonString)));\n\n// Use ee.Geometry to cast computed geometry objects into the ee.Geometry\n// class to access their methods. In the following example an ee.Geometry\n// object is stored as a ee.Feature property. When it is retrieved with the\n// .get() function, a computed geometry object is returned. Cast the computed\n// object as a ee.Geometry to get the geometry's bounds, for instance.\nvar feature = ee.Feature(null, {geom: ee.Geometry(geojsonObject)});\nprint('Cast computed geometry objects to ee.Geometry class',\n ee.Geometry(feature.get('geom')).bounds());\n```\nPython setup\n\nSee the [Python Environment](/earth-engine/guides/python_install) page for information on the Python API and using\n`geemap` for interactive development. \n\n```python\nimport ee\nimport geemap.core as geemap\n```\n\n### Colab (Python)\n\n```python\nimport json\n\n# A GeoJSON object for a triangular polygon.\ngeojson_object = {\n 'type': 'Polygon',\n 'coordinates': [\n [\n [\n -122.085,\n 37.423\n ],\n [\n -122.092,\n 37.424\n ],\n [\n -122.085,\n 37.418\n ],\n [\n -122.085,\n 37.423\n ]\n ]\n ]\n}\nprint(\n 'ee.Geometry accepts a GeoJSON object:',\n ee.Geometry(geojson_object).getInfo()\n)\n\n# GeoJSON strings need to be converted to an object.\ngeojson_string = json.dumps(geojson_object)\nprint('A GeoJSON string needs to be converted to an object:',\n ee.Geometry(json.loads(geojson_string)).getInfo())\n\n# Use ee.Geometry to cast computed geometry objects into the ee.Geometry\n# class to access their methods. In the following example an ee.Geometry\n# object is stored as a ee.Feature property. When it is retrieved with the\n# .get() function, a computed geometry object is returned. Cast the computed\n# object as a ee.Geometry to get the geometry's bounds, for instance.\nfeature = ee.Feature(None, {'geom': ee.Geometry(geojson_object)})\nprint('Cast computed geometry objects to ee.Geometry class:',\n ee.Geometry(feature.get('geom')).bounds().getInfo())\n```"]]