Skip to content

skanjila/neo4j-spatial-scala

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Neo4j Spatial Scala wrapper library

Building

$ git clone git://github.com/FaKod/neo4j-scala.git
$ cd neo4j-scala
$ mvn clean install

This library needs Neo4j-Scala that you have to "mvn install" first.

Using this library

Spatial Database Service Provider

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

Transaction Wrapping

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
}

Using Layer

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))
}

Adding Spatial Features to a Layer

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

Searching Things

For spatial searches defined by one geometry parameter search[SearchType] can be used:

val result = search[SearchWithin](toGeometry(new Envelope(15.0, 16.0, 56.0, 57.0)))

withSearch[SearchWithin](bayern.getGeometry) {
  implicit s =>
    executeSearch
    // yield all Nodes that are of type Case Class City
    val cities = for(n <- getResults; c <- n.toCC[City]) yield c
}

About

Scala Wrapper for Neo4j Spatial

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published