圖資料庫實踐系列 (三)--Neo4j Spatial的REST整合

來源:互聯網
上載者:User

上講回顧:主要講述Neo4j Spatial項目以及空間資料(向量)的儲存。本文主要介紹Neo4j Spatial與Neo4j Server的整合,以及與GeoServer 的整合。

Noted:與Geoserver的整合方法可行,但是geoserver無法顯示發行集資料庫內的圖層。(系統內容:Ubuntu 12.04,Spatial 0.9,Neo4j 1.8M6,Geoserver 2.1.1)

Neo4J圖資料庫實踐系列

圖資料庫實踐系列 (一)--Neo4J簡介與安裝

圖資料庫實踐系列 (二)--Neo4J空間資料儲存

圖資料庫實踐系列 (三)--Neo4j Spatial的REST整合

 

1.Neo4j Server安裝與配置1.1Neo4j Server 安裝

Neo4j可以安裝成資料庫伺服器,能夠已應用或者系統服務兩種形式運行在作業系統中。它內建了jetty 和REST介面,來實現使用瀏覽器對資料庫操作[17,18]。

  1. 在neo4j官網http://neo4j.org/download下載你喜歡的版本(需要選擇你的作業系統)
  2. 解壓到特定位置,解壓路徑表述為$NEO4J_HOME(如/home/dev/neo4j/)
  3. 啟動指令碼在$NEO4J_HOME/bin 檔案夾下,在Linux/MacOS下,運行 $NEO4J_HOME/bin/neo4j start 在Window 只要雙擊%NEO4J_HOME%\bin\Neo4j.bat檔案即可

我們也可以按照第一講所述,進入源碼安裝的Neo4j的的bin檔案夾($NEO4J_HOME/bin)命令啟動,

cd $NEO4J_HOME/bin/$NEO4J_HOME/bin/neo4j start

我們只需要訪問 http://localhost:7474/webadmin/ 會出現Neo4j 的web 管理介面,1所示:

圖1 Neo4j Server管理介面

在Web 管理介面,我們可以查看資料庫的節點,屬性,關係資訊。還可以通過Http ,Shell 和Germlin三種方式來對圖資料庫做CRUD。如果需要將Neo4j Server 以系統服務的方式運行,可以查閱參考文獻[17]

1.2Neo4j Server 配置參數

如果我們需要對伺服器的後端資料庫效能調優等,可以通過Server的設定檔來瞭解圖資料庫的具體參數。這些重要的參數都儲存在$NEO4J_HOME/conf/neo4j-server.properties檔案內,包括伺服器資料庫在磁碟上的路徑:

org.neo4j.server.database.location=data/graph.db

http 伺服器介面:

org.neo4j.server.database.location=data/graph.db

設定REST資料介面所能夠操縱的資料庫的相對路徑

org.neo4j.server.webadmin.data.uri=/db/data/

等。至於Neo4j的績效參數和日誌參數分別參看$NEO4J_HOME/conf/neo4j.properties,$NEO4J_HOME/conf/logging.properties兩個檔案

2.Neo4j Server與Spatial整合2.1 Neo4j Server的Spatail外掛程式安裝

上講我們通過利用源碼安裝了neo4j spatial ,在/target目錄下會有一個neo4j-spatial-0.9-SNAPSHOT-server-plugin.zip檔案。如果沒有,可以運行以下命令來獲得該檔案:

git clone https://github.com/neo4j/spatial.gitcd ./spatialmvn clean package -DskipTests

將該檔案解壓到,複製所有的jar包到neo4j 的lib檔案夾內,然後重啟neo4j server即可。

2.2 Neo4j Server的空間操作

利用curl[20]工具能夠在命令列中對Neo4j實現空間資料讀寫,包括查詢,圖層建立,點建立等。這些都是以JSON格式以http協議對圖資料庫的操作。

curl http://localhost:7474/db/data/

會返回資料庫的整體資訊,2所示:

圖2 查詢圖資料庫

我們可以看到返回的JSON資料中有"SpatialPlugin"對象,它的屬性包括addEditableLayer,getLayer,addNodeToLayer等。我們通過curl命令來建立名字為'test'等簡單點圖層。

curl -d "layer=test" http://localhost:7474/db/data/ext/SpatialPlugin/graphdb/addSimplePointLayer

3所示:

圖3 添加點圖層

可以看到資料隊形的屬性,包括圖層的類,圖層名稱,幾何編碼類別型,建立時間。然後添加三個Well-Konw text 格式的點

# Creating three points from Well-known text formatcurl -v http://localhost:7474/db/data/ext/SpatialPlugin/graphdb/addGeometryWKTToLayer -H "Content-Type: application/json" -d '{"geometry":"POINT(10 10)", "layer":"test"}'curl -v http://localhost:7474/db/data/ext/SpatialPlugin/graphdb/addGeometryWKTToLayer -H "Content-Type: application/json" -d '{"geometry":"POINT(10 11)", "layer":"test"}'curl -v http://localhost:7474/db/data/ext/SpatialPlugin/graphdb/addGeometryWKTToLayer -H "Content-Type: application/json" -d '{"geometry":"POINT(9 10)", "layer":"test"}'

然後執行一個範圍查詢

curl -v http://localhost:7474/db/data/ext/SpatialPlugin/graphdb/findGeometriesInBBox -H "Content-Type: application/json" -d '{"minx":9.0,"maxx":11.0,"miny":9.0,"maxy":12.0,"layer":"test"}'

返回在邊界內的點為兩個,4所示:

圖4 範圍查詢

  • 1
  • 2
  • 下一頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.