-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split up procedures and functions into separate classes (#408)
- Loading branch information
Showing
18 changed files
with
636 additions
and
510 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -172,7 +172,7 @@ The spatial queries implemented are: | |
The simplest way to build Neo4j Spatial is by using maven. Just clone the git repository and run | ||
|
||
~~~bash | ||
mvn install | ||
mvn install | ||
~~~ | ||
|
||
This will download all dependencies, compiled the library, run the tests and install the artifact in your local | ||
|
@@ -207,22 +207,18 @@ Spatial data is divided in Layers and indexed by a RTree. | |
~~~java | ||
GraphDatabaseService database = new GraphDatabaseFactory().newEmbeddedDatabase(storeDir); | ||
try{ | ||
ShapefileImporter importer = new ShapefileImporter(database); | ||
importer. | ||
|
||
importFile("roads.shp","layer_roads"); | ||
}finally{ | ||
database. | ||
|
||
shutdown(); | ||
ShapefileImporter importer = new ShapefileImporter(database); | ||
importer.importFile("roads.shp","layer_roads"); | ||
} finally { | ||
database.shutdown(); | ||
} | ||
~~~ | ||
|
||
If using the server, the same can be achieved with spatial procedures (3.x only): | ||
|
||
~~~cypher | ||
CALL spatial.addWKTLayer('layer_roads','geometry') | ||
CALL spatial.importShapefileToLayer('layer_roads','roads.shp') | ||
CALL spatial.addWKTLayer('layer_roads', 'geometry') | ||
CALL spatial.importShapefileToLayer('layer_roads', 'roads.shp') | ||
~~~ | ||
|
||
### Importing an Open Street Map file ### | ||
|
@@ -267,24 +263,24 @@ try { | |
If using the server, the same can be achieved with spatial procedures (3.x only): | ||
|
||
~~~cypher | ||
CALL spatial.bbox('layer_roads', {lon:15.0,lat:60.0}, {lon:15.3, lat:61.0}) | ||
CALL spatial.bbox('layer_roads', {lon: 15.0, lat: 60.0}, {lon: 15.3, lat: 61.0}) | ||
~~~ | ||
|
||
Or using a polygon: | ||
|
||
~~~cypher | ||
WITH "POLYGON((15.3 60.2, 15.3 60.4, 15.7 60.4, 15.7 60.2, 15.3 60.2))" as polygon | ||
CALL spatial.intersects('layer_roads',polygon) YIELD node RETURN node.name as name | ||
WITH 'POLYGON((15.3 60.2, 15.3 60.4, 15.7 60.4, 15.7 60.2, 15.3 60.2))' AS polygon | ||
CALL spatial.intersects('layer_roads', polygon) YIELD node | ||
RETURN node.name AS name | ||
~~~ | ||
|
||
For further Java examples, refer to the test code in | ||
the [LayersTest](https://github.com/neo4j-contrib/spatial/blob/master/src/test/java/org/neo4j/gis/spatial/LayersTest.java) | ||
and | ||
the [TestSpatial](https://github.com/neo4j-contrib/spatial/blob/master/src/test/java/org/neo4j/gis/spatial/TestSpatial.java) | ||
classes. | ||
For further Java examples, refer to the test code in the | ||
[LayersTest](src/test/java/org/neo4j/gis/spatial/LayersTest.java) and | ||
the [TestSpatial](src/test/java/org/neo4j/gis/spatial/TestSpatial.java) classes. | ||
|
||
For further Procedures examples, refer to the code in | ||
the [SpatialProceduresTest](https://github.com/neo4j-contrib/spatial/blob/master/src/test/java/org/neo4j/gis/spatial/procedures/SpatialProceduresTest.java) | ||
the [SpatialProceduresTest](src/test/java/org/neo4j/gis/spatial/procedures/SpatialProceduresTest.java) | ||
class. | ||
|
||
## Neo4j Spatial Geoserver Plugin ## | ||
|
@@ -306,7 +302,7 @@ This has not been tested at all in any GeoTools enabled application, but could p | |
### Building ### | ||
|
||
~~~bash | ||
mvn clean install | ||
mvn clean install | ||
~~~ | ||
|
||
### Deployment into Geoserver ### | ||
|
@@ -326,38 +322,38 @@ This has not been tested at all in any GeoTools enabled application, but could p | |
* check out the geoserver source | ||
|
||
~~~bash | ||
svn co https://svn.codehaus.org/geoserver/trunk geoserver-trunk | ||
svn co https://svn.codehaus.org/geoserver/trunk geoserver-trunk | ||
~~~ | ||
|
||
* build the source | ||
|
||
~~~bash | ||
cd geoserver-trunk | ||
mvn clean install | ||
cd geoserver-trunk | ||
mvn clean install | ||
~~~ | ||
|
||
* check that you can run the web app as | ||
of [The GeoServer Maven build guide](http://docs.geoserver.org/latest/en/developer/maven-guide/index.html#running-the-web-module-with-jetty) | ||
|
||
~~~bash | ||
cd src/web/app | ||
mvn jetty:run | ||
cd src/web/app | ||
mvn jetty:run | ||
~~~ | ||
|
||
* in `$GEOSERVER_SOURCE/src/web/app/pom.xml` https://svn.codehaus.org/geoserver/trunk/src/web/app/pom.xml, add the | ||
following lines under the profiles section: | ||
|
||
~~~xml | ||
<profile> | ||
<id>neo4j</id> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.neo4j</groupId> | ||
<artifactId>neo4j-spatial</artifactId> | ||
<version>0.19-neo4j-3.0.3</version> | ||
</dependency> | ||
</dependencies> | ||
</profile> | ||
<profile> | ||
<id>neo4j</id> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.neo4j</groupId> | ||
<artifactId>neo4j-spatial</artifactId> | ||
<version>0.19-neo4j-3.0.3</version> | ||
</dependency> | ||
</dependencies> | ||
</profile> | ||
~~~ | ||
|
||
The version specified on the version line can be changed to match the version you wish to work with (based on the | ||
|
@@ -461,15 +457,15 @@ The Java API (the original API for Neo4j Spatial) still remains, however, the mo | |
and therefor we recommend that if you need to access Neo4j server remotely, and want deeper access to Spatial functions, | ||
consider writing your own Procedures. The Neo4j 3.0 documentation provides some good information on how to do this, | ||
and you can also refer to | ||
the [Neo4j Spatial procedures source code](https://github.com/neo4j-contrib/spatial/blob/master/src/main/java/org/neo4j/gis/spatial/procedures/SpatialProcedures.java) | ||
the [Neo4j Spatial procedures source code](src/main/java/org/neo4j/gis/spatial/procedures/SpatialProcedures.java) | ||
for examples. | ||
|
||
## Building Neo4j spatial ## | ||
|
||
~~~bash | ||
git clone https://github.com/neo4j/spatial.git | ||
cd spatial | ||
mvn clean package | ||
git clone https://github.com/neo4j-contrib/spatial/spatial.git | ||
cd spatial | ||
mvn clean package | ||
~~~ | ||
|
||
### Building Neo4j Spatial Documentation ### | ||
|
@@ -478,57 +474,57 @@ Add your GitHub credentials in your `~/.m2/settings.xml` | |
|
||
~~~xml | ||
<settings> | ||
<servers> | ||
<server> | ||
<id>github</id> | ||
<username>[email protected]</username> | ||
<password>secret</password> | ||
</server> | ||
</servers> | ||
<servers> | ||
<server> | ||
<id>github</id> | ||
<username>[email protected]</username> | ||
<password>secret</password> | ||
</server> | ||
</servers> | ||
</settings> | ||
~~~ | ||
|
||
To build and deploy: | ||
|
||
~~~bash | ||
git clone https://github.com/neo4j/spatial.git | ||
cd spatial | ||
mvn clean install site -Pneo-docs-build | ||
git clone https://github.com/neo4j/spatial.git | ||
cd spatial | ||
mvn clean install site -Pneo-docs-build | ||
~~~ | ||
|
||
## Using Neo4j spatial in your Java project with Maven ## | ||
|
||
Add the following repositories and dependency to your project's pom.xml: | ||
|
||
~~~xml | ||
<repositories> | ||
<repository> | ||
<id>neo4j-contrib-releases</id> | ||
<url>https://raw.github.com/neo4j-contrib/m2/master/releases</url> | ||
<releases> | ||
<enabled>true</enabled> | ||
</releases> | ||
<snapshots> | ||
<enabled>false</enabled> | ||
</snapshots> | ||
</repository> | ||
<repository> | ||
<id>neo4j-contrib-snapshots</id> | ||
<url>https://raw.github.com/neo4j-contrib/m2/master/snapshots</url> | ||
<releases> | ||
<enabled>false</enabled> | ||
</releases> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
</snapshots> | ||
</repository> | ||
</repositories> | ||
[...] | ||
<dependency> | ||
<groupId>org.neo4j</groupId> | ||
<artifactId>neo4j-spatial</artifactId> | ||
<version>0.30.0-neo4j-5.13.0</version> | ||
</dependency> | ||
<repositories> | ||
<repository> | ||
<id>neo4j-contrib-releases</id> | ||
<url>https://raw.github.com/neo4j-contrib/m2/master/releases</url> | ||
<releases> | ||
<enabled>true</enabled> | ||
</releases> | ||
<snapshots> | ||
<enabled>false</enabled> | ||
</snapshots> | ||
</repository> | ||
<repository> | ||
<id>neo4j-contrib-snapshots</id> | ||
<url>https://raw.github.com/neo4j-contrib/m2/master/snapshots</url> | ||
<releases> | ||
<enabled>false</enabled> | ||
</releases> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
</snapshots> | ||
</repository> | ||
</repositories> | ||
[...] | ||
<dependency> | ||
<groupId>org.neo4j</groupId> | ||
<artifactId>neo4j-spatial</artifactId> | ||
<version>0.30.0-neo4j-5.13.0</version> | ||
</dependency> | ||
~~~ | ||
|
||
The version specified on the last version line can be changed to match the version you wish to work with (based on the | ||
|
@@ -547,16 +543,16 @@ other using the 'exec:java' target in maven. In both cases we use maven to set u | |
### Compile ### | ||
|
||
~~~bash | ||
git clone git://github.com/neo4j-contrib/spatial.git | ||
cd spatial | ||
mvn clean compile | ||
git clone git://github.com/neo4j-contrib/spatial.git | ||
cd spatial | ||
mvn clean compile | ||
~~~ | ||
|
||
### Run using JAVA command ### | ||
|
||
~~~bash | ||
mvn dependency:copy-dependencies | ||
java -cp target/classes:target/dependency/* org.neo4j.gis.spatial.osm.OSMImporter osm-db two-street.osm | ||
mvn dependency:copy-dependencies | ||
java -cp target/classes:target/dependency/* org.neo4j.gis.spatial.osm.OSMImporter osm-db two-street.osm | ||
~~~ | ||
|
||
_Note: On windows remember to separate the classpath with ';' instead of ':'._ | ||
|
@@ -571,7 +567,7 @@ the above approach is most certainly the easiest way to do this. | |
### Run using 'mvn exec:java' ### | ||
|
||
~~~bash | ||
mvn exec:java -Dexec.mainClass=org.neo4j.gis.spatial.osm.OSMImporter -Dexec.args="osm-db two-street.osm" | ||
mvn exec:java -Dexec.mainClass=org.neo4j.gis.spatial.osm.OSMImporter -Dexec.args="osm-db two-street.osm" | ||
~~~ | ||
|
||
Note that the OSMImporter cannot re-import the same data multiple times, | ||
|
58 changes: 58 additions & 0 deletions
58
src/main/java/org/neo4j/gis/spatial/functions/SpatialFunctions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (c) "Neo4j" | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j Spatial. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.neo4j.gis.spatial.functions; | ||
|
||
import org.neo4j.gis.spatial.Layer; | ||
import org.neo4j.gis.spatial.procedures.SpatialProcedures.GeometryResult; | ||
import org.neo4j.gis.spatial.utilities.SpatialApiBase; | ||
import org.neo4j.graphdb.Node; | ||
import org.neo4j.procedure.Description; | ||
import org.neo4j.procedure.Name; | ||
import org.neo4j.procedure.UserFunction; | ||
|
||
public class SpatialFunctions extends SpatialApiBase { | ||
|
||
@UserFunction("spatial.decodeGeometry") | ||
@Description("Returns a geometry of a layer node as the Neo4j geometry type, to be passed to other procedures or returned to a client") | ||
public Object decodeGeometry( | ||
@Name("layerName") String name, | ||
@Name("node") Node node) { | ||
|
||
Layer layer = getLayerOrThrow(tx, spatial(), name); | ||
GeometryResult result = new GeometryResult( | ||
toNeo4jGeometry(layer, layer.getGeometryEncoder().decodeGeometry(node))); | ||
return result.geometry; | ||
} | ||
|
||
@UserFunction("spatial.asMap") | ||
@Description("Returns a Map object representing the Geometry, to be passed to other procedures or returned to a client") | ||
public Object asMap(@Name("object") Object geometry) { | ||
return toGeometryMap(geometry); | ||
} | ||
|
||
@UserFunction("spatial.asGeometry") | ||
@Description("Returns a geometry object as the Neo4j geometry type, to be passed to other functions or procedures or returned to a client") | ||
public Object asGeometry(@Name("geometry") Object geometry) { | ||
return toNeo4jGeometry(null, geometry); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.