Created
January 8, 2014 17:39
-
-
Save danhammer/8320914 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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