22
© COPYRIGHT 2016 MARKLOGIC CORPORATION. ALL RIGHTS RESERVED. Geospatial Applications created using JavaScript (and NoSQL) Tamas Piros (@tpiros | me.tamas.io)

Geospatial applications created using java script(and nosql)

Embed Size (px)

Citation preview

© COPYRIGHT 2016 MARKLOGIC CORPORATION. ALL RIGHTS RESERVED.

Geospatial Applications created using JavaScript (and NoSQL)Tamas Piros (@tpiros | me.tamas.io)

SLIDE: 2

© COPYRIGHT 2016 MARKLOGIC CORPORATION. ALL RIGHTS RESERVED.

Agenda

▪ What is full stack JavaScript and why should you care?▪ What is geospatial data?▪ How is this related to NoSQL and databases?

▪ JSON data▪ Server Side JavaScript▪ Node.js

▪ Demo

SLIDE: 3

© COPYRIGHT 2016 MARKLOGIC CORPORATION. ALL RIGHTS RESERVED.

JavaScript is eating the world

SLIDE: 4

© COPYRIGHT 2016 MARKLOGIC CORPORATION. ALL RIGHTS RESERVED.

And if you need more convincing

SLIDE: 5

© COPYRIGHT 2016 MARKLOGIC CORPORATION. ALL RIGHTS RESERVED.

A bit more on JavaScript

▪ JavaScript has been around, it is here now and will be here for a while (whether you like it / use it or not)

▪ Ruling the browser since ‘95

<html> <body> <script src="jquery.js"></script> <script> $.ajax({ url: "/items" }).done(function(html) { $("#results").append(html); }); </script> </body></html>

AJAX & jQuery era

● Asynchronous requests to websites● Page updates & data loads, without the need to reload the site● First real step towards interactive websites

SLIDE: 7

© COPYRIGHT 2016 MARKLOGIC CORPORATION. ALL RIGHTS RESERVED.

The evolution of JS frameworks / libraries

▪ And a ‘few’ frameworks and libraries followed

▪ AngularJS▪ Ember▪ Knockout▪ React▪ Backbone▪ Dojo▪ ExtJS▪ D3.js▪ Velocity▪ etc etc etc

var http = require('http');

var server = http.createServer(function(request, response) { response.writeHead(200, { 'Content-type': 'text/plain' }); response.write('hello node'); response.end();});

server.listen(8080);

JavaScript at the server-side

● Ubiquity in the browser had trickled down the stack● You can run JavaScript at the server-side● It’s fast - asynchronous & non-blocking

SLIDE: 9

© COPYRIGHT 2016 MARKLOGIC CORPORATION. ALL RIGHTS RESERVED.

The future of JavaScript

▪ JavaScript has a prosperous future ES6/2015 and ES7/2016▪ classes▪ arrow functions▪ string templates▪ promises▪ object destructuring▪ array includes▪ async functions▪ rest parameters

SLIDE: 10

© COPYRIGHT 2016 MARKLOGIC CORPORATION. ALL RIGHTS RESERVED.

Geospatial data- data represents geographical information which can include site locations (as

well as vectors and raster data)

- (site) locations are made up of (geospatial) points

- (geospatial) points can be placed on a coordinate system and they consist of a pair of latitude and longitude values

SLIDE: 11

© COPYRIGHT 2016 MARKLOGIC CORPORATION. ALL RIGHTS RESERVED.

Geospatial data

Munich: (+) 48.1351° N, (+) 11.5820° ESydney: (-) 33.8600° S, (+) 151.2094° E

SLIDE: 12

© COPYRIGHT 2016 MARKLOGIC CORPORATION. ALL RIGHTS RESERVED.

Exif dataExchangeable image file format (standard)- metadata about

images (and sounds)

- make, model, orientation, exposure time, creation date, focal length, …

- with location services on: GPS data

Let’s put all this together

SLIDE: 14

© COPYRIGHT 2016 MARKLOGIC CORPORATION. ALL RIGHTS RESERVED.

Application Architecture

User Interface● Data views● User workflow● Browser

Middle-tier● Business rules● Application logic

JSON over HTTP

Pros● Same language throughout the stack● Lightweight data format● Data format ‘natively’ understood by

JavaScript

Con(s)● Missing persistent data storage

SLIDE: 15

© COPYRIGHT 2016 MARKLOGIC CORPORATION. ALL RIGHTS RESERVED.

Application Architecture

User Interface● Data views● User workflow● Browser

Middle-tier● Business rules● Application logic

JSON over HTTP

Wouldn’t it be nice to add a database to this architecture that can:

● store JSON documents natively (along with XML, binary and RDF)?

● allow you to construct queries using JavaScript?

● have ACID properties instead of eventual consistency?

● Give you all the indexes you need and allow you to execute search out of the box?

● Apply role based, document level security?

● Execute SPARQL queries?● Manage the database via REST API

calls?

SLIDE: 16

© COPYRIGHT 2016 MARKLOGIC CORPORATION. ALL RIGHTS RESERVED.

Application Architecture

User Interface● Data views● User workflow● Browser

Middle-tier● Business rules● Application logic

JSON over HTTP

MarkLogic can:

● store JSON documents natively (along with XML, binary and RDF)

● allow you to construct queries using JavaScript

● have ACID properties instead of eventual consistency

● Give you all the indexes you need and allow you to execute search out of the box

● Apply role based, document level security

● Execute SPARQL queries● Manage the database via REST API

calls

JSON/XML over HTTP

Database-tier● Persistent storage

SLIDE: 17

© COPYRIGHT 2016 MARKLOGIC CORPORATION. ALL RIGHTS RESERVED.

- support for WGS84 coordinate system as well as raw coordinate system

- support for geospatial queries, indexes and shapes- points, (complex) polygons, circles, boxes

- support for Well-Known Text (WKT) and Well-Known Binary (WKB) representation of geospatial data- point, linestring, triangle, multipoint, multilinestring, multipolygon,

geometrycollection

Geospatial data in MarkLogic

var latitude = 10.3910;var longitude = -75.4794;var miles = function(distance) { return distance * 1.60934 };

cts.search(cts.jsonPropertyChildGeospatialQuery('location', 'coordinates', cts.circle(miles(5), cts.point(latitude, longitude))));

Server-side JavaScript in MarkLogic

● Runs on Google’s V8 engine (JavaScript compiler)● Allows you to execute JavaScript code close to your data (“stored procedures”)

○ both native JavaScript (including some ES2015) and proprietary JavaScript

var marklogic = require('marklogic');var db = marklogic.createDatabaseClient(connection);

var qb = marklogic.queryBuilder;db.documents.query( qb.where( qb.geospatial( qb.geoProperty( qb.property('location'), qb.property('coordinates')), qb.circle(10, 10.3910, -75.4794) ) )).result().then(function(response) { console.log(response);});

Node.js Client API● Registered npm package● Focus on application

features rather than plumbing:○ read/write (bulk), patch

(updates), queries, projections, extensions, alerting, semantics …

● Supports all geospatial query types

Demo

SLIDE: 21

© COPYRIGHT 2016 MARKLOGIC CORPORATION. ALL RIGHTS RESERVED.

Resources- Get the database for free!- GeoPhoto (GitHub)- Samplestack (GitHub)- Character Search v1 (GitHub)- Character Search v2 (GitHub)- MarkLogic Java API (GitHub)- MarkLogic Node.js API (GitHub)- How is MarkLogic different from MongoDB? (Article)- Free Training- More on MarkLogic’s Node.js API (free training)

SLIDE: 22

© COPYRIGHT 2016 MARKLOGIC CORPORATION. ALL RIGHTS RESERVED.

Danke schön!