-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
62 lines (50 loc) · 1.88 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
import ee
import webapp2
import jinja2
import os
import json
# Authenticate with Earth Engine
EE_ACCOUNT = '[email protected]'
EE_PRIVATE_KEY_FILE = 'privatekey.pem'
EE_CREDENTIALS = ee.ServiceAccountCredentials(EE_ACCOUNT, EE_PRIVATE_KEY_FILE)
ee.Initialize(EE_CREDENTIALS)
JINJA2_ENVIRONMENT = jinja2.Environment(
loader = jinja2.FileSystemLoader(os.path.dirname(__file__)),
autoescape = True,
extensions = ['jinja2.ext.autoescape'])
class MainHandler(webapp2.RequestHandler):
def get(self):
template_values = {
'title': 'Hello from Python!'
}
template = JINJA2_ENVIRONMENT.get_template('index.html')
self.response.out.write(template.render(template_values))
class GetMapHandler(webapp2.RequestHandler):
def get(self):
start_date = '2000-01-01'
end_date = '2000-12-31'
collection = ee.ImageCollection('MODIS/MYD13A1')
reference = collection.filterDate(start_date,end_date).sort('system:time_start').select('EVI')
mymean = ee.Image(reference.mean())
countries = ee.FeatureCollection('ft:1tdSwUL7MVpOauSgRzqVTOwdfy17KDbw-1d9omPw')
country_names = ['Myanmar (Burma)','Thailand','Laos','Vietnam','Cambodia']
mekongCountries = countries.filter(ee.Filter.inList('Country', country_names))
fit = mymean.clip(mekongCountries)
mapid = fit.getMapId({
'min': '-400',
'max': '400',
'bands': ' EVI_mean',
'palette' : '931206,ff1b05,fdff42,4bff0f,0fa713'
})
map_results = {
'eeMapId': mapid['mapid'],
'eeToken': mapid['token']
}
self.response.headers['Content-Type'] = 'application/json'
self.response.out.write(json.dumps(map_results))
# Setup dynamic routing table
app = webapp2.WSGIApplication([
('/getmap', GetMapHandler),
('/', MainHandler)
])