Skip to content

Instantly share code, notes, and snippets.

@robinkraft
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robinkraft/c10fa8ef9f67ff1d84ce to your computer and use it in GitHub Desktop.
Save robinkraft/c10fa8ef9f67ff1d84ce to your computer and use it in GitHub Desktop.
Extracting polygons from GEE
import ee
# based on https://ee-api.appspot.com/cd2e21cd508327c5eb92ce57809f1360
def main():
# speciesData = ee.FeatureCollection(
# 'ft:14QQnwJVRPYXdhb4sRqaDblVRclbMxmew1rQCYig6')
# collection = ee.ImageCollection(
# 'MODIS/MOD13Q1').filterDate('2000-02-24', '2014-07-01')
# mean = collection.mean()
# clipped = mean.clip(speciesData)
# result = clipped.select('NDVI')
# resultIC = ee.ImageCollection(result)
# extractedValues = resultIC.getRegion(speciesData, 100)
# ser = ee.serializer.toJSON(extractedValues)
#serialized = ee.data.getValue({'extractedValues':ee.serializer.toJSON(extractedValues)})
# print ee.data.getValue({"json": ser})
#serialized = ee.Serializer.toJSON(extractedValues)
# print ee.data.getValue({json: serialized})
fc = ee.FeatureCollection([
ee.Feature(
ee.Geometry.Polygon(
[[-109.05, 41], [-109.05, 37], [-102.05, 37], [-102.05, 41]]),
dict(name='Colorado', fill=1)),
ee.Feature(
ee.Geometry.Polygon(
[[-114.05, 37.0], [-109.05, 37.0], [-109.05, 41.0],
[-111.05, 41.0], [-111.05, 42.0], [-114.05, 42.0]]),
dict(name='Utah', fill=2))
])
ser = ee.serializer.toJSON(fc)
data = ee.data.getValue({"json": ser})
print data
s = json.dumps(data['features'][0]['geometry']
open('/tmp/json.json', 'w').write(s)
return data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment