Created
June 20, 2013 14:28
-
-
Save mneedham/5823205 to your computer and use it in GitHub Desktop.
neo4j spatial withinDistance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Test | |
| public void testEpic() { | |
| Map<String, String> config = SpatialIndexProvider.SIMPLE_POINT_CONFIG; | |
| IndexManager indexMan = db.index(); | |
| Index<Node> index = indexMan.forNodes("geom", config); | |
| Transaction tx = db.beginTx(); | |
| Node n1 = db.createNode(); | |
| n1.setProperty("lat", 60.1); | |
| n1.setProperty("lon", 15.2); | |
| index.add(n1, "dummy", "value"); | |
| ExecutionEngine engine = new ExecutionEngine(db); | |
| ExecutionResult result = engine.execute("start n=node:geom('withinDistance:[60.0, 15.0, 100.0]') return n"); | |
| System.out.println("cypher = " + result.dumpToString()); | |
| } | |
| @Test | |
| @Documented | |
| public void find_geometries_within__distance_using_cypher() throws Exception | |
| { | |
| data.get(); | |
| String response = post(Status.OK,"{\"layer\":\"geom\", \"lat\":\"lat\", \"lon\":\"lon\"}", ENDPOINT + "/graphdb/addSimplePointLayer"); | |
| response = post(Status.CREATED,"{\"name\":\"geom\", \"config\":{\"provider\":\"spatial\", \"geometry_type\":\"point\",\"lat\":\"lat\",\"lon\":\"lon\"}}", "http://localhost:"+PORT+"/db/data/index/node/"); | |
| response = post(Status.CREATED,"{\"lat\":60.1, \"lon\":15.2}", "http://localhost:"+PORT+"/db/data/node"); | |
| int nodeId = getNodeId(response); | |
| response = post(Status.OK,"{\"layer\":\"geom\", \"node\":\"http://localhost:"+PORT+"/db/data/node/"+nodeId+"\"}", ENDPOINT + "/graphdb/addNodeToLayer"); | |
| response = post(Status.OK,"{\"query\":\"start node = node:geom(\'withinDistance:[60.0,15.0, 100.0]\') return node\"}", "http://localhost:"+PORT+"/db/data/cypher"); | |
| System.out.println("nodeId = " + response); | |
| assertTrue(response.contains( "node" )); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment