0

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.

Community
  • 1
  • 1
Mik378
  • 21,881
  • 15
  • 82
  • 180

1 Answers1

1

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

Jim Biard
  • 2,252
  • 11
  • 14
  • However, I just noticed using your solution, it doesn't return all the node that should match. Using http calls, it returns 4 nodes but using cypher, only 2: `start n = node:CarsLocation("withinDistance:[2.373140, 48.892501, 100.0]") return n` – Mik378 Aug 21 '14 at 17:05
  • What I've just did is to clear the whole database, rename the Location in lower case, and it works with your solution :) – Mik378 Aug 21 '14 at 18:34
  • And clearly no need to add any indexes :) It works "out of the box" – Mik378 Aug 21 '14 at 18:48
  • "You must specify latitude first, then longitude" => it's the reverse actually, 48...is the latitude ;) – Mik378 Apr 30 '15 at 23:19