我在这里找到了解决方案:http:
//www.markhneedham.com/blog/2013/03/10/neo4jcypher-finding-football-stadiums-near-a-city-using-spatial/
我们只需要将节点添加到空间索引中。节点应该有一个包含坐标信息的wkt属性。添加到此索引的所有节点也将自动添加到空间层。
IndexProviderTest.java 提供了一个更新的实现:
https ://github.com/mneedham/spatial/blob/master/src/test/java/org/neo4j/gis/spatial/IndexProviderTest.java#L251
@Test
public void testWithinDistanceIndex() {
Map<String, String> config = SpatialIndexProvider.SIMPLE_WKT_CONFIG;
IndexManager indexMan = db.index();
Index<Node> index = indexMan.forNodes("layer2", config);
Transaction tx = db.beginTx();
Node batman = db.createNode();
String wktPoint = "POINT(41.14 37.88 )";
batman.setProperty("wkt", wktPoint);
String batman1 = "batman";
batman.setProperty("name", batman1);
index.add(batman, "dummy", "value");
Map<String, Object> params = new HashMap<String, Object>();
Double[] point = {37.87, 41.13};
params.put(LayerNodeIndex.POINT_PARAMETER,
point);
params.put(LayerNodeIndex.DISTANCE_IN_KM_PARAMETER, 2.0);
IndexHits<Node> hits = index.query(
LayerNodeIndex.WITHIN_DISTANCE_QUERY, params);
tx.success();
tx.finish();
Node node = hits.getSingle();
assertTrue(node.getId() == batman.getId());
assertTrue(node.getProperty("name").equals(batman1));
}