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. #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)
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. #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. #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. #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. #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);
}