Hi everybody,
I've played for the first time today with the Neo4j spatial plugin through the ReST API.
I'll describe first the steps I've done, so maybe I've missed something (I'm using a curl wrapper so the code can be obvious but the flow is the same)
1. Create layer:
$spurl = $spatialPlugin->addSimplePointLayer;
$layer = 'test';
$body = json_encode(array('layer' => $layer));
$req = $client->post($spurl);
$req->setBody($body);
$req->setHeader('Content-Type', 'application/json');
$resp = $req->send();
2. Add points to the layer :
$spurl =Â $spatialPlugin->addGeometryWKTToLayer;
$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'));
  $req = $client->post($spurl);
  $req->setBody($body);
  $req->setHeader('Content-Type', 'application/json');
  $resp = $req->send();
}
So far it is good, I can see my 3 nodes in the webadmin, here is the representation of the 3 nodes :
{
"extensions" : {
},
"paged_traverse" : "http://localhost:7474/db/data/node/80/paged/traverse/{returnType}{?pageSize,leaseTime}",
"outgoing_relationships" : "http://localhost:7474/db/data/node/80/relationships/out",
"traverse" : "http://localhost:7474/db/data/node/80/traverse/{returnType}",
"all_typed_relationships" : "http://localhost:7474/db/data/node/80/relationships/all/{-list|&|types}",
"self" : "http://localhost:7474/db/data/node/80",
"property" : "http://localhost:7474/db/data/node/80/properties/{key}",
"all_relationships" : "http://localhost:7474/db/data/node/80/relationships/all",
"properties" : "http://localhost:7474/db/data/node/80/properties",
"outgoing_typed_relationships" : "http://localhost:7474/db/data/node/80/relationships/out/{-list|&|types}",
"incoming_relationships" : "http://localhost:7474/db/data/node/80/relationships/in",
"incoming_typed_relationships" : "http://localhost:7474/db/data/node/80/relationships/in/{-list|&|types}",
"create_relationship" : "http://localhost:7474/db/data/node/80/relationships",
"data" : {
"bbox" : [ 50.727926, 3.196237, 50.727926, 3.196237 ],
"longitude" : 50.727926,
"latitude" : 3.196237,
"gtype" : 1
}
}{
"extensions" : {
},
"paged_traverse" : "http://localhost:7474/db/data/node/81/paged/traverse/{returnType}{?pageSize,leaseTime}",
"outgoing_relationships" : "http://localhost:7474/db/data/node/81/relationships/out",
"traverse" : "http://localhost:7474/db/data/node/81/traverse/{returnType}",
"all_typed_relationships" : "http://localhost:7474/db/data/node/81/relationships/all/{-list|&|types}",
"self" : "http://localhost:7474/db/data/node/81",
"property" : "http://localhost:7474/db/data/node/81/properties/{key}",
"all_relationships" : "http://localhost:7474/db/data/node/81/relationships/all",
"properties" : "http://localhost:7474/db/data/node/81/properties",
"outgoing_typed_relationships" : "http://localhost:7474/db/data/node/81/relationships/out/{-list|&|types}",
"incoming_relationships" : "http://localhost:7474/db/data/node/81/relationships/in",
"incoming_typed_relationships" : "http://localhost:7474/db/data/node/81/relationships/in/{-list|&|types}",
"create_relationship" : "http://localhost:7474/db/data/node/81/relationships",
"data" : {
"bbox" : [ 50.897234, 4.366227, 50.897234, 4.366227 ],
"longitude" : 50.897234,
"latitude" : 4.366227,
"gtype" : 1
}
}{
"extensions" : {
},
"paged_traverse" : "http://localhost:7474/db/data/node/82/paged/traverse/{returnType}{?pageSize,leaseTime}",
"outgoing_relationships" : "http://localhost:7474/db/data/node/82/relationships/out",
"traverse" : "http://localhost:7474/db/data/node/82/traverse/{returnType}",
"all_typed_relationships" : "http://localhost:7474/db/data/node/82/relationships/all/{-list|&|types}",
"self" : "http://localhost:7474/db/data/node/82",
"property" : "http://localhost:7474/db/data/node/82/properties/{key}",
"all_relationships" : "http://localhost:7474/db/data/node/82/relationships/all",
"properties" : "http://localhost:7474/db/data/node/82/properties",
"outgoing_typed_relationships" : "http://localhost:7474/db/data/node/82/relationships/out/{-list|&|types}",
"incoming_relationships" : "http://localhost:7474/db/data/node/82/relationships/in",
"incoming_typed_relationships" : "http://localhost:7474/db/data/node/82/relationships/in/{-list|&|types}",
"create_relationship" : "http://localhost:7474/db/data/node/82/relationships",
"data" : {
"bbox" : [ 48.843028, 2.393891, 48.843028, 2.393891 ],
"longitude" : 48.843028,
"latitude" : 2.393891,
"gtype" : 1
}
Now, I would like to start from one of the 3 nodes and find the closest point to him.
Well, I didn't find anything to do that with the ReST API or a Cypher Query.
Is this possible ?
Thanks,
Christophe