This is the code to go along with the OpenShift blog piece on how to use Flask (python) with MongoDB to create a REST like web service with spatial data
Python Shell
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 31 commits ahead, 2 commits behind thesteve0:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.openshift
data
libs
wsgi
.gitignore
README
README.md
parkcoord.json
setup.py

README.md

openshift-mongo-flask-example

This is the code to go along with the OpenShift blog piece on how to use Flask (python) with MongoDB to create a REST like web service with spatial data Please note that this only works with Python-2.6 cartridge

Running on OpenShift

Create an account at https://www.openshift.com

Create a python application with MongoDB

rhc app create pythonws python-2.6 mongodb-2 --from-code git://github.com/openshift-quickstart/openshift-mongo-flask-example.git

or you can do this

rhc app create pythonws python-2.6 mongodb-2
cd pythonws
git remote add upstream -m master git://github.com/openshift-quickstart/openshift-mongo-flask-example.git
git pull -s recursive -X theirs upstream master
git push

To add the data to the MongoDB instance please follow the instructions on this blog: Mongo Spatial on OpenShift

Now, ssh into the application.

Add the data to a collection called parkpoints:

mongoimport -d pythonws -c parkpoints --type json --file $OPENSHIFT_REPO_DIR/parkcoord.json  -h $OPENSHIFT_MONGODB_DB_HOST  -u admin -p $OPENSHIFT_MONGODB_DB_PASSWORD --port $OPENSHIFT_MONGODB_DB_PORT

Create the spatial index on the documents:

mongo
use pythonws
db.parkpoints.ensureIndex( { pos : "2d" } );

Once the data is imported you can now checkout your application at:

http://pythonws-$yournamespace.rhcloud.com/ws/parks

License

This code is dedicated to the public domain to the maximum extent permitted by applicable law, pursuant to CC0 (http://creativecommons.org/publicdomain/zero/1.0/)