Neo4j Spatial in uDig

Neo4j Spatial supports Geotools, and therefor also Geotools based platforms like GeoServer and uDig. For information on setting up and running Neo4j Spatial in GeoServer, see the section [geoserver].

uDig SDK

Here we will discuss how to set up a development environment for developing code for uDig making use of Neo4j Spatial. For example, if you want to build a uDig plugin that makes use of Neo4j for the data model, or if you have a custom extension to Neo4j Spatial, and want to visualize the data in uDig.

Setting up uDig SDK

Follow the uDig SDK Quickstart instructions on the uDig wiki at http://udig.refractions.net/confluence/display/DEV/1+SDK+Quickstart. It is best to follow those instructions in detail, since all steps are explained and alternatives given. However, for the impatient and foolish, we include simplified instructions here:

Adding Neo4j Spatial

Versions and Dependencies:

  • Note that the trunk version of Neo4j Spatial requires uDig 1.2.1, which was not yet released at the time of writing. However, there was a SNAPSHOT build available at http://udig.refractions.net/files/downloads/branches, dated 10th September. If you cannot find a SNAPSHOT SDK at that date, or more recent, then look in the normal location, or consider building the SDK yourself according to the instructions athttp://udig.refractions.net/confluence/display/ADMIN/02+Development+Environment

  • If you wish to use uDig 1.2.0 official release, then you need to use an older version of Neo4j Spatial. Specifically any version earlier than the upgrade to GeoTools 2.7 which occurred on the 1st October. Adding Neo4j Spatial to uDig:

  • Install Maven2 support for Eclipse:

  • Go to 'Help→Install New Software' and add a new update site for M2Eclipse using URL http://m2eclipse.sonatype.org/sites/m2e

  • Select and install the maven integration for eclipse

  • Get the source code for Neo4j Spatial using: git clone git://github.com/neo4j/neo4j-spatial.git

  • If you need to use the GeoTools 2.6 version of Neo4j Spatial:

  • Switch to the end of September version using the command: git checkout 04a0ae

  • If you plan to develop Neo4j Spatial code from this point, consider making a branch first by going to the newly created directory, typing 'git branch yourbranchname' followed by 'git checkout yourbranchname'

  • Compile and test the code using: mvn test

  • This should download all dependencies and run some test cases to make sure everything is OK

  • Get the source code for eu.udig.catalog.neo4j using: git clone git://gitorious.org/udig-community/neo4j.git eu.udig.catalog.neo4j

  • you can branch this as well

  • Start eclipse and import the two projects into the workspace

  • Use 'File→Import→General→Existing Projects into Workspace'

  • Browse to the location of your git projects and select and import the neo4j-spatial and eu.udig.catalog.neo4j projects

  • Create a libs project that wraps some dependent jars

  • Use 'New Project→Plug-in Development→Plug-in from existing JAR archives'

  • The files you need to add would have been installed by maven during the 'mvn test' of neo4j-spatial above (on Windows possibly in your User\Username\.m2\repository folder) but can also be downloaded separately

  • Select the JAR files to add to the libs project:

  • neo4j-kernel-1.2-1.2.jar

  • neo4j-index-1.2-1.2.jar

  • neo4j-graph-algo-0.7-1.2.jar

  • geronimo-jta_1.1_spec-1.1.1.jar

  • org.apache.servicemix.bundles.lucene-3.0.1_2.jar

  • json-simple-1.1.jar

  • Choose a name like 'org.neo4j.spatial.libs' and create the project

  • Open the new libs projects MANIFEST.MF file and exit the exports to include all packages in the jars

Testing sample layers in uDig

When Neo4j Spatial was first installed above, you used 'mvn test' to run some test cases. This will have created a neo4j database with one or more layers, which you can use to display in uDig. However, we will take more control over this by specifically re-running one of the test cases, so we know exactly which layers will be visible.

  • Navigate to the test code for TestDynamicLayers, right click and choose 'Run as → JUnit Test'

  • This test case will load an OSM dataset for the city of Malmö in Sweden. It will then assign a number of 'dynamic layers', which are pre-configured filters of the dataset, designed to look like separate layers in the GIS, but in reality being views of the same connected graph in the database.

  • The test will also export these layers as both Shapefile and PNG images for testing purposes in neo4j-spatial\target\export. We will not need them for uDig, since we will be streaming the data directly into the view in uDig. However, you can compare these in uDig later to see the differences.

  • Open the run configurations dialog and look at the run configuration for uDig that was created earlier when you first ran uDig.

  • Check the plugins tab and make sure that the two new plugins in your workspace are selected:

  • org.neo4j.spatial

  • org.neo4j.spatial.libs

  • eu.udig.catalog.neo4j

  • Click 'Validate plugins' and optionally 'Add required plugins' to ensure that all dependencies are met (if needed edit the manifest.mf files of both eu.udig.catalog.neo4j and neo4j-spatial to mark the management dependencies optional: org.neo4j.kernel.impl.management;resolution:=optional, and org.neo4j.kernel.management;resolution:=optional)

  • Some errors in the projects may be due to invalid characters, such as in 'crossing_bygg_förstadsgatan'. Simply replace it with another name.

  • Optionally check 'clear workspace' on the main tab

  • Click the 'Run' button to run uDig with Neo4j support enabled

  • Once it has started, the eu.udig.catalog.neo4j plugin will scan your home directory for neo4j databases. In the catalog view you should see the one created by the unit test code. If you do not find one, you can import one:

  • Right click in the catalog view and choose 'Import→Data→Files'

  • Select the neostore-id file in the database directory to add this database to the catalog

  • Select one or more layers in the catalog and add them to the current map.

  • If you select the map2.osm layer, you will get a single layer containing all geometry types recognized as Geometries in the database

Udig map2
  • If you select one of the other layers, you will get a filtered view of only that data

  • Adding multiple layers to the map allows you to reorder the layers and modify their styling separately.

  • Optionally change the projection to look better for northern latitudes:

  • Click on the projection button below the map, which initially says 'WGS84'

  • Type 'RT90' into the filter, and then select 'RT90 2.5 gon V (3021)'. This is a common Swedish projection and so will work well for Malmö.

Udig map2 rt90
  • Try set the style for the map2.osm layer using the sample style file in the Neo4j Spatial source code: neo.sld.xml

  • Turn off all layers but map2.osm in the layers view, to keep the view simple

  • Right-click on the map2.osm layer in the layers view and choose 'Style'

  • Go to the 'XML' option, and mark all XML and delete it

  • Open neo.sld.xml in a text editor, select all the text and copy and paste it into the Style editor

  • Click apply and see the map redraw with more complex styling

Udig map2 styled

Update: New automatic styles for OSM

As of the 20th October (commit 506ee4), OSM layers now publish default styles to the GIS. The initial styles are quite simple, but this does allow for nicer out the box experience. Currently, the code will only work in a development environment with certain directory structure, but we’ll make it more generic soon.

Udig multi styled layers