Google Earth Engine/App Engine Hello World example

Hello World (Hard)

This is the example we are going to implement here.
Hello World (Hard)
If you are intimidated by "Hard", try this easy version first,
Hello World (Easy) then come back to here when you feel ready

1. Get the code

Hello World (Hard)

2. Find and read the README.txt file CAREFULLY!

Read everything carefully BEFORE you start doing anything! NOTE: the dependencies are listed at the bottom of the README file.
You need to take care of those first! (That tripped me up!)

    cd ~/Downloads/earthengine-api-c66a3384c26e/python/examples/AppEngine/hello_world
    vi README.txt
    
Let's deal with the dependencies together:

Installation of Dependencies



oauth2client

    hg clone https://code.google.com/p/google-api-python-client/
    cp -r google-api-python-client/oauth2client ~/Downloads/earthengine-api-c66a3384c26e/python/examples/AppEngine/hello_world/


Earth Engine API (if not already installed)
* follow the instructions at:
Earth Engine API

     cp -r ee ~/Downloads/earthengine-api-c66a3384c26e/python/examples/AppEngine/hello_world/


httplib2

     hg clone https://code.google.com/p/httplib2/
     cp -r httplib2/python2/httplib2 ~/Downloads/earthengine-api-c66a3384c26e/python/examples/AppEngine/hello_world/


pycrypto (even if already installed installed)
* download from https://www.dlitz.net/software/pycrypto/

     cd pycryopto
     python setup.py build
     sudo python setup.py install


3. Download the Google App Engine SDK (this will also download the appcfg.py file)

App Engine Launcher

4. Set your Python paths

Make sure that the app_engine libraries are in your python path.
In the .bashrc (linux)/.bash_profile(OSX) that is located in your home directory:

      export PYTHONPATH=/usr/local/google_appengine/:/usr/local/google_appengine/lib/:/usr/local/google_appengine/lib/yaml/:$PYTHONPATH
Make sure to source the script to set the environment variable.
source ~/.bashrc

5. Create a project at the console

Console
The id generated is the one you need to add to the app.yaml file as “application”

6A. Launching with SDK in local environment

Make sure the correct python version is used by Launcher
Go to Launcher preferences Set python path to the desired python version (>=2.7). In my case it is /opt/local/bin/python2.7
/opt/local/bin/python2.7
!!!!PRESS ENTER -- otherwise the choice will be ignored, this is a bug in the GUI!!
Now upload your app into the launcher:
File --> Add Existing Application
Press the green Run button (piciture here)
Check the Logs for errors and if none encountered
Press the Browse button

OR

6B. Launching from command-line in local environment

Run the appfcg.py command like this. The appcfg.py script is part of google_appengine so can be found under the google_appengine install directory (in my case: /usr/local/google_appengine/appcfg.py)

Add the path to appfcg.py to your PYTHONPATH

    export PYTHONPATH=[your-old-python-path]:/usr/local/google_appengine:$PYTHONPATH
    

    cd ~/Downloads/earthengine-api-c66a3384c26e/python/examples/AppEngine
    python appcfg.py update hello_world/
NOTE: user your google mail address (not your EE account email!) and the this email addresses password on prompt.

OR

pre-assign your email address like this:

    python appcfg.py —email=bdaudert@gmail.com  update hello_world/
    
And enter password

7A. Deploying on appspot.com with SDK

In your config file, modified the last 4 lines:


    #EE_CREDENTIALS = AppAssertionCredentials(ee.OAUTH2_SCOPE)
    # Change the above line to the below to use your private credentials in
    # an App Engine instance.
    EE_CREDENTIALS = ee.ServiceAccountCredentials(EE_ACCOUNT, EE_PRIVATE_KEY_FILE)
    
Click on the "Deploy" button in the top right corner of the SDK GUI
Go to .appspot.com to view and run your application.



OR

7B. Deploying on appspot.com from command line


    appcfg.py update hello_world/
    
View your app at
http://your-app-id.appspot.com