SlideShare a Scribd company logo
Geospatial Graphs Made Easy
With
Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016
Luigi Dell’Aquila
Core Developer and Director of Consulting
OrientDB LTD
Twitter: @ldellaquila
http://www.orientdb.com
Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016
Our goal
Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016
Summary
•What is OrientDB
•OrientDB GeoSpatial API
•Importing Geo data (Java and/or Node.js)
•Querying Geo data (OrientDB Studio)
•Displaying Geo data (Angular2, Google Maps)
•Adding Relationships - graph data
•Graph + Spatial queries
Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016
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
Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016
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
Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016
OrientDB GeoSpatial Classes
•OPoint
•OLine
•OPolygon
•OMultiPoint
•OMultiline
•OMultiPlygon
Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016
Data Model
•POI (V)
•Natural (V)
•Person (V)
•FriendOf (E)
Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016
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…
Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016
Create the Schema
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
Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016
Our Data Source (WKT)
WKT,osm_id,name,type
"POINT (14.4641804 50.0972109)",24569342,"Invalidovna, Metro B",station
"POINT (14.4739792 50.1036789)",24569358,"Palmovka, Metro B",station
"POINT (14.4921863 50.1062907)",24569412,"Českomoravská, Metro B",station
Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016
Now let’s import data!
Let’s do it in Java
you can download some Geo files from
http://www.mapcruzin.com/free-italy-arcgis-maps-shapefiles.htm
and convert them to WKT using QGis (www.qgis.org)
Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016
Maven Dependencies
<dependency>

<groupId>org.apache.commons</groupId>

<artifactId>commons-csv</artifactId>

<version>1.2</version>

</dependency>



<dependency>

<groupId>com.orientechnologies</groupId>

<artifactId>orientdb-graphdb</artifactId>

<version>2.2.13</version>

</dependency>
Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016
Read from CSV
Reader reader = new FileReader("/path/to/poi_file.csv");

CSVParser parser = CSVFormat.DEFAULT.parse(reader);

Iterator<CSVRecord> iterator = parser.iterator();

iterator.next(); //discard the header




while(iterator.hasNext()){ //read each row

importRecord(iterator.next()); 

}


Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016
OrientDB connection
Reader reader = new FileReader("/path/to/poi_file.csv");

CSVParser parser = CSVFormat.DEFAULT.parse(reader);

Iterator<CSVRecord> iterator = parser.iterator();

iterator.next(); //discard the header


OrientGraph graph =
new OrientGraph("remote:localhost/testdb", "admin", "admin");

while(iterator.hasNext()){ //read each row

importRecord(iterator.next(), graph);

}


graph.shutdown();
Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016
importRecord()
void importRecord(CSVRecord record, OrientGraph graph) {

String wkt = record.get(0);

String name = record.get(2);

String type = record.get(3);



graph.command(new OCommandSQL(

"insert into Natural " +

"set name = ?, type = ?, " +

"location = ST_GeomFromText(?)"))

.execute(name, type, wkt);

}
Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016
Querying geo data
We are here:
(45.5031135, 9.1554415)
(lat, lon)
Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016
Front-End!
Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016
Clone the scaffolding
> git clone https://github.com/luigidellaquila/geospatial-demo
> cd geospatial-demo
> npm install
(it’s a clone of https://github.com/angular/quickstart)
> npm start
Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016
Clone the scaffolding
> git clone https://github.com/luigidellaquila/geospatial-demo
> 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
Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016
We need Google Maps
<script src=“https://maps.googleapis.com/maps/api/js?key=API_KEY"

async defer></script>
Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016
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>
Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016
Draw the map
drawMap(){

var controller = this;

let mapProp = {

center: new google.maps.LatLng(40.399640, -3.8375544),

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();

});

});

}
Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016
Create a Person
createPerson(): void{

var location = {

// the location object

}



var queryString = ””; // OrientDB statement



this.orient.command(
queryString,
(result) => { /* Success callback */ },
(error) => { /* Error callback */ }
);

}

Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016
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 */ }
);}

Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016
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 */ }
);

}

Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016
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) });

}

Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016
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);

}
Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016
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);

});

}
Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016
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);

}
Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016
Query the
Geospatial Graph
(DEMO)
Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016
Thank you!

More Related Content

PDF
GeeCON Prague 2016 - Geospatial Graphs made easy with OrientDB
PDF
Geospatial Graphs made easy with OrientDB - Luigi Dell'Aquila - Codemotion Mi...
PPTX
OrientDB - Time Series and Event Sequences - Codemotion Milan 2014
PDF
Javantura v3 - Logs – the missing gold mine – Franjo Žilić
PPTX
Connect S3 with Kafka using Akka Streams
PDF
Using akka streams to access s3 objects
PDF
Akka stream and Akka CQRS
PDF
Jena University Talk 2016.03.09 -- SQL at Zalando Technology
GeeCON Prague 2016 - Geospatial Graphs made easy with OrientDB
Geospatial Graphs made easy with OrientDB - Luigi Dell'Aquila - Codemotion Mi...
OrientDB - Time Series and Event Sequences - Codemotion Milan 2014
Javantura v3 - Logs – the missing gold mine – Franjo Žilić
Connect S3 with Kafka using Akka Streams
Using akka streams to access s3 objects
Akka stream and Akka CQRS
Jena University Talk 2016.03.09 -- SQL at Zalando Technology

What's hot (8)

KEY
Nu program language on Shibuya.lisp#5 LT
PDF
OrientDB - the 2nd generation of (Multi-Model) NoSQL - Devoxx Belgium 2015
PDF
Utilising the data attribute
PDF
Codemotion akka persistence, cqrs%2 fes y otras siglas del montón
PDF
Spark Your Legacy (Spark Summit 2016)
PPTX
Big Data processing with Spark, Scala or Java?
PDF
Introduction to interactive data visualisation using R Shiny
PPT
Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Nu program language on Shibuya.lisp#5 LT
OrientDB - the 2nd generation of (Multi-Model) NoSQL - Devoxx Belgium 2015
Utilising the data attribute
Codemotion akka persistence, cqrs%2 fes y otras siglas del montón
Spark Your Legacy (Spark Summit 2016)
Big Data processing with Spark, Scala or Java?
Introduction to interactive data visualisation using R Shiny
Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Ad

Similar to Geospatial Graphs made easy with OrientDB - Codemotion Milan 2016 (20)

PDF
Geospatial Graphs made easy with OrientDB - Codemotion Spain
PDF
Geospatial Graphs made easy with OrientDB - Codemotion Warsaw 2016
PDF
OrientDB - The 2nd generation of (multi-model) NoSQL
PDF
Dove sono i tuoi vertici e di cosa stanno parlando?
PPTX
Getting Started with Geospatial Data in MongoDB
PPTX
Where are yours vertexes and what are they talking about?
PPTX
OrientDB: a Document-Graph Database ready for the Cloud - Dell'Aquila
PPTX
OrientDB Codemotion 2014
PDF
OrientDB - Voxxed Days Berlin 2016
PDF
OrientDB - Voxxed Days Berlin 2016
PDF
OrientDB - the 2nd generation of (Multi-Model) NoSQL - J On The Beach 2016
PDF
Change RelationalDB to GraphDB with OrientDB
PDF
OrientDB - Perché le tue applicazioni meritano un DB Multi-Model
PDF
OrientDB
PDF
Geospatial querying in Apache Marmotta - ApacheCon Big Data Europe 2015
PDF
OrientDB Intro & HTTP REST API Tutorial
PDF
Uber Geo spatial data platform at DataWorks Summit
PDF
Works with persistent graphs using OrientDB
PDF
OrientDB - the 2nd generation of (Multi-Model) NoSQL - Codemotion Warsaw 2016
PPTX
Optimizing Geospatial Operations with Server-side Programming in HBase and Ac...
Geospatial Graphs made easy with OrientDB - Codemotion Spain
Geospatial Graphs made easy with OrientDB - Codemotion Warsaw 2016
OrientDB - The 2nd generation of (multi-model) NoSQL
Dove sono i tuoi vertici e di cosa stanno parlando?
Getting Started with Geospatial Data in MongoDB
Where are yours vertexes and what are they talking about?
OrientDB: a Document-Graph Database ready for the Cloud - Dell'Aquila
OrientDB Codemotion 2014
OrientDB - Voxxed Days Berlin 2016
OrientDB - Voxxed Days Berlin 2016
OrientDB - the 2nd generation of (Multi-Model) NoSQL - J On The Beach 2016
Change RelationalDB to GraphDB with OrientDB
OrientDB - Perché le tue applicazioni meritano un DB Multi-Model
OrientDB
Geospatial querying in Apache Marmotta - ApacheCon Big Data Europe 2015
OrientDB Intro & HTTP REST API Tutorial
Uber Geo spatial data platform at DataWorks Summit
Works with persistent graphs using OrientDB
OrientDB - the 2nd generation of (Multi-Model) NoSQL - Codemotion Warsaw 2016
Optimizing Geospatial Operations with Server-side Programming in HBase and Ac...
Ad

Recently uploaded (20)

PDF
Electronic commerce courselecture one. Pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Big Data Technologies - Introduction.pptx
PDF
KodekX | Application Modernization Development
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Machine learning based COVID-19 study performance prediction
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Empathic Computing: Creating Shared Understanding
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Encapsulation theory and applications.pdf
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPT
Teaching material agriculture food technology
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Electronic commerce courselecture one. Pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
The AUB Centre for AI in Media Proposal.docx
Big Data Technologies - Introduction.pptx
KodekX | Application Modernization Development
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Machine learning based COVID-19 study performance prediction
Dropbox Q2 2025 Financial Results & Investor Presentation
Empathic Computing: Creating Shared Understanding
Chapter 3 Spatial Domain Image Processing.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Mobile App Security Testing_ A Comprehensive Guide.pdf
Network Security Unit 5.pdf for BCA BBA.
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
NewMind AI Monthly Chronicles - July 2025
Encapsulation theory and applications.pdf
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Teaching material agriculture food technology
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf

Geospatial Graphs made easy with OrientDB - Codemotion Milan 2016

  • 2. Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016 Luigi Dell’Aquila Core Developer and Director of Consulting OrientDB LTD Twitter: @ldellaquila http://www.orientdb.com
  • 3. Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016 Our goal
  • 4. Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016 Summary •What is OrientDB •OrientDB GeoSpatial API •Importing Geo data (Java and/or Node.js) •Querying Geo data (OrientDB Studio) •Displaying Geo data (Angular2, Google Maps) •Adding Relationships - graph data •Graph + Spatial queries
  • 5. Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016 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
  • 6. Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016 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
  • 7. Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016 OrientDB GeoSpatial Classes •OPoint •OLine •OPolygon •OMultiPoint •OMultiline •OMultiPlygon
  • 8. Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016 Data Model •POI (V) •Natural (V) •Person (V) •FriendOf (E)
  • 9. Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016 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…
  • 10. Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016 Create the Schema 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
  • 11. Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016 Our Data Source (WKT) WKT,osm_id,name,type "POINT (14.4641804 50.0972109)",24569342,"Invalidovna, Metro B",station "POINT (14.4739792 50.1036789)",24569358,"Palmovka, Metro B",station "POINT (14.4921863 50.1062907)",24569412,"Českomoravská, Metro B",station
  • 12. Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016 Now let’s import data! Let’s do it in Java you can download some Geo files from http://www.mapcruzin.com/free-italy-arcgis-maps-shapefiles.htm and convert them to WKT using QGis (www.qgis.org)
  • 13. Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016 Maven Dependencies <dependency>
 <groupId>org.apache.commons</groupId>
 <artifactId>commons-csv</artifactId>
 <version>1.2</version>
 </dependency>
 
 <dependency>
 <groupId>com.orientechnologies</groupId>
 <artifactId>orientdb-graphdb</artifactId>
 <version>2.2.13</version>
 </dependency>
  • 14. Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016 Read from CSV Reader reader = new FileReader("/path/to/poi_file.csv");
 CSVParser parser = CSVFormat.DEFAULT.parse(reader);
 Iterator<CSVRecord> iterator = parser.iterator();
 iterator.next(); //discard the header 
 
 while(iterator.hasNext()){ //read each row
 importRecord(iterator.next()); 
 } 

  • 15. Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016 OrientDB connection Reader reader = new FileReader("/path/to/poi_file.csv");
 CSVParser parser = CSVFormat.DEFAULT.parse(reader);
 Iterator<CSVRecord> iterator = parser.iterator();
 iterator.next(); //discard the header 
 OrientGraph graph = new OrientGraph("remote:localhost/testdb", "admin", "admin");
 while(iterator.hasNext()){ //read each row
 importRecord(iterator.next(), graph);
 } 
 graph.shutdown();
  • 16. Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016 importRecord() void importRecord(CSVRecord record, OrientGraph graph) {
 String wkt = record.get(0);
 String name = record.get(2);
 String type = record.get(3);
 
 graph.command(new OCommandSQL(
 "insert into Natural " +
 "set name = ?, type = ?, " +
 "location = ST_GeomFromText(?)"))
 .execute(name, type, wkt);
 }
  • 17. Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016 Querying geo data We are here: (45.5031135, 9.1554415) (lat, lon)
  • 18. Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016 Front-End!
  • 19. Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016 Clone the scaffolding > git clone https://github.com/luigidellaquila/geospatial-demo > cd geospatial-demo > npm install (it’s a clone of https://github.com/angular/quickstart) > npm start
  • 20. Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016 Clone the scaffolding > git clone https://github.com/luigidellaquila/geospatial-demo > 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
  • 21. Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016 We need Google Maps <script src=“https://maps.googleapis.com/maps/api/js?key=API_KEY"
 async defer></script>
  • 22. Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016 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>
  • 23. Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016 Draw the map drawMap(){
 var controller = this;
 let mapProp = {
 center: new google.maps.LatLng(40.399640, -3.8375544),
 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();
 });
 });
 }
  • 24. Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016 Create a Person createPerson(): void{
 var location = {
 // the location object
 }
 
 var queryString = ””; // OrientDB statement
 
 this.orient.command( queryString, (result) => { /* Success callback */ }, (error) => { /* Error callback */ } );
 }

  • 25. Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016 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 */ } );}

  • 26. Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016 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 */ } );
 }

  • 27. Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016 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) });
 }

  • 28. Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016 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);
 }
  • 29. Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016 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);
 });
 }
  • 30. Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016 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);
 }
  • 31. Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016 Query the Geospatial Graph (DEMO)
  • 32. Luigi Dell’Aquila @ldellaquila Milan - Nov 25-26 2016 Thank you!