Many thanks for pointing me in the right direction Michael!!! I managed to
solve all my spatial problems yesterday :) As soon as I stopped adding
nodes to the layer all strange exceptions disappeared and I don´t even have
to remove and add the user node to the index to update it as discussed in
question 3. The only thing which didn't work was returning the score from
withinDistance via REST, I get a server 500 error there but I guess I will
just calculate the distance myself, it´s much nicer to keep the cypher
query anyway. Thanks again.
Den måndagen den 31:e mars 2014 kl. 22:30:19 UTC+2 skrev Michael Hunger:
Hi Jenny,
sorry that you have a hard time getting going with Neo4j spatial. Which
version of Neo4j Spatial are you using? We recently released:
0.13-neo4j-2.0.1
Did you see Max' blog post and webinar?
http://maxdemarzi.com/2014/02/11/neo4j-spatial-part-2/ |
https://vimeo.com/89064528
Let me try to answer as good as I can, I also looped in the experts.
You shouldn't need to add your nodes to the layer, adding them to the
index should be good enough.
1) Cypher unfortunately doesn't return the distance, if you use the
REST endpoint for index lookups instead, you should see the distance in
the score field:
http://docs.neo4j.org/chunked/milestone/rest-api-indexes.html#rest-api-find-node-by-queryjust
add a query parameter :
http://localhost:7474/db/data/index/node/geom?query=withinDistance:[
60.0,15.0,100.0]ordering=score
2) In your cypher query you can also filter for labels:
START n=node:geom('withinDistance:[60.0, 15.0, 100.0]') WHERE n:User
RETURN n
You could also use two different geo-indexes to separate the nodes, if
that makes sense.
3) I would want to test that, in general Neo4j (manual) indexes work by
removing a node from the _index_ and then re-adding it. Did you try that?
Otherwise you would very probably get duplicate index entries. But I'm not
sure about that.
4) I think it should be quite easily possible, but don't know it out of my
head (Perhaps Craig can tell).
I could imagine something like this:
// lookup city by user coordinates
START city=node:geom('withinDistance:[60.0, 15.0, 100.0]'), user=node(id)
WHERE city:City
WITH user, city LIMIT 1
SET user.city = city.name
// or
CREATE (user)-[:IN]-(city)
we could either rely on the order returned from the index lookup is by
distance
or use something like haversin in Cypher to compute the distance between
the two (but the current impl is really generic and unfortunately overkill)
http://docs.neo4j.org/chunked/milestone/query-functions-mathematical.html#functions-haversin
Hope that helps a bit,
Michael
On Mon, Mar 31, 2014 at 3:49 PM, Jenny Pettersson
jenny.m.p...@gmail.comjavascript:
wrote:
Hi!
Trying to build a social network app with Neo4j 2.0 but unfortunately the
spatial plugin is giving me a hard time. It's difficult to find
documentation/samples and my trial and error approach is rather frustrating
and time consuming so I would really appreciate clarification to a couple
of questions a lot!
A short simplified description of my domain is that I have Places and
Users which both have the properties lat and lon. I have managed to add a
simple point layer and a spatial index geom to my db. Then I have created
user and place nodes and added them to the index and after that to the
point layer. Using the web interface the nodes and relationships look
correct but I am having problems quering and updating the data:
1. My most common use case is that I want to return nearby users and
places from a users given position. Using cypher and the withinDistance
query START n=node:geom('withinDistance:[60.0, 15.0, 100.0]') RETURN n; I
am only able to get the nearest node even though there are multiple nodes
situated within the given distance. Have I misunderstood that
withinDistance should return all nodes within the given distance ordered by
distance? Is there any way to return the distance metric too? I really
would like to tell UserA that UserB is for example only 200 metres away.
2. Another thing is that I would like to differentiate between the node
type User and Place, is it possible to filter the withinDistance query just
to return my Users för example?
3. My users location will be updated every 10 minutes or so. When I tried
to only update the User nodes lat and lon property I get a
NotFoundException: NODE[28] has no property with propertyKey=\bbox\.}
System.Exception
{Neo4jClient.NeoException} the next time I execute the withinDistance
query. What is the correct way to update a location, should I remove the
node from the point layer and add it again if the lat and lon change and
how do I do that, the manual at http://neo4j.github.io/spatial/ which I
have been following only tells how to add a node to a layer.
4. Another thing I would like to do is set the nearest City for every
logged