Skip to content

Instantly share code, notes, and snippets.

@ikwattro
Created October 6, 2012 07:03
Show Gist options
  • Save ikwattro/3844259 to your computer and use it in GitHub Desktop.
Save ikwattro/3844259 to your computer and use it in GitHub Desktop.
Neo4j Spatial Tests
<?php
require_once('./vendor/autoload.php');
use Kwattro\Neo4jClient;
$bclient = new Neo4jClient();
$client = $bclient->getClient();
$request = $client->get('/db/data');
$response = $request->send();
$api = json_decode($response->getBody(true));
echo '<pre>';
print_r($api);
$spatialPlugin = $api->extensions->SpatialPlugin;
$request = $client->post($spatialPlugin->getLayer);
$request->setHeader('Content-Type', 'application/json');
$body = json_encode(array('layer' => 'test'));
$request->setBody($body);
$response = $request->send();
$layer = json_decode($response->getBody(true));
print_r($layer);
$request = $client->get($layer[0]->outgoing_relationships);
$response = $request->send();
$points = json_decode($response->getBody(true));
print_r($points);
foreach($points as $position){
if($position->type == 'GEOMETRIES' || $position->type == 'RTREE_ROOT'){
$node = $position->end;
$split = explode('http://localhost:7474', $node);
$nodeurl = $split[1];
$req = $client->get($nodeurl);
$resp = $req->send();
print_r($resp->getBody(true));
}
}
/**
$query = 'start n=node:test(\'withinDistance:[44.44, 33.32, 5.0]\') return n';
$q = json_encode(array('query' => $query));
$cy = $api->cypher;
$split = explode('http://localhost:7474', $cy);
$cypher = $split[1];
$request = $client->post($cypher);
$request->setBody($q);
$request->setHeader('Content-Type', 'application/json');
$response = $request->send();
print_r($response->getBody(true));
**/
/**
* Retrieve points within distance ordered from closest to farest
*/
$bruges = array(
'layer' => 'test',
'distanceInKm' => 150,
'pointX' => '50.883326',
'pointY' => '4.706217'
);
$body = json_encode($bruges);
$url = $api->extensions->SpatialPlugin;
$split = explode('http://localhost:7474', $url->findGeometriesWithinDistance);
$cypher = $split[1];
$request = $client->post($cypher);
$request->setBody($body);
$request->setHeader('Content-Type', 'application/json');
$response = $request->send();
print_r($response->getBody(true));
/**
* Add points to layer
*
$mouscron = 'POINT(50.727926 3.196237)';
$bruxelles = 'POINT(50.897234 4.366227)';
$paris = 'POINT(48.843028 2.393891)';
$locations = array($mouscron, $bruxelles, $paris);
foreach($locations as $point){
$body = json_encode(array('geometry' => $point, 'layer' => 'test'));
$split = explode('http://localhost:7474', $spatialPlugin->addGeometryWKTToLayer);
$spurl = $split[1];
if(!$spurl){
exit();
}
$req = $client->post($spurl);
$req->setBody($body);
$req->setHeader('Content-Type', 'application/json');
$resp = $req->send();
}
*
**/
/**
* Créer le layer
*
$split = explode('http://localhost:7474', $spatialPlugin->addSimplePointLayer);
$spurl = $split[1];
print_r($spurl);
if(!$spurl){
exit();
}
$layer = 'test';
$body = json_encode(array('layer' => $layer));
$req = $client->post($spurl);
$req->setBody($body);
$req->setHeader('Content-Type', 'application/json');
$resp = $req->send();
print_r($resp->getBody(true));
**/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment