Graph database practice series (iii) -- REST integration of Neo4j Spatial

Source: Internet
Author: User
Tags neo4j

Last Review: This article mainly describes the Neo4j Spatial project and space data (vector) storage. This article describes how to integrate Neo4j Spatial with Neo4j Server and GeoServer.

Noted: it is feasible to integrate with Geoserver, but geoserver cannot display the layers in the Publishing Database. (System environment: Ubuntu 12.04, Spatial 0.9, Neo4j 1.8M6, Geoserver 2.1.1)

Neo4J graph database practice series

Graph database practice series (1)-introduction and installation of Neo4J

Graph database practice series (II) -- Neo4J Spatial Data Storage

Graph database practice series (iii) -- REST integration of Neo4j Spatial

 

1. install and configure Neo4j Server 1.1install Neo4j Server

Neo4j can be installed as a database server and can run in the operating system in two forms: application or system service. It has built-in jetty and REST interfaces to operate databases using browsers [].

  1. Download your version on the neo4j official website http://neo4j.org/download( select your operating system)
  2. Decompress the package to a specific location. The decompressed path is expressed as $ NEO4J_HOME (for example,/home/dev/neo4j /)
  3. The STARTUP script is in the $ NEO4J_HOME/bin folder and runs $ NEO4J_HOME/bin/neo4j start in Linux/MacOS. In the Window, just double-click the % NEO4J_HOME % \ bin \ Neo4j. bat file.

We can also go to the bin folder ($ NEO4J_HOME/bin) of Neo4j installed in the source code as described in section 1 to start the command,

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

We only need to access http: // localhost: 7474/webadmin/. The web management interface of Neo4j appears, as shown in 1:

Figure 1 Neo4j Server Management page

On the Web management interface, we can view database nodes, attributes, and link information. You can also perform CRUD on Graph databases through Http, Shell, and Germlin. If you need to run Neo4j Server as a system service, refer to references [17].

1.2Neo4j Server configuration parameters

If you need to optimize the performance of the backend database of the Server, you can use the Server configuration file to understand the specific parameters of the graph database. These important parameters are stored in$ NEO4J_HOME/conf/neo4j-server.propertiesFile, including the path of the server database on disk:

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

Http server interface:

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

Set the relative path of the database that the REST data interface can manipulate

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

. For performance parameters and log parameters of Neo4j, see$ NEO4J_HOME/conf/neo4j. properties,$ NEO4J_HOME/Conf/logging. propertiesTwo files.

2. Neo4j Server and Spatial are integrated. 2.1 install the Spatail plug-in of Neo4j Server

We have installed neo4j spatial by using the source code. A file named neo4j-spatial-0.9-snapshot-server-plugin.zip is available in the/targetdirectory. If not, run the following command to obtain the file:

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

Decompress the file, copy all the jar packages to the lib folder of neo4j, and restart the neo4j server.

2.2 Neo4j Server spatial operations

The curl [20] tool can be used to read and write spatial data to Neo4j in the command line, including query, layer creation, and point creation. These operations are performed on Graph databases in JSON format using the http protocol.

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

The overall information of the database is returned, as shown in Figure 2:

Figure 2 query graph Databases

The returned JSON data contains the "SpatialPlugin" object. Its attributes include addEditableLayer, getLayer, and addNodeToLayer. We use the curl command to create simple vertex layers such as 'test.

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

3:

Figure 3 add a vertex Layer

You can see the attributes of the data formation, including the layer class, layer name, geometric encoding type, and creation time. Then add three vertices in Well-Konw text format

# 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"}'

Then execute a Range Query

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"}'

Two vertices in the boundary are returned, as shown in figure 4:

Figure 4 Range Query

  • 1
  • 2
  • Next Page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.