AI-generated Key Takeaways
-
Earth Engine uses the
Geometry
type to represent vector data, supporting various shapes like points, lines, and polygons, as defined in the GeoJSON specification. -
Geometries can be created interactively with the Code Editor tools or programmatically by providing coordinate lists to
Geometry
constructors. -
LinearRing
geometries are closed shapes where the starting and ending coordinates are the same, unlikeLineString
geometries. -
Multi-part geometries, such as
MultiPoint
orMultiPolygon
, can be broken down into individual geometries using thegeometries()
method.
Earth Engine handles vector data with the Geometry
type. The
GeoJSON spec describes in
detail the type of geometries supported by Earth Engine, including Point
(a list of coordinates in some projection), LineString
(a list of points),
LinearRing
(a closed LineString
), and Polygon
(a
list of LinearRing
s where the first is a shell and subsequent rings are
holes). Earth Engine also supports MultiPoint
, MultiLineString
,
and MultiPolygon
. The GeoJSON GeometryCollection is also supported, although
it has the name MultiGeometry
within Earth Engine.
Creating Geometry objects
You can create geometries interactively using the Code Editor geometry tools. See the
Earth Engine Code Editor page for more
information. To create a Geometry
programmatically, provide the
constructor with the proper list(s) of coordinates. For example:
Code Editor (JavaScript)
var point = ee.Geometry.Point([1.5, 1.5]); var lineString = ee.Geometry.LineString( [[-35, -10], [35, -10], [35, 10], [-35, 10]]); var linearRing = ee.Geometry.LinearRing( [[-35, -10], [35, -10], [35, 10], [-35, 10], [-35, -10]]); var rectangle = ee.Geometry.Rectangle([-40, -20, 40, 20]); var polygon = ee.Geometry.Polygon([ [[-5, 40], [65, 40], [65, 60], [-5, 60], [-5, 60]] ]);
In the previous examples, note that the distinction between a LineString
and a LinearRing
is that the LinearRing
is “closed” by
having the same coordinate at both the start and end of the list.
An individual Geometry
may consist of multiple geometries. To break a
multi-part Geometry
into its constituent geometries, use
geometry.geometries()
. For example:
Code Editor (JavaScript)
// Create a multi-part feature. var multiPoint = ee.Geometry.MultiPoint([[-121.68, 39.91], [-97.38, 40.34]]); // Get the individual geometries as a list. var geometries = multiPoint.geometries(); // Get each individual geometry from the list and print it. var pt1 = geometries.get(0); var pt2 = geometries.get(1); print('Point 1', pt1); print('Point 2', pt2);