Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Introducing spatial views for location aware applications with couchbase server 4.0: Couchbase Connect 2015

2,652 views

Published on

Couchbase Server’s new spatial views feature is not just there for your geospatial indexes, it can also be used to build multi-dimensional indexes on any number of metrics. Even combined indexes (e.g. number of people living in a geographic region) can be built and queried by using this feature. This talk will explain typical use cases, how to best write your map function, and how to query multi-dimensional views enabling you to write location-aware applications with Couchbase Server 4.0.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Introducing spatial views for location aware applications with couchbase server 4.0: Couchbase Connect 2015

  1. 1. INTRODUCING SPATIAL VIEWS FOR LOCATION AWARE APPLICATIONS WITH COUCHBASE SERVER 4.0 Simon Leigh Solutions Engineer David Maier Principal Solutions Engineer
  2. 2. ©2015 Couchbase Inc. 2 Agenda  A bit of History  Introduction  Typical Use Cases  Technical Overview  Demo
  3. 3. A bit of History
  4. 4. ©2015 Couchbase Inc. 4 A bit of History  Did you know?  Already in 2.x and 3.x  Marked as experimental  Since then  Performance and Stability improvements  GA in 4.0  Further Improvements will follow  Radius, Polygon, …
  5. 5. Introduction Geo- and Spatial Indexes
  6. 6. ©2015 Couchbase Inc. 6 Introduction  Same look and feel as ‘normal’ Views  Map-Function for Indexing  REST for Querying  Spatial: Index and Query on Geo- Data and multi-dimensionally  e.g. the average income of a person in a region where the age of this person is greater than 30
  7. 7. Typical Use Cases
  8. 8. ©2015 Couchbase Inc. 8 Use Cases  Multi Dimensional Analysis  Not necessarily Geo-Data but any numeric data  Query within a Hyper-Cube  Map categories to numbers  e.g.  Income,Age, Education level (Bsc = 4, Msc = 5)  Timestamp, Log-Level
  9. 9. ©2015 Couchbase Inc. 9 Use Cases  Geo-Data  GeoJSON: the “Open Standard”  More complex geometries stored as regions  Bounding-BoxQueries  e.g. all buildings in San Francisco { "type": "LineString", "coordinates": [ [100.0, 0.0], [101.0, 1.0] ] } { "type": "Polygon", "coordinates": [ [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ] ] } { "type": "Point", "coordinates": [100.0, 0.0] }
  10. 10. ©2015 Couchbase Inc. 10 Use Cases  Combined  2 dimensions for Geo-Data  Additional dimensions  e.g. all persons with an age greater than 10 in San Francisco
  11. 11. Technical Overview
  12. 12. ©2015 Couchbase Inc. 12 R-Trees  Regions & Points  Hierarchy “Contains” reflected by aTree structure  Specifics  N-dimensional  Min-max per dimension  Regions can overlap
  13. 13. ©2015 Couchbase Inc. 13 4 Ways to Emit Data - GeoJSON function (doc) { if ( typeof doc.geo !== 'undefined’ ) { var geojson = {}; geojson.type = "Point"; geojson.coordinates = [ doc.geo.lon, doc.geo.lat ]; emit(geojson, doc.name); } } Index on Query Output GeoJSON Rows with the Columns • Id: Original document id • Key: Emitted key • Value: Emitted value • Geometry: Original GeoJSON geometry
  14. 14. ©2015 Couchbase Inc. 14 4 Ways to Emit Data – Flat Array function (doc) { if ( typeof doc.geo !== 'undefined’ ) { var geojson = {}; geojson.coordinates = [ doc.geo.lon, doc.geo.lat ]; emit(geojson.coordinates, doc.name); } } Index on Query Output Array of coordinates/numeric values Rows with the Columns • Id: Original document id • Key: Emitted key • Value: Emitted value
  15. 15. ©2015 Couchbase Inc. 15 4 Ways to Emit Data – Min-Max-Array function (doc) { if ( typeof doc.geo !== 'undefined’ ) { // [x_min, x_max], [y_min, y_max] // x_min == x_max && y_min == y_may  [x_min, y_min] emit([ [doc.geo.lon, doc.geo.lon ], [doc.geo.lat, doc.geo.lat] ], doc.name); } } Index on Query Output Array of min-max- tuples of coordinates/numeric values Rows with the Columns • Id: Original document id • Key: Emitted key • Value: Emitted value
  16. 16. ©2015 Couchbase Inc. 16 4 Ways to Emit Data – Combined function (doc) { if ( typeof doc.geo !== 'undefined' && typeof doc.updated !== 'undefined') { var geojson = {}; geojson.type = "Point"; geojson.coordinates = [ doc.geo.lon, doc.geo.lat ]; var date = Date.parse(doc.updated)/1000; //The GeoJSON should be by convention the first element emit([geojson, date], doc.name); } } Index on Query Output GeoJSON and a flat or min-max array Rows with the Columns • Id: Original document id • Key: Emitted key • Value: Emitted value • Geometry: Original GeoJSON geometry
  17. 17. ©2015 Couchbase Inc. 17 Creation via the UI
  18. 18. ©2015 Couchbase Inc. 18 Querying via REST / Client SDK http://$host/beer- sample/_design/dev_spatials/_spati al/by_region?stale=false&start_ran ge=[- 180,0,0]&end_range=[180,90,null]  start_range  end_range  limit  skip  stale
  19. 19. ©2015 Couchbase Inc. 19 Example Output total_rows 3452 rows id key value geometry boon_rawd_br ewery [[100.509,100.509] ,[13.7783,13.7783]] {"brewery":"Boon Rawd Brewery”} {"type":"Point","co ordinates":[100.50 9,13.7783]}
  20. 20. Demo
  21. 21. ©2015 Couchbase Inc. 21 Demo
  22. 22. Thank you! Q&A

×