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.
Geospatial Graphs made easy
with
#OrientDB - @ldellaquila
Luigi Dell’Aquila
Core Developer and Director of Consulting
OrientDB LTD
Twitter: @ldellaquila
ht...
#OrientDB - @ldellaquila
Summary
• Getting started with OrientDB
• OrientDB GeoSpatial API
• Importing Geo data (Node.js)
...
#OrientDB - @ldellaquila
What is OrientDB
• Multi-Model Database (Document, Graph and more)
• Tables Classes
• Extended SQ...
#OrientDB - @ldellaquila
Install
• http://www.orientdb.com/download/
• http://central.maven.org/maven2/com/orientechnologi...
#OrientDB - @ldellaquila
OrientDB GeoSpatial Classes
• OPoint
• OLine
• OPolygon
• OMultiPoint
• OMultiline
• OMultiPlygon
#OrientDB - @ldellaquila
OrientDB GeoSpatial Functions
• ST_GeomFromText(text)
• ST_Equals(geom, geom)
• ST_Contains(geom,...
#OrientDB - @ldellaquila
Our goal
#OrientDB - @ldellaquila
Our Data Model
CREATE CLASS POI EXTENDS V
CREATE PROPERTY POI.location EMBEDDED OPoint
CREATE IND...
#OrientDB - @ldellaquila
Now let’s import data!
> npm init
> npm install orientjs
> npm install fast-csv
> touch index.js
...
#OrientDB - @ldellaquila
Dependencies
var fs = require("fs")

var ODatabase = require("orientjs").ODatabase

var csv = req...
#OrientDB - @ldellaquila
Read from CSV
var stream = fs.createReadStream("data/poland-poi.csv");



var csvStream = csv.par...
#OrientDB - @ldellaquila
DB connection
var db = new ODatabase({

host: "localhost",

port: 2424,

username: "admin",

pass...
#OrientDB - @ldellaquila
Insert
var insertElement = function(data){

db.insert().into(className).set(

{

name: data.name,...
#OrientDB - @ldellaquila
Is it done?
Not yet :-(
Node.js… asynchronous… promises…
Final version:
https://github.com/luigid...
#OrientDB - @ldellaquila
Querying geo data
We are here:
(52.231807953759706, 21.013154983520508)
(lat, lon)
#OrientDB - @ldellaquila
Front-End!
#OrientDB - @ldellaquila
Clone the scaffolding
> git clone https://github.com/luigidellaquila/geospatial-demo
> git checko...
#OrientDB - @ldellaquila
Clone the scaffolding
> git clone https://github.com/luigidellaquila/geospatial-demo
> git checko...
#OrientDB - @ldellaquila
We need Google Maps
<script src=“https://maps.googleapis.com/maps/api/js?key=API_KEY"

async defe...
#OrientDB - @ldellaquila
Let’s display a map (app.html)
<div class=“container">

<div class="row">

<div class="col-md-12"...
#OrientDB - @ldellaquila
Draw the map
drawMap(){

var controller = this;

let mapProp = {

center: new google.maps.LatLng(...
#OrientDB - @ldellaquila
Create a Person
createPerson(): void{

var location = {

// the location object

}



var querySt...
#OrientDB - @ldellaquila
Create a Person
createPerson(): void{

var location = {

"@class": "OPoint",

coordinates: [this....
#OrientDB - @ldellaquila
Create a Person
createPerson(): void{

var location = {

"@class": "OPoint",

coordinates: [this....
#OrientDB - @ldellaquila
Create a Person
createPerson(): void{

var location = {

"@class": "OPoint",

coordinates: [this....
#OrientDB - @ldellaquila
Add Person Vertex to Orient via REST API
command(statement: string, success: (data: any) => void,...
#OrientDB - @ldellaquila
Add Person to the Map
addPersonToMap(personData:any){

let location = personData.location;

let c...
#OrientDB - @ldellaquila
Add an edge between people
(FriendOf)
createEdge(from:any, to:any): void{

this.orient.command(

...
#OrientDB - @ldellaquila
Query the
Geospatial Graph
(DEMO)
#OrientDB - @ldellaquila
Thank you!
You’ve finished this document.
Download and read it offline.
Upcoming SlideShare
Fully Reactive - from Data to UI with OrientDB + Node.js + Socket.io - Luigi Dell'Aquila - Codemotion Rome 2015
Next
Upcoming SlideShare
Fully Reactive - from Data to UI with OrientDB + Node.js + Socket.io - Luigi Dell'Aquila - Codemotion Rome 2015
Next
Download to read offline and view in fullscreen.

Share

Geospatial Graphs made easy with OrientDB - Codemotion Warsaw 2016

Download to read offline

How to configure OrientDB to manage geospatial data, implement a Node.js importer and an Angular2+GoogleMaps frontend

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

Geospatial Graphs made easy with OrientDB - Codemotion Warsaw 2016

  1. 1. Geospatial Graphs made easy with
  2. 2. #OrientDB - @ldellaquila Luigi Dell’Aquila Core Developer and Director of Consulting OrientDB LTD Twitter: @ldellaquila http://www.orientdb.com
  3. 3. #OrientDB - @ldellaquila Summary • Getting started with OrientDB • OrientDB GeoSpatial API • Importing Geo data (Node.js) • Querying Geo data (OrientDB Studio) • Displaying Geo data (Angular2, Google Maps) • Adding Relationships - graph data • Graph + Spatial queries
  4. 4. #OrientDB - @ldellaquila What is OrientDB • Multi-Model Database (Document, Graph and more) • Tables Classes • Extended SQL • JOIN Physical Pointers • Schema, No-Schema, Hybrid • HTTP + Binary protocols • Stand-alone or Embedded • Distributed Multi-Master • Apache 2 license
  5. 5. #OrientDB - @ldellaquila Install • http://www.orientdb.com/download/ • http://central.maven.org/maven2/com/orientechnologies/ orientdb-spatial/VERSION/orientdb-spatial-VERSION-dist.jar > cd orientdb-community/bin/ > ./server.sh
  6. 6. #OrientDB - @ldellaquila OrientDB GeoSpatial Classes • OPoint • OLine • OPolygon • OMultiPoint • OMultiline • OMultiPlygon
  7. 7. #OrientDB - @ldellaquila OrientDB GeoSpatial Functions • ST_GeomFromText(text) • ST_Equals(geom, geom) • ST_Contains(geom, geom) • ST_Disjoint(geom, geom) • ST_Intersects(geom, geom) • ST_Distance_Sphere(geom, geom) • and more…
  8. 8. #OrientDB - @ldellaquila Our goal
  9. 9. #OrientDB - @ldellaquila Our Data Model CREATE CLASS POI EXTENDS V CREATE PROPERTY POI.location EMBEDDED OPoint CREATE INDEX POI.location on POI(location) SPATIAL ENGINE LUCENE CREATE CLASS Natural EXTENDS V CREATE PROPERTY Natural.location EMBEDDED OPolygon CREATE INDEX Natural.location on Natural(location) SPATIAL ENGINE LUCENE CREATE CLASS Person EXTENDS V CREATE PROPERTY Person.location EMBEDDED OPoint CREATE CLASS FriendOf EXTENDS E
  10. 10. #OrientDB - @ldellaquila Now let’s import data! > npm init > npm install orientjs > npm install fast-csv > touch index.js import files http://www.mapcruzin.com/free-poland-maps.htm (convert to WKT using QGis)
  11. 11. #OrientDB - @ldellaquila Dependencies var fs = require("fs")
 var ODatabase = require("orientjs").ODatabase
 var csv = require("fast-csv")
  12. 12. #OrientDB - @ldellaquila Read from CSV var stream = fs.createReadStream("data/poland-poi.csv");
 
 var csvStream = csv.parse({headers: true})
 .on("data", function(data){
 console.log(data)
 })
 .on("end", function(){
 console.log("Done!")
 });
 
 stream.pipe(csvStream); 

  13. 13. #OrientDB - @ldellaquila DB connection var db = new ODatabase({
 host: "localhost",
 port: 2424,
 username: "admin",
 password: "admin",
 name: "geo"
 }) db.open().then(function(){
 } 

  14. 14. #OrientDB - @ldellaquila Insert var insertElement = function(data){
 db.insert().into(className).set(
 {
 name: data.name,
 type: data.type,
 location: db.rawExpression("ST_GeomFromText('"+data.WKT+"')")
 }
 ).one().then(function(){})
 } 

  15. 15. #OrientDB - @ldellaquila Is it done? Not yet :-( Node.js… asynchronous… promises… Final version: https://github.com/luigidellaquila/wkt-to-orient
  16. 16. #OrientDB - @ldellaquila Querying geo data We are here: (52.231807953759706, 21.013154983520508) (lat, lon)
  17. 17. #OrientDB - @ldellaquila Front-End!
  18. 18. #OrientDB - @ldellaquila Clone the scaffolding > git clone https://github.com/luigidellaquila/geospatial-demo > git checkout warsaw_demo_step0 > cd geospatial-demo > npm install (it’s a clone of https://github.com/angular/quickstart) > npm start
  19. 19. #OrientDB - @ldellaquila Clone the scaffolding > git clone https://github.com/luigidellaquila/geospatial-demo > git checkout warsaw_demo_step0 > cd geospatial-demo > npm install (it’s a clone of https://github.com/angular/quickstart) > npm start > cd <orientdb-home>/www > ln -s <quickstart-path> > tsc -w
  20. 20. #OrientDB - @ldellaquila We need Google Maps <script src=“https://maps.googleapis.com/maps/api/js?key=API_KEY"
 async defer></script>
  21. 21. #OrientDB - @ldellaquila Let’s display a map (app.html) <div class=“container">
 <div class="row">
 <div class="col-md-12" id="map" style=“height:600px"></div>
 </div>
 </div>
  22. 22. #OrientDB - @ldellaquila Draw the map drawMap(){
 var controller = this;
 let mapProp = {
 center: new google.maps.LatLng(52.231807953759706, 21.013154983520508),
 zoom: 16,
 mapTypeId: google.maps.MapTypeId.ROADMAP
 };
 
 controller.map = new google.maps.Map(document.getElementById("map"), mapProp);
 controller.map.addListener("click", function(point: any){
 controller.zone.run(()=> {
 controller.lat = point.latLng.lat();
 controller.lon = point.latLng.lng();
 });
 });
 }
  23. 23. #OrientDB - @ldellaquila Create a Person createPerson(): void{
 var location = {
 // the location object
 }
 
 var queryString = ””; // OrientDB statement
 
 this.orient.command( queryString, (result) => { /* Success callback */ }, (error) => { /* Error callback */ } );
 }

  24. 24. #OrientDB - @ldellaquila Create a Person createPerson(): void{
 var location = {
 "@class": "OPoint",
 coordinates: [this.lon, this.lat]
 }
 
 var queryString = ””; // OrientDB statement
 
 this.orient.command( queryString, (result) => { /* Success callback */ }, (error) => { /* Error callback */ } );}

  25. 25. #OrientDB - @ldellaquila Create a Person createPerson(): void{
 var location = {
 "@class": "OPoint",
 coordinates: [this.lon, this.lat]
 }
 
 var queryString = `insert into Person 
 set name = '${this.personName}', 
 location = ${JSON.stringify(location)}`;
 
 this.orient.command( queryString, (result) => { /* Success callback */ }, (error) => { /* Error callback */ } );
 }

  26. 26. #OrientDB - @ldellaquila Create a Person createPerson(): void{
 var location = {
 "@class": "OPoint",
 coordinates: [this.lon, this.lat]
 }
 
 var queryString = `insert into Person 
 set name = '${this.personName}', 
 location = ${JSON.stringify(location)}`;
 
 this.orient.command( queryString, (res) => {
 let body = res.json();
 let person = body.result[0];
 this.addPersonToMap(person)
 }, (e) => { console.log(e) });
 }

  27. 27. #OrientDB - @ldellaquila Add Person Vertex to Orient via REST API command(statement: string, success: (data: any) => void, error: (err: any) => void): void{
 var url = this.url + "sql/-/-1" 
 var headers = new Headers();
 headers.append("Authorization", "Basic " + btoa(this.username+":"+this.password));
 
 this.http.post( // HTTP POST
 url, // the URL
 JSON.stringify({
 "command": statement // the SQL command
 }),
 {headers: headers} // the authentication data
 ).toPromise()
 .then(success)
 .catch(error);
 }
  28. 28. #OrientDB - @ldellaquila Add Person to the Map addPersonToMap(personData:any){
 let location = personData.location;
 let coordinates = location.coordinates;
 let controller = this;
 let marker = new google.maps.Marker({
 position: {lat:coordinates[1], lng:coordinates[0]},
 map: this.map,
 title: personData.name,
 rid: personData["@rid"]
 });
 google.maps.event.addListener(marker, 'click', function() {
 controller.onMarkerClick(marker);
 });
 }
  29. 29. #OrientDB - @ldellaquila Add an edge between people (FriendOf) createEdge(from:any, to:any): void{
 this.orient.command(
 `create edge FriendOf from ${from.rid} to ${to.rid}`,
 (x)=>{console.log(x)},
 (x)=>{console.log(x)}
 )
 this.addEdgeBetweenMarkersToMap(from, to);
 }
  30. 30. #OrientDB - @ldellaquila Query the Geospatial Graph (DEMO)
  31. 31. #OrientDB - @ldellaquila Thank you!
  • kennethowino9

    May. 25, 2019
  • claunet1

    Oct. 3, 2016
  • robfrankie

    Oct. 2, 2016
  • molodchik

    Sep. 16, 2016
  • lvca

    Sep. 15, 2016
  • dongwq

    Sep. 15, 2016

How to configure OrientDB to manage geospatial data, implement a Node.js importer and an Angular2+GoogleMaps frontend

Views

Total views

773

On Slideshare

0

From embeds

0

Number of embeds

50

Actions

Downloads

14

Shares

0

Comments

0

Likes

6

×