Announcement: All noncommercial projects registered to use Earth Engine before April 15, 2025 must verify noncommercial eligibility to maintain Earth Engine access.
Stay organized with collections
Save and categorize content based on your preferences.
Earth Engine supports a wide variety of operations on Geometry objects.
These include operations on individual geometries such as computing a buffer,
centroid, bounding box, perimeter, convex hull, etc. For example:
Observe from the previous example that the buffer distance is specified in meters.
Supported geometric operations also include relational computations between geometries
such as intersection, union, difference, distance, contains, etc. To test some of these
relations, geometries use the “even-odd” rule by default. By the even-odd rule, a point
is inside the polygon if a line from that point to some point known to be outside the
polygon crosses an odd number of other edges. The inside of a polygon is everything
inside the shell and not inside a hole. As a simple example, a point within a circular
polygon must cross exactly one edge to escape the polygon. Geometries can optionally use
the "left-inside" rule, if necessary. Imagine walking the points of a ring in the order
given; the inside will be on the left.
To demonstrate the difference between geometries created with the "left-inside" rule
(evenOdd: false) and those created with the "even-odd" rule,
the following example compares a point to two different polygons:
The previous example demonstrates how the order of coordinates provided to the
Polygon constructor affects the result when a left-inside polygon is
constructed. Specifically, the point is outside the left-inside polygon but inside the
even-odd polygon.
The following example computes and visualizes derived geometries based on the relationship
between two polygons:
In these examples, note that that maxError parameter is set to one meter for
the geometry operations. The maxError is the maximum allowable error, in
meters, from transformations (such as projection or reprojection) that may alter the
geometry. If one of the geometries is in a different projection from the other, Earth
Engine will do the computation in a spherical coordinate system, with a projection
precision given by maxError. You can also specify a specific projection in
which to do the computation, if necessary.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-10-06 UTC."],[[["\u003cp\u003eEarth Engine provides numerous geometric operations, including buffer, centroid, bounding box calculations, and more, all measured in meters.\u003c/p\u003e\n"],["\u003cp\u003eGeometries utilize the "even-odd" rule for relational computations like intersection and union, but this can be changed to the "left-inside" rule if needed.\u003c/p\u003e\n"],["\u003cp\u003eThe order of coordinates influences results for left-inside polygons, affecting point containment compared to even-odd polygons.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003emaxError\u003c/code\u003e is used in geometric operations to account for potential errors from projections, ensuring accurate calculations.\u003c/p\u003e\n"]]],["Earth Engine performs various operations on `Geometry` objects, including computing a buffer, centroid, or bounding box. Geometries can use \"even-odd\" or \"left-inside\" rules to define whether a point is within. The `contains` operator checks for point inclusion. The code demonstrates the intersection, union, difference, and symmetric difference operations between two polygons. The `maxError` parameter sets the maximum allowable error in meters for geometry transformations and allows to perform operations between different projections.\n"],null,["# Geometric Operations\n\nEarth Engine supports a wide variety of operations on `Geometry` objects.\nThese include operations on individual geometries such as computing a buffer,\ncentroid, bounding box, perimeter, convex hull, etc. For example:\n\n### Code Editor (JavaScript)\n\n```javascript\n// Create a geodesic polygon.\nvar polygon = ee.Geometry.Polygon([\n [[-5, 40], [65, 40], [65, 60], [-5, 60], [-5, 60]]\n]);\n\n// Compute a buffer of the polygon.\nvar buffer = polygon.buffer(1000000);\n\n// Compute the centroid of the polygon.\nvar centroid = polygon.centroid();\nMap.addLayer(buffer, {}, 'buffer');\nMap.addLayer(centroid, {}, 'centroid');\n```\n\nObserve from the previous example that the buffer distance is specified in meters.\n\nSupported geometric operations also include relational computations between geometries\nsuch as intersection, union, difference, distance, contains, etc. To test some of these\nrelations, geometries use the \"even-odd\" rule by default. By the even-odd rule, a point\nis inside the polygon if a line from that point to some point known to be outside the\npolygon crosses an odd number of other edges. The inside of a polygon is everything\ninside the shell and not inside a hole. As a simple example, a point within a circular\npolygon must cross exactly one edge to escape the polygon. Geometries can optionally use\nthe \"left-inside\" rule, if necessary. Imagine walking the points of a ring in the order\ngiven; the inside will be on the left.\n\nTo demonstrate the difference between geometries created with the \"left-inside\" rule\n(`evenOdd: `**false**) and those created with the \"even-odd\" rule,\nthe following example compares a point to two different polygons:\n\n### Code Editor (JavaScript)\n\n```javascript\n// Create a left-inside polygon.\nvar holePoly = ee.Geometry.Polygon({\n coords: [\n [[-35, -10], [-35, 10], [35, 10], [35, -10], [-35, -10]]\n ],\n evenOdd: false\n});\n\n// Create an even-odd version of the polygon.\nvar evenOddPoly = ee.Geometry({\n geoJson: holePoly,\n evenOdd: true\n});\n\n// Create a point to test the insideness of the polygon.\nvar pt = ee.Geometry.Point([1.5, 1.5]);\n\n// Check insideness with a contains operator.\nprint(holePoly.contains(pt)); // false\nprint(evenOddPoly.contains(pt)); // true\n```\n\nThe previous example demonstrates how the order of coordinates provided to the\n`Polygon` constructor affects the result when a left-inside polygon is\nconstructed. Specifically, the point is outside the left-inside polygon but inside the\neven-odd polygon.\n\nThe following example computes and visualizes derived geometries based on the relationship\nbetween two polygons:\n\n### Code Editor (JavaScript)\n\n```javascript\n// Create two circular geometries.\nvar poly1 = ee.Geometry.Point([-50, 30]).buffer(1e6);\nvar poly2 = ee.Geometry.Point([-40, 30]).buffer(1e6);\n\n// Display polygon 1 in red and polygon 2 in blue.\nMap.setCenter(-45, 30);\nMap.addLayer(poly1, {color: 'FF0000'}, 'poly1');\nMap.addLayer(poly2, {color: '0000FF'}, 'poly2');\n\n// Compute the intersection, display it in green.\nvar intersection = poly1.intersection(poly2, ee.ErrorMargin(1));\nMap.addLayer(intersection, {color: '00FF00'}, 'intersection');\n\n// Compute the union, display it in magenta.\nvar union = poly1.union(poly2, ee.ErrorMargin(1));\nMap.addLayer(union, {color: 'FF00FF'}, 'union');\n\n// Compute the difference, display in yellow.\nvar diff1 = poly1.difference(poly2, ee.ErrorMargin(1));\nMap.addLayer(diff1, {color: 'FFFF00'}, 'diff1');\n\n// Compute symmetric difference, display in black.\nvar symDiff = poly1.symmetricDifference(poly2, ee.ErrorMargin(1));\nMap.addLayer(symDiff, {color: '000000'}, 'symmetric difference');\n```\n\nIn these examples, note that that `maxError` parameter is set to one meter for\nthe geometry operations. The `maxError` is the maximum allowable error, in\nmeters, from transformations (such as projection or reprojection) that may alter the\ngeometry. If one of the geometries is in a different projection from the other, Earth\nEngine will do the computation in a spherical coordinate system, with a projection\nprecision given by `maxError`. You can also specify a specific projection in\nwhich to do the computation, if necessary."]]