Geo-Indexing w/MongoDB

3,205 views

Published on

building location aware applications using mongodb, django, html5, phonegap

Published in: Technology, Business
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,205
On SlideShare
0
From Embeds
0
Number of Embeds
35
Actions
Shares
0
Downloads
60
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Geo-Indexing w/MongoDB

    1. 1. Location Based ServicesLalit Kapoor - @idefine
    2. 2. MongoDB is EasyDocument Object StoreJSON (BSON)Schema-lessMultiple language support (c++ to python to nodejs)Easy-to-Scale (http://www.mongodb.org/display/DOCS/Production+Deployments)
    3. 3. LBS w/MongoDBGet or collect some location data (addresses are fine)Store it in mongoDB if data is in tsv/csv/json use mongoimportfind lat/long use Google’s MAP API to find lat/longbuild a 2d index (lat/long) db.collection.ensureIndex({field:”2d”});let the geospatial queries begin!
    4. 4. Building Your First LocationAware App
    5. 5. PulseHelp people in emergency situationsFind the closest hospitalNotify important contacts (immediate family, friends, primary care physician, etc)Provide real-time updates of your location to hospital and contactsExtra features that would make this app rock! Send pictures to hospital Get ER wait times Notify hospital of important medical information: blood-type, allergies, current medications, EMR, etc (integrate with google health/careverge) 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
    6. 6. Get Some DataLocation of Hospitals In The United StatesMedicare.gov has information about the quality of careat each hospital - this data also happens to include
    7. 7. Import into MongoDBmongoimport --headerline --type csv --drop --dbmongodc --collection hospitals --file Outcome of Care Measures.csv
    8. 8. Geospatial Indexingdb.places.ensureIndex({loc:”2d”}); / (compounded indexes): db.places.ensureIndex( { loc : "2d" ,category : 1 } );Geohash is calculated and stored in a B-TreeSharding Capable (as of 1.7.2 - Thanks Mathias - from 10gen)Current Limitations “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” “$within can be used instead of $near to find items within a shape. At the moment, $box (rectangles) and $center (circles) are supported.” Need to use geoNear command instead of $near for now when sharding (see JIRA SERVER-1981) - Proposed for resolution in 2011 geoNear not in the pymongo Drivers! Eval Hack - http://permalink.gmane.org/gmane.comp.db.mongodb.user/67 (Thanks smsfail on #mongodb) eval_result = db.eval(db.runCommand( { geoNear : "location" , near :[%s,%s], num : %s } ); % (lat, lon, num)) results = eval_result.get(results, []) Do not shard on a geo key - works, but inefficient. See JIRA SERVER-1982.
    9. 9. Geospatial QueriesgeoNear (gives you back the distance :-) )$near vs. $nearSphere (1.7.0)db.hospitals.find({"loc": {"$nearSphere":[38.890389,-77.084144]}})$within [box,center]Results are sorted by distance away from points

    ×