Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Where am I? Django & Location Services

Where am I? Django & Location Services

Slides from my talk at JSPyConf in Istanbul. I talked about Django and different location database and search solutions you can use with it, as well as some visualization and mapping options.

Style and colour theme was totally ripped off from Chris Coyier's (http://chriscoyier.net) excellent slide deck designs with his gracious approval.

5b4c599a7720f8fa3d16370d630afddc?s=128

Taylan Pince

March 30, 2013
Tweet

Transcript

  1. Where am I? Django & Location Services

  2. Taylan Pinçe @taylanpince Tech Lead @

  3. APIs & Web Services

  4. APPS!

  5. Django + Location 1 2 3 4 Technologies Storing Data

    Searching Visualizing
  6. Technologies 1 2 3 geodjango mongoDB elasticsearch

  7. None
  8. geodjango 1 2 3 Easy installation Integrated with Django Support:

    GEOS & GDAL 4 Low performance!
  9. geodjango How to install? sudo apt-get install libgdal1-1.7.0 postgresql-9.1-postgis postgresql-server-dev-9.1

    proj That’s it!
  10. geodjango Model Integration from django.db import models from django.contrib.gis.db import

    models class Restaurant(models.Model): location = models.PointField() objects = models.GeoManager()
  11. geodjango from django.contrib.gis.measure import D Restaurant.objects.filter( location__distance_lte=( point, D(m=radius) )

    ).distance(point)
  12. Where did that point come from?

  13. geodjango GEOS Geometry Engine Open Source

  14. geodjango GEOS from django.contrib.gis.geos import GEOSGeometry, Point point = GEOSGeometry(“POINT(20.391

    46.556)”) point = Point(20.391, 46.556)
  15. geodjango GEOS Point LineString Polygon

  16. If all you have is a hammer, everything looks like

    a nail. - Abraham Maslow
  17. geodjango 1 2 3 Good for complex data Not performance

    oriented 95% simple data is OK 4 Simple queries are enough
  18. None
  19. mongoDB 1 2 3 Hard to install & deploy Only

    simple queries Good performance
  20. mongoDB is web scale ha ha

  21. “It is, if you set it up properly.”

  22. mongoDB app server app server mongoDB config mongoDB config mongoDB

    config mongoDB shard mongoDB replica mongoDB shard mongoDB replica mongoDB shard mongoDB replica Simple Production Deployment
  23. mongoDB Data Insertion with PyMongo db.restaurants.insert({ “name”: “Mano Burger”, “location”:

    { “lat”: 41.029, “lng”: 28.974 } })
  24. mongoDB Search with PyMongo db.restaurants.ensureIndex({ “location”: “2d” }) db.restaurants.find({ “location”:

    { “$within”: { “$centerSphere”: { [[lat, lng], radius], }}}})
  25. mongoDB 1 2 3 Limited to simple data Only simple

    search queries High performance 4 Easy to scale
  26. None
  27. elasticsearch 1 2 3 Easy installation Simple search queries Amazing

    performance 4 Not a database
  28. elasticsearch Installation * openjdk-6-jre-headless * elasticsearch * elasticsearch-servicewrapper sudo elasticsearch

    install sudo elasticsearch start pip install haystack
  29. elasticsearch Haystack Integration from haystack import indexes class RestaurantIndex( indexes.SearchIndex,

    indexes.Indexable): location = indexes.LocationField( model_attr="location" )
  30. elasticsearch Haystack Search from haystack.query import SearchQuerySet SearchQuerySet().dwithin( “location”, Point(longitude,

    latitude), D(m=radius) )
  31. None
  32. elasticsearch app server app server elastic search elastic search elastic

    search Simple Production Deployment Can detect other instances automatically!
  33. elasticsearch 1 2 3 AWS focused deployment haystack Integration Excellent

    performance 4 Scaling is super easy
  34. Visualization 1 2 3 Google Maps Open Layers MapBox

  35. Google Maps

  36. Open Layers

  37. MapBox

  38. Where am I? Demo

  39. Q&A

  40. hipo.biz @hipolabs

  41. Thank you! @taylanpince