Mik378
Mik378

Reputation: 22181

Neo4j / Cypher Query using withinDistance returns 0 rows

I've just set the Neo4j Spatial plugin on my server and I'm using SDN 3.1.2 to create my wkt index:

@Indexed(indexName = "CarsLocation", indexType = IndexType.POINT) var wkt: String

The whole works great and I can make queries involving withinDistance using the HTTP console like this, returning my matched node:

POST /db/data/ext/SpatialPlugin/graphdb/findGeometriesWithinDistance {"layer":"CarsLocation","pointX":48.892501,"pointY":2.373140,"distanceInKm":100.0}

However, I want to query using Cypher like this:

start n = node:CarsLocation("withinDistance:[48.892501,2.373140,100.0]") return n

It just returns 0 rows, no matter the values are.

I came across this post, advising to manually add the Car node to the spatial index: CarsLocation.

So I executed this command:

POST /db/data/index/node/CarsLocation {"value":"dummy","key":"dummy", "uri":"http://localhost:7474/db/data/node/30"}  //30 being the Car node I want to index

but it also doesn't make the cypher query works.

I also try executing Cypher through an http call:

POST /db/data/cypher {"query" : "start n = node:CarsLocation({indexQuery}) return n", "params": {"indexQuery": "withinDistance:[48.892067, 2.373140, 10.0]"}}

Doesn't work either.

However, when I specify a huge amount of kilometers (IMO exceeding the limit), this one passes:

start n = node:CarsLocation("withinDistance:[48.892501,2.373140,10000.0]") return n

(Returning my Car node 30).

Did I miss something important?

I don't figure out where could be the mistake, preventing Cypher query to work.

I'm pointing out I'm using Neo4j 2.1.2.

Upvotes: 0

Views: 288

Answers (1)

Jim Biard
Jim Biard

Reputation: 2272

Mik378,

The problem here is pretty simple. The 'withinDistance' Cypher spatial index query has a quirk (a bug, as far as I'm concerned). You must specify latitude first, then longitude. I'm not familiar with SDN, so I don't know if you also need to do the explicit spatial index creation commands.

Grace and peace,

Jim

Upvotes: 1

Related Questions