introducing spatial views for location aware applications with couchbase server 4.0: couchbase...

22
INTRODUCING SPATIAL VIEWS FOR LOCATION AWARE APPLICATIONS WITH COUCHBASE SERVER 4.0 Simon Leigh Solutions Engineer David Maier Principal Solutions Engineer

Upload: couchbase

Post on 15-Aug-2015

206 views

Category:

Technology


1 download

TRANSCRIPT

INTRODUCING SPATIAL VIEWS FOR LOCATION AWARE APPLICATIONS WITH COUCHBASE SERVER 4.0

Simon LeighSolutions Engineer

David MaierPrincipal Solutions Engineer

©2015 Couchbase Inc. 2

Agenda

A bit of History Introduction Typical Use Cases Technical Overview Demo

A bit of History

©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, …

IntroductionGeo- and Spatial Indexes

©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

Typical Use Cases

©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

©2015 Couchbase Inc. 9

Use Cases

Geo-Data GeoJSON: the “Open Standard” More complex geometries stored as

regions Bounding-Box Queries 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] }

©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

Technical Overview

©2015 Couchbase Inc. 12

R-Trees

Regions & Points Hierarchy “Contains”

reflected by a Tree structure

Specifics N-dimensional Min-max per dimension Regions can overlap

©2015 Couchbase Inc. 13

4 Ways to Emit Data - GeoJSONfunction (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

©2015 Couchbase Inc. 14

4 Ways to Emit Data – Flat Arrayfunction (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

©2015 Couchbase Inc. 15

4 Ways to Emit Data – Min-Max-Arrayfunction (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

©2015 Couchbase Inc. 16

4 Ways to Emit Data – Combinedfunction (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

©2015 Couchbase Inc. 17

Creation via the UI

©2015 Couchbase Inc. 18

Querying via REST / Client SDK

http://$host/beer-sample/_design/dev_spatials/_spatial/by_region?stale=false&start_range=[-180,0,0]&end_range=[180,90,null]

start_range end_range limit skip stale

©2015 Couchbase Inc. 19

Example Output

total_rows

3452

rows

id key value geometry

boon_rawd_brewery

[[100.509,100.509],[13.7783,13.7783]]

{"brewery":"Boon Rawd Brewery”}

{"type":"Point","coordinates":[100.509,13.7783]}

Demo

©2015 Couchbase Inc. 21

Demo

Thank you!Q&A