$ git clone git://github.com/FaKod/neo4j-spatial-scala.git
$ cd neo4j-spatial-scala
$ mvn clean install
This library needs Neo4j-Scala that you have to "mvn install" first.
Or try to maven fetch it with a Github Maven Repo:
<repositories>
<repository>
<id>fakod-snapshots</id>
<url>https://raw.github.com/FaKod/fakod-mvn-repo/master/snapshots</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-spatial-scala</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
</dependencies>
Neo4j Spatial Scala Wrapper needs a Spatial Database Service Provider, it has to implement SpatialDatabaseServiceProvider trait. One possibility is to use the SimpleSpatialDatabaseServiceProvider for embedded Neo4j instances where you simply have to define a Neo4j storage directory. A class using the wrapper is f.e.:
class MyNeo4jClass extends SomethingClass with Neo4jSpatialWrapper with EmbeddedGraphDatabaseServiceProvider with SimpleSpatialDatabaseServiceProvider {
def neo4jStoreDir = "/tmp/temp-spatial-neo"
. . .
}
Transactions are wrapped by withSpatialTx. After leaving the "scope" success is called (or rollback if an exception is raised):
withSpatialTx {
implicit neo =>
deleteLayer("test", new NullListener)
val layerNames = getLayerNames
}
To ease the Layer handling a Layer scope can be provided:
// return or create a Layer instance
withLayer(getOrCreateEditableLayer("test")) {
implicit layer =>
// adding a new Point to Layer "test"
val point = add newPoint ((15.3, 56.2))
}
Tuples are used for locations, List of Tuples for geometries with more than one location. Case class serialization can by added by "using ..."
case class City(name: String)
case class FederalState(name: String)
. . .
val point = add newPoint ((15.3, 56.2))
val munich = add newPoint ((15.3, 56.2)) using City("Munich")
val ring = LinRing((15.0, 56.0) ::(16.0, 56.0) ::(15.0, 57.0) ::(16.0, 57.0) ::(15.0, 56.0) :: Nil)
val bayern = add newPolygon (ring) using FederalState("Bayern")
munich --> "CapitalCityOf" --> bayern
Spatial searches start with Search
and the type of search, like:
- within
- withinDistance
- coveredBy
- intersect
- … more to come ...
For instance:
// search all cities within envelope
val sw = Search within Envelope(15.0, 16.0, 56.0, 57.0)
for (r <- sw; city <- r.toCC[City]) yield city