Spatial Plugin : FindClosestPointsTo with the ReST API

52 views
Skip to first unread message

Christophe Willemsen

unread,
Oct 5, 2012, 7:23:53 PM10/5/12
to ne...@googlegroups.com
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

Christophe Willemsen

unread,
Oct 5, 2012, 7:24:54 PM10/5/12
to ne...@googlegroups.com
Oh I forgot, I'm currently on W7 OS, Neo4j 1.8RC1.

Peter Neubauer

unread,
Oct 5, 2012, 9:07:49 PM10/5/12
to ne...@googlegroups.com
Christophe, https://github.com/neo4j/spatial/blob/master/src/test/java/org/neo4j/gis/spatial/SpatialPluginFunctionalTest.java#L66
should do what you want?

Cheers,

/peter neubauer

G: neubauer.peter
S: peter.neubauer
P: +46 704 106975
L: http://www.linkedin.com/in/neubauer
T: @peterneubauer

Neo4j 1.8 GA - http://www.dzone.com/links/neo4j_18_release_fluent_graph_literacy.html
> --
>
>

Christophe Willemsen

unread,
Oct 6, 2012, 3:05:42 AM10/6/12
to ne...@googlegroups.com
Hi Peter,

Yes this did the trick, thanks a lot !

Peter Neubauer

unread,
Oct 7, 2012, 11:22:43 AM10/7/12
to ne...@googlegroups.com
No problem,
feel free to report back progress with a blog or so, so others can learn, too :)

Cheers,

/peter neubauer

G: neubauer.peter
S: peter.neubauer
P: +46 704 106975
L: http://www.linkedin.com/in/neubauer
T: @peterneubauer

Neo4j 1.8 GA - http://www.dzone.com/links/neo4j_18_release_fluent_graph_literacy.html


> --
>
>

Thomas Spahr

unread,
Oct 10, 2012, 7:57:41 AM10/10/12
to <neo4j@googlegroups.com>
Peter,

How do I unsubscribe from the mailing list?

Tom

Sent from my iPad
> --
>
>

Peter Neubauer

unread,
Oct 10, 2012, 8:15:54 AM10/10/12
to ne...@googlegroups.com
Already done.

Cheers,

/peter neubauer

G: neubauer.peter
S: peter.neubauer
P: +46 704 106975
L: http://www.linkedin.com/in/neubauer
T: @peterneubauer

Neo4j 1.8 GA - http://www.dzone.com/links/neo4j_18_release_fluent_graph_literacy.html


> --
>
>
Reply all
Reply to author
Forward
0 new messages