cypher - Update to: Adding node to Neo4j Spatial Index -


i'm hoping can provide updated clarification on adding nodes spatial. best instructions can find is:

neo4j spatial 'withindistance' cypher query returns empty while rest call returns data

however it's 2 years old , has contradictory information acknowledged bug (https://github.com/neo4j-contrib/spatial/issues/106), appears still open.

i found tutorial:

http://mattbanderson.com/setting-up-the-neo4j-spatial-extension/

which says should add node layer , insert neo4j id# node property, not insert node geom index.

my main priority here able query via cypher (within browser) want able query via rest well. so, ideally i'd insert nodes in such way can both.

so, questions are:

1) correct steps here allow querying via both rest , cypher?

2) if call /addsimplepointlayer , /index/node add spatial index (both via curl or rest), can use load csv insert nodes , able query spatial plugin via both rest , cypher?

3) if using rest insert nodes, calls (and in order) need make in order ensure can query via both rest , cypher (web browser)?

thanks, i'm looking forward getting worked out!!

question 1

you first need initialize once layer , create spatial index using rest calls:

post /db/data/ext/spatialplugin/graphdb/addsimplepointlayer http/1.1 host: localhost:7474 accept: application/json content-type: application/json cache-control: no-cache  {      "layer" : "geom",      "lat" : "lat",      "lon" : "lon"  } 

and:

post /db/data/index/node/ http/1.1 host: localhost:7474 accept: application/json content-type: application/json cache-control: no-cache  {      "name" : "geom",      "config" : {          "provider" : "spatial",          "geometry_type" : "point",          "lat" : "lat",          "lon" : "lon"      }  } 

create node lon/lat properties using cypher via transactional endpoint:

post /db/data/transaction/commit http/1.1 host: localhost:7474 accept: application/json content-type: application/json cache-control: no-cache  {   "statements" : [    {     "statement" : "create (city:city {data}) return id(city)",     "parameters" : {       "data" : {         "name" : "mytown",         "lon": 15.2,         "lat": 60.1       }     }   }    ] } 

and add spatial index - sure adopt node id id of node returned previous request:

post /db/data/ext/spatialplugin/graphdb/addnodetolayer http/1.1 host: localhost:7474 accept: application/json content-type: application/json cache-control: no-cache  {      "layer": "geom",      "node": "http://localhost:7474/db/data/node/<my_nodeid_goes_here>"  } 

in order enable spatial play nice cypher hack required: every geo-indexed node should carry property called id value of node id. can accomplished simple cypher statement (the example below city nodes):

post /db/data/transaction/commit http/1.1 host: localhost:7474 accept: application/json content-type: application/json cache-control: no-cache  {      "statements" : [          { "statement" : "match (n:city) set n.id=id(n)" }      ]  } 

with in place can use cypher geo queries, e.g.:

post /db/data/transaction/commit http/1.1 host: localhost:7474 accept: application/json content-type: application/json cache-control: no-cache  {   "statements" : [    {     "statement" : "start city = node:geom('withindistance:[60.1,15.2, 100.0]') return city",     "parameters" : {}   }    ] } 

nb: withindistance have specify lat,lon, distanceinkm.

question 2

as described above need have separate rest call adding node spatial index. not possible cypher directly. workaround use load csv create nodes lon/lat properties. in preprocessing step run statement match (n:city) not has(n.id) set n.id = id(n) return id(n) id. set id properties (the hack described above) , returns list of ids of new nodes. each of them emit rest call add node geo index.

question 3

has been answered above :-)


Popular posts from this blog