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
Pull request Compare This branch is 31 commits ahead, 2 commits behind thesteve0:master.
Latest commit 1b06cdc Dec 2, 2015 @danmcp danmcp Merge pull request #5 from dobbymoodge/fix_setup
Fix for issue #4
Permalink
Failed to load latest commit information.
.openshift V2 cart compatibility Jun 4, 2013
data prepping to move up to github Aug 14, 2012
libs prepping to move up to github Aug 14, 2012
wsgi Bug 966465 Jun 2, 2013
.gitignore Update .gitignore Aug 14, 2012
README Use OpenShift consistently Mar 31, 2014
README.md Fixing urls Apr 7, 2014
parkcoord.json prepping to move up to github Aug 14, 2012
setup.py Fix for issue #4 May 21, 2014

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/)