Skip to content

Instantly share code, notes, and snippets.

@danhammer
Created January 8, 2014 17:39
Show Gist options
  • Save danhammer/8320914 to your computer and use it in GitHub Desktop.
Save danhammer/8320914 to your computer and use it in GitHub Desktop.
def formatPolygon(coords):
"""Accepts a set of coordinates, in sequence, and checks that they
are formatted counter-clockwise; returns an Earth Engine polygon.
Works for non-convex polygons."""
def _edger(c0, c1):
# anonymous function to generate the edge value between
# coordinate tuples `c0` and `c1`
x0, y0 = c0
x1, y1 = c1
return (x1 - x0) * (y1 + y0)
coord_seq = range(0, len(coords)-1)
coll = [_edger(coords[i], coords[i+1]) for i in coord_seq]
if sum(coll) > 0:
coords = list(reversed(coords))
# return an Earth Engine polygon
return ee.Feature.Polygon(coords)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment