Neo4j Spatial in GeoServer

Neo4j Spatial includes built-in support for a GeoTools data store. This means it is, in principle, directly usable inside GeoServer. This document will discuss how to get it up and running in GeoServer. If you are interested in a desktop GIS, take a look at Neo4j Spatial in uDig.

Installing Neo4j-Spatial in GeoServer

Installing GeoServer

First of all you need to download and install geoserver from http://geoserver.org/display/GEOS/Download. For detailed installation instructions, refer to the official GeoServer documentation at http://docs.geoserver.org/stable/en/user/installation/index.html Here we provide very basic instructions, with factors to consider regarding installing GeoServer with Neo4j Spatial:

  • Choose the right version for the version of Neo4j Spatial you are going to use:

  • Neo4j-Spatial trunk is currently coded to work with GeoTools 2.7, so this means we need to load it into GeoServer 2.1 or later. The version we tested against was geoserver-2.1-beta1

  • If you want to deploy on the stable release of GeoServer 2.0.2, then you can use an older Neo4j-Spatial, or modify the code to work with GeoTools 2.6 (the differences are small). The last version of Neo4j Spatial that works with the GeoServer 2.0 series, is from the end of September 2010.

  • If you already have a servlet container running, you can download the WAR version, otherwise download the BIN version (or the Windows installer if on Windows). Install and run using the included instructions in geoserver.

  • Once installed, open a web browser on http://localhost:8080/geoserver/web/ (or other location is you configured it differently) to test that geoserver is runnning correctly.

Adding Neo4j Spatial

Install Neo4j-Spatial by copying the following JAR files into the in the GeoServer directory webapps/geoserver/WEB-INF/lib:

  • json-simple-1.1.jar

  • geronimo-jta_1.1_spec-1.1.1.jar

  • neo4j-kernel-1.2-1.2.M03.jar

  • neo4j-index-1.2-1.2.M03.jar

  • neo4j-spatial.jar

Getting this last jar can be achieved by using maven to compile from source, or by simply browsing to the maven repository website at http://m2.neo4j.org/org/neo4j/neo4j-spatial/

At the time of writing the latest JAR was:

Visualizing Neo4j Spatial data in GeoServer

These instructions lead you through getting started with adding some test layers from Neo4j Spatial to the running GeoServer

Login as 'admin' with password 'geoserver', unless you have changed those in the security/users.properties file during installation

Geoserver 1 logged in

Add a data source

Go to 'Stores' and click 'Add a new Store'

Geoserver 2 add new store

Name the data source and add the path to the Neo4j Database you have your layers in

Geoserver 3 path to neo4j db
  • One option for the database location is a database created using the unit tests in Neo4j Spatial. The rest of this wiki assumes that you ran the TestDynamicLayers unit test which loads an OSM dataset for the city of Malmö in Sweden, and then creates a number of Dynamic Layers (or views) on this data, which we can publish in GeoServer.

  • If you do use the unit test for the sample database, then the location of the database will be in the target/var/neo4j-db directory of the Neo4j Source code.

  • Type the URL as the full path to the neostore-id file in the database directory

Publish from data source

Now we will publish a layer from the data source

Click 'Neo4j' under 'Vector Data Sources' and then click 'Add new layer'

Geoserver 5 choose new layer

Choose the 'Neo4j Data Store'

Geoserver 6 choose new layer2

Choose a layer and click 'Publish' GeoServer seems to have trouble detecting the CRS and bounds, so we have to enter this manually

Geoserver 6 publish layer settings
  • Type CRS manually into the 'Declared SRS' field. For OSM data (as published by the TestDynamicLayers code) use EPSG:4326

  • Click 'Compute from data' to get the native bounding box

  • Copy and paste all these fields into the Lat/Lon bounding box (for some reason, 'Compute from native bounds' is not working)

  • Save the layer

  • Repeat this for as many layers as you want to publish

Geoserver 7 four layers published

Previewing layers

Preview one of the published layers

Go to the layer preview page and select the layer and 'OpenLayers' or other option for preview.

Geoserver 8 single layer preview

Preview multiple layers

  • Add a layer group, by clicking on 'layer groups'

Geoserver 9 layer groups
  • and then click 'add new layer group'.

Geoserver 10 layer group settings
  • Enter the name, and copy the bounds from one of the layers you plan to add. The 'Generate Bounds' function does not seem to work.

  • Enter the CRS as the same as the one used in one of the layers you plan to add.

  • Then click 'Add Layer' and select a layer to add to the group. Repeat this for as many layers as you plan to add.

  • Save the group and then go to the Layer Preview and you will see the group as an option to preview.

Geoserver 11 layer preview list
  • Select 'OpenLayers' to preview in a dynamic map that can be zoomed in.

Geoserver 12 layer group preview

Controlling layer style

If you want to change the styles of the layers, one option is to go back to the layers list, select a layer, click the display tab and edit the styling information. This will also affect the preview in openlayers.

Geoserver 13 layers preview with styles