Location Based Services<br />Lalit Kapoor - @idefine<br />Washington, DC<br />Monday, June 27, 2011<br />
MongoDB Is Easy!<br />Document Object Store<br />JSON (BSON)<br />Schema-less<br />Multiple language support (c++ to pytho...
Building Your First Location Aware App<br />Pulse Mobile<br />
Pulse<br />Help people in emergency situations<br />Find the closest hospital<br />Notify important contacts (immediate fa...
LBS w/MongoDB<br />Get or collect some location data (addresses are fine)<br />Store it in mongoDB<br />if data is in tsv/...
Get Some Data<br />Location of Hospitals In The United States<br />Medicare.gov has information about the quality of care ...
Import into MongoDB<br />mongoimport --headerline --type csv --drop --db mongodc --collection hospitals --file Outcome of ...
Geospatial Indexing<br />db.places.ensureIndex({loc:”2d”}); / (compounded indexes):  db.places.ensureIndex( { loc : "2d" ,...
Geospatial Querying<br />geoNeargives you back the distance  (in radians if sphere=true)<br />Results are sorted by dista...
Questions?<br />Lalit Kapoor - @idefine<br />
Upcoming SlideShare
Loading in …5
×

MongoDC - Location Aware Applications w/mongodb

3,541 views

Published on

Published in: Technology, Health & Medicine
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,541
On SlideShare
0
From Embeds
0
Number of Embeds
756
Actions
Shares
0
Downloads
32
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • Today I’m going to be talking about building location aware applications with mongodb
  • If you’re new to mongodb, there are various reasons for why you may want to choose it as your database, but today I’m going to focus on its support for working with geospatial data
  • I was planning on just pulling up the mongo shell and going through some geo commandsBut that would be boring and you’d learn more from the wiki anyway, so I decided to actually build an app that would show case some of mongo’s geo capabilitiesI made a mobile app called Pulse that utilizes the technologies you see on this pageWe will touch up on how each of these is used later on
  • I use to work for a healthcare startup in DC and so I wanted to build something around health that was immediately useful to the end user
  • So, let’s get started with what it takes to build an app like pulse
  • Ok, so back to pulse
  • By geohashing we transform the 2d search problem back into a 1d search problem, which is what B-tree indexes are good at.The geo-index of MongoDB encodes a geohash on top of a standard MongoDB b-tree. Geohashing is a way to divide a coordinate system into hierarchical buckets of grid shape.It basically divides an area in two for every bit and so on.A drawback of geohashing is the wrapping (-180 and 179 are very close for example), this can be solved by doing a grid search after the initial scan. It’s a bit comparable by how google maps loads the map images, it starts with the center of the viewport and then the surrounding areas are downloaded.
  • MongoDC - Location Aware Applications w/mongodb

    1. 1. Location Based Services<br />Lalit Kapoor - @idefine<br />Washington, DC<br />Monday, June 27, 2011<br />
    2. 2. MongoDB Is Easy!<br />Document Object Store<br />JSON (BSON)<br />Schema-less<br />Multiple language support (c++ to python to nodejs)<br />Easy-to-Scale (http://www.mongodb.org/display/DOCS/Production+Deployments)<br />Support for geospatial indexing and queries<br />
    3. 3. Building Your First Location Aware App<br />Pulse Mobile<br />
    4. 4. Pulse<br />Help people in emergency situations<br />Find the closest hospital<br />Notify important contacts (immediate family, friends, primary care physician, etc)<br />Extra features that would make this app rock!<br />Provide real-time updates of your location to hospital and contacts<br />Send pictures to hospital<br />Get ER wait times (this data is available in some states)<br />Notify hospital of important medical information: blood-type, allergies, current medications, EMR, etc (integrate with google health/careverge)<br />Integrate with 3rd party devices (watches, wristbands, etc) that know your vitals such as: blood pressure and heart rate. Transmit to your smart phone and then to hospital and contacts<br />
    5. 5. LBS w/MongoDB<br />Get or collect some location data (addresses are fine)<br />Store it in mongoDB<br />if data is in tsv/csv/json use mongoimport<br />find lat/lng if you don’t already have it<br />use Google’s MAP API to find lat/long if you have an address<br />build a 2d index (lat/lng)<br />db.collection.ensureIndex({field:”2d”});<br />let the geospatial queries begin!<br />
    6. 6. Get Some Data<br />Location of Hospitals In The United States<br />Medicare.gov has information about the quality of care at each hospital - this data also happens to include the address for over 4000 hospitals in the US<br />
    7. 7. Import into MongoDB<br />mongoimport --headerline --type csv --drop --db mongodc --collection hospitals --file Outcome of Care Measures.csv<br />
    8. 8. Geospatial Indexing<br />db.places.ensureIndex({loc:”2d”}); / (compounded indexes): db.places.ensureIndex( { loc : "2d" , category : 1 } );<br />Geohash is calculated and stored in a B-Tree<br />Sharding Capable (as of 1.7.2 - Thanks Mathias - from 10gen)<br />Current Limitations<br />“Doesn’t currently handle wrapping at the poles or at the transition from -180° to +180° longitude, however we detect when a search would wrap and raise an error” (Resolved in 1.9+)<br />Need to use geoNear command instead of $near for now when sharding (see JIRA SERVER-1981) - Proposed for resolution in 2011<br />geoNear not in the pymongoDrivers!<br />Eval Hack - http://permalink.gmane.org/gmane.comp.db.mongodb.user/67 (Thanks smsfail on #mongodb)<br />eval_result = db.eval('db.runCommand( { geoNear : "location" , near :[%s,%s], num : %s } );' % (lat, lon, num))<br />results = eval_result.get('results', [])<br />Do not shard on a geo key - works, but inefficient. See JIRA SERVER-1982.<br />
    9. 9. Geospatial Querying<br />geoNeargives you back the distance  (in radians if sphere=true)<br />Results are sorted by distance away from points<br />$near vs. $nearSphere (1.7.0)<br />$within [box, center, polygon] instead of $near<br />Not sorted by distance<br />More examples and details on the wiki<br />
    10. 10. Questions?<br />Lalit Kapoor - @idefine<br />

    ×