Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#### SETUP
# 1.) Create a simple point layer
curl -X POST -d '{"layer":"geom","lat":"lat","lon":"lon"}' --header "Content-Type:application/json" http://localhost:7474/db/data/ext/SpatialPlugin/graphdb/addSimplePointLayer
# 2.) Add a spatial index
curl -X POST -d '{"name":"geom","config":{"provider":"spatial","geometry_type":"point","lat":"lat","lon":"lon"}}' --header "Content-Type:application/json" http://localhost:7474/db/data/index/node/
# 3.) Create a sample node with lat and lon data (you can change the name of the properties in step 2)
curl -v -X POST -d '{"query":"CREATE (n {name:\"Strandbar Hermann 2\",lon:16.385539770126344,lat:48.21198395790515}) RETURN n;"}' --header "Content-Type:application/json" http://localhost:7474/db/data/cypher
# 4.) Add this node to the previously created "geom" index (step 2)
# This should be done by an auto indexer:
curl -X POST -d '{"key":"name","value":"Strandbar Hermann 2","uri":"http://localhost:7575/db/data/node/5"}' --header "Content-Type:application/json" http://localhost:7474/db/data/index/node/geom
# 5.) Add the node to the PointLayer (This is not necessary. Adding it to the spatial index will handle this too)
#curl -X POST -d '{"layer":"geom","node":"http://localhost:7575/db/data/node/5"}' --header "Content-Type:application/json" http://localhost:7474/db/data/ext/SpatialPlugin/graphdb/addNodeToLayer
# 6.) Get nodes within distance via REST API
curl -v -X POST -d '{"layer":"geom","pointX":16.3,"pointY":48.2,"distanceInKm":100.0}' --header "Content-Type:application/json" http://localhost:7474/db/data/ext/SpatialPlugin/graphdb/findGeometriesWithinDistance
## Returns the "Strandbar Hermann" node
# 7.) Get nodes within Distance via cypher
curl -X POST -d "{\"query\":\"START node=node:geom('withinDistance:[48.2,16.3,100.0]') return node\"}" --header "Content-Type:application/json" http://lcalhost:7474/db/data/cypher
## Returns the "Strandbar Hermann" node

There's an error in step 4)

For me it was node/4 and needs to be 7474

curl -X POST -d '{"key":"name","value":"Strandbar Hermann 2","uri":"http://localhost:7474/db/data/node/4"}' --header "Content-Type:application/json" http://localhost:7474/db/data/index/node/geom

Thanks for posting ! I too would like to index directly from cypher

Have you found a solution to this issue? besides manually hitting the rest api to add to index?

jspenc72 commented May 3, 2015

With this query, I am getting this error and i cannot figure out what is the cause. Any help would be appreciated.

curl -X POST -d "{"query":"START node=node:geom('withinDistance:[48.2,16.3,100.0]') return node"}" --header "Content-Type:application/json" http://localhost:7474/db/data/cypher

"message" : "org.apache.lucene.queryParser.ParseException: Cannot parse 'withinDistance:[48.2,16.3,100.0]': Encountered " "]" "] "" at line 1, column 31.\nWas expecting one of:\n "TO" ...\n <RANGEIN_QUOTED> ...\n <RANGEIN_GOOP> ...\n ",
"exception" : "RuntimeException",
"fullname" : "java.lang.RuntimeException",

when i used cypher query

node=node:geom('withinDistance:[48.2,16.3,100.0]') return node

it returned error "Index 'geom' does not exists"

but when i used this

{"layer":"geom","pointX":16.3,"pointY":48.2,"distanceInKm":100.0}' --header "Content-Type:application/json" http://localhost:7474/db/data/ext/SpatialPlugin/graphdb/findGeometriesWithinDistance

it works but i want to add order by and limit for this query and in this request i can't
anyone can help me?
thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment