NEO4J空間索引

Neo4j空間索引可以對數據進行空間索引,例如在指定區域內以某個感興趣的點作爲起始,搜索指定距離內其它感興趣的點。可以方便地將空間索引的節點數據與已有圖數據結合分析。

1、創建圖層

CALL spatial.addPointLayer('geom')

在這裏插入圖片描述

2、查看已經創建的圖層列表

CALL spatial.layers()

在這裏插入圖片描述

3、建立空間點並將新創建的點加入到geom圖層中

MERGE (n:Node {longitude:15.2,latitude:60.1}) WITH n 
CALL spatial.addNode('geom',n) YIELD node RETURN node

在這裏插入圖片描述

4、查詢維度在60.0到60.2之間,經度在15.0到15.3之間的空間點

CALL spatial.bbox('geom',{longitude:15.0,latitude:60.0},{longitude:15.3,latitude:60.2}) YIELD node RETURN node

在這裏插入圖片描述

5、導入全國公路shp文件

數據下載地址

// 將*.shp,*.dbf,*.shx文件移動到neo4j安裝根目錄下
CALL spatial.addWKTLayer('layer_roads','geometry')
CALL spatial.importShapefileToLayer('layer_roads','roa_4m.shp')

6、查詢一個矩形內的圖形語句

CALL spatial.bbox('layer_roads',{longitude:14.0,latitude:60.0},{longitude:19.3,latitude:81.0}) YIELD node RETURN node.name as name

7、查詢一個多邊形內的點

WITH "POLYGON((15.3 60.0,15.3 62.0,15.2 60.2,15.4 65.0))" as  polygon
CALL spatial.intersects('layer_roads', polygon) YIELD node RETURN node.name as name

8、WithinDistance - 查詢點周邊distance(0.1km)以內的點

CALL spatial.withinDistance('geom',{longitude:15.2,latitude:60.1},0.1) YIELD node RETURN node LIMIT 10

在這裏插入圖片描述

9、批量節點構建空間索引

CALL spatial.addPointLayer('geom')
UNWIND [{name:'a',latitude:60.1,longitude:15.2},{name:'b',latitude:60.3,longitude:15.5}] as point CREATE (n:Node) SET n += point WITH n 
CALL spatial.addNode('geom',n) YIELD node RETURN node.name as name

neo4j-spatial-plugin downloa
neo4j根據經緯度計算兩點之間的距離

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章