11# neo4j-rtree
2- 一个用于neo4j的空间索引
2+ a spatial index for neo4j 4.x.
33
4- ## 这个项目能干什么
4+ [ README ] ( README.md ) | [ 中文文档 ] ( README_zh.md )
55
6- 新建空间索引
6+ ## What can it do
7+
8+ create a spatial index
79~~~ java
810RTreeIndex rTreeIndex = RTreeIndexManager . createIndex(db, " index1" , " geometry" , 64 );
911~~~
1012
1113
12- 简洁地为node加入空间索引:
14+ add node(s) to spatial index
1315~~~ java
1416Transaction tx = db. beginTx();
15- Node node = tx. createNode(testLabel);// 新建节点
17+ Node node = tx. createNode(testLabel);// create node
1618Point geo = wkbReader. read(" POINT(10 20)" );
17- byte [] wkb = wkbWriter. write(geo);// 转为wkb
18- node. setProperty(" geometry" , wkb);// 设置空间字段值,必须为wkb格式
19- rTreeIndex. add(node,tx);// 加入索引(效率起见,多个node的话用list add,详见测试用例 )
19+ byte [] wkb = wkbWriter. write(geo);// to wkb
20+ node. setProperty(" geometry" , wkb);// set the property of the spatial field
21+ rTreeIndex. add(node,tx);// add to spatial index(if you have many vertices, add as list for efficiency )
2022
2123~~~
2224
23- 空间查询
25+ spatial query
2426~~~ java
25- // 输入一个矩形范围,查询矩形覆盖的节点
27+ // Enter a rectangle and query the node covered by the rectangle
2628double [] bbox = new double []{3 , 1 , 8 , 9 };
2729try (Transaction tx = db. beginTx()) {
2830 RtreeQuery . queryByBbox(tx, rTreeIndex, bbox, (node, geometry) - > {
@@ -32,7 +34,7 @@ try (Transaction tx = db.beginTx()) {
3234~~~
3335
3436~~~ java
35- // 输入一个geometry,查询geometry覆盖的节点
37+ // Input an geometry, query the node covered by the geometry
3638Geometry inputGeo = new WKTReader (). read(" POLYGON ((11 24, 22 28, 29 15, 11 24))" );
3739try (Transaction tx = db. beginTx()) {
3840 RtreeQuery . queryByGeometryIntersects(tx, rTreeIndex, inputGeo, (node, geometry) - > {
@@ -41,17 +43,17 @@ try (Transaction tx = db.beginTx()) {
4143}
4244~~~
4345
44- 最邻近搜索
46+ nearest neighbor search
4547~~~ java
46- // 查询距离点 (10.2, 13.2)最近的5个node
48+ // Query the 5 nodes closest to point (10.2, 13.2)
4749try (Transaction tx = db. beginTx()) {
4850 List<DistanceResult > res = RtreeNearestQuery . queryNearestN(tx, rTreeIndex, 10.2 , 13.2 , 5 , (node, geometry) - > true );
4951 System . out. println(res);
5052}
5153
5254~~~
5355~~~ java
54- // 查询满足约束条件且距离点 (10.2, 13.2)最近的5个node
56+ // Query the 5 nodes closest to point (10.2, 13.2) with filter
5557try (Transaction tx = db. beginTx()) {
5658 List<DistanceResult > res = RtreeNearestQuery . queryNearestN(tx, rTreeIndex, 10.2 , 13.2 , 5 , (node, geometry) - > geometry. getCoordinate(). x< 10 );
5759 System . out. println(res);// DistanceResult里包含了node、距离以及geometry,详见测试用例
@@ -71,7 +73,7 @@ maven import in your project
7173 <version>1.2</version>
7274</dependency>
7375```
74- 注意,maven中央库的依赖用jdk11编译,所以如果你的项目使用了jdk8,你需要自己编译一份适合于你的jdk的 :
76+ Maven central repository build by jdk11,So if you use jdk8,you must build yourself :
7577
7678clone & install
7779
@@ -82,13 +84,14 @@ mvn clean install -DskipTests
8284```
8385
8486
85- ## 关于本项目
86- 本项目源码中的org .wowtools.neo4j.rtree.spatial包取自开源项目Neo4j Spatial(https://github.com/neo4j-contrib/spatial )
87+ ## about this project
88+ In this project source, package org .wowtools.neo4j.rtree.spatial is based on from project "Neo4j Spatial" (https://github.com/neo4j-contrib/spatial )
8789
88- 截至本项目首次push起, Neo4j Spatial已经有16个月未更新, Neo4j 4.0的发布,大量的api重写导致Neo4j Spatial已不可用,
89- 所以我抽取了Neo4j Spatial中的空间索引部分并适配至Neo4j 4.0。
90+ but " Neo4j Spatial" has not been updated for 16 months. With the release of Neo4j 4.0, "Neo4j Spatial" has become unavailable due to a large number of API rewriting.
91+ Therefore, I extracted the Spatial index part in the Neo4j Spatial and adapted it to Neo4j 4.0.
9092
91- 同时,去掉了原项目中的osm、shp解析等内容,旨在使项目更精简,这个项目的理念是精简与解耦,你可以独立或集成使用geotools等工具来实现shp等文件的导入,而非与neo4j捆绑在一起。
93+ At the same time, OSM, SHP parsing and other contents in the original project were removed to make the project more streamlined.
94+ The idea of this project is to simplify and decouple, and you can use tools such as GeoTools to import files such as SHP independently or integrated with Neo4j, instead of being bundled with Neo4J.
9295
93- org.wowtools.neo4j.rtree.nearest包则是取自开源项目PRTree (https://github.com/EngineHub/PRTree )
94- ,基于分支限界法的最邻近搜索
96+ package org.wowtools.neo4j.rtree.nearest is based on project PRTree (https://github.com/EngineHub/PRTree )
97+ , the nearest neighbor search based on the branch limit method
0 commit comments