adding nodes to spatial layer in c# using REST /neo4jclient

330 views Asked by At

I am making a locations based application in c#, and I am using neo4j and neo4j spatial plugin to handle it. for communication with spatial plugin, I have to use its REST API as there is currently no support for it in neo4jClient. now I want to add all the nodes (with location data ie lat, lon) to spatial layer, for which I need all the neo4j node Ids, my qusestion is there any way to get the node id of previously inserted nodes through it's data(in this case, its lat/lon), or is there any better approch to add nodes to spatial layer?

EDIT: I'm also using neo4jClient for other insertion and retrievals

1

There are 1 answers

0
Lin-Daiyu On

First of all, there isn't an other approach than adding the nodes to a spatial by their IDs.

You can write a Cypher-query that retrieves all the node Ids by using the function has(n.Property), e.g.:

// cypher-query to retrieve node Ids
client.Cypher
   .Match("(n:SpatialIndex)")
   .Where("has(n.lat)")
   .AndWhere("has(n.lon)")
   .Return(node => node.Id());

// add existing node to SimplePoint-Layer
public void AddNodeToLayer(long nodeId, string layer)
{
    string URINode = string.Format("{0}node/{1}",_client.BaseUrl, nodeId);
    string json = string.Format("{{\"layer\":\"{0}\", \"node\":\"{1}\"}}", layer, URINode);

    string URIAdd = string.Format("{0}ext/SpatialPlugin/graphdb/addNodeToLayer", _client.BaseUrl);
    HTTPCommand(new Uri(URIAdd), json);
 }

Acutally there was an other REST-endpoint: addMultipleNodesToLayer. But seems like it wasn't pushed yet. I already asked about that and hope that it will be availible soon.