Skip to content

Commit 95f88c4

Browse files
authored
Split up procedures and functions into separate classes (#408)
1 parent 99b4198 commit 95f88c4

18 files changed

+636
-510
lines changed

README.md

Lines changed: 80 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ The spatial queries implemented are:
172172
The simplest way to build Neo4j Spatial is by using maven. Just clone the git repository and run
173173

174174
~~~bash
175-
mvn install
175+
mvn install
176176
~~~
177177

178178
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.
207207
~~~java
208208
GraphDatabaseService database = new GraphDatabaseFactory().newEmbeddedDatabase(storeDir);
209209
try{
210-
ShapefileImporter importer = new ShapefileImporter(database);
211-
importer.
212-
213-
importFile("roads.shp","layer_roads");
214-
}finally{
215-
database.
216-
217-
shutdown();
210+
ShapefileImporter importer = new ShapefileImporter(database);
211+
importer.importFile("roads.shp","layer_roads");
212+
} finally {
213+
database.shutdown();
218214
}
219215
~~~
220216

221217
If using the server, the same can be achieved with spatial procedures (3.x only):
222218

223219
~~~cypher
224-
CALL spatial.addWKTLayer('layer_roads','geometry')
225-
CALL spatial.importShapefileToLayer('layer_roads','roads.shp')
220+
CALL spatial.addWKTLayer('layer_roads', 'geometry')
221+
CALL spatial.importShapefileToLayer('layer_roads', 'roads.shp')
226222
~~~
227223

228224
### Importing an Open Street Map file ###
@@ -267,24 +263,24 @@ try {
267263
If using the server, the same can be achieved with spatial procedures (3.x only):
268264

269265
~~~cypher
270-
CALL spatial.bbox('layer_roads', {lon:15.0,lat:60.0}, {lon:15.3, lat:61.0})
266+
CALL spatial.bbox('layer_roads', {lon: 15.0, lat: 60.0}, {lon: 15.3, lat: 61.0})
271267
~~~
272268

273269
Or using a polygon:
274270

275271
~~~cypher
276-
WITH "POLYGON((15.3 60.2, 15.3 60.4, 15.7 60.4, 15.7 60.2, 15.3 60.2))" as polygon
277-
CALL spatial.intersects('layer_roads',polygon) YIELD node RETURN node.name as name
272+
273+
WITH 'POLYGON((15.3 60.2, 15.3 60.4, 15.7 60.4, 15.7 60.2, 15.3 60.2))' AS polygon
274+
CALL spatial.intersects('layer_roads', polygon) YIELD node
275+
RETURN node.name AS name
278276
~~~
279277

280-
For further Java examples, refer to the test code in
281-
the [LayersTest](https://github.com/neo4j-contrib/spatial/blob/master/src/test/java/org/neo4j/gis/spatial/LayersTest.java)
282-
and
283-
the [TestSpatial](https://github.com/neo4j-contrib/spatial/blob/master/src/test/java/org/neo4j/gis/spatial/TestSpatial.java)
284-
classes.
278+
For further Java examples, refer to the test code in the
279+
[LayersTest](src/test/java/org/neo4j/gis/spatial/LayersTest.java) and
280+
the [TestSpatial](src/test/java/org/neo4j/gis/spatial/TestSpatial.java) classes.
285281

286282
For further Procedures examples, refer to the code in
287-
the [SpatialProceduresTest](https://github.com/neo4j-contrib/spatial/blob/master/src/test/java/org/neo4j/gis/spatial/procedures/SpatialProceduresTest.java)
283+
the [SpatialProceduresTest](src/test/java/org/neo4j/gis/spatial/procedures/SpatialProceduresTest.java)
288284
class.
289285

290286
## Neo4j Spatial Geoserver Plugin ##
@@ -306,7 +302,7 @@ This has not been tested at all in any GeoTools enabled application, but could p
306302
### Building ###
307303

308304
~~~bash
309-
mvn clean install
305+
mvn clean install
310306
~~~
311307

312308
### Deployment into Geoserver ###
@@ -326,38 +322,38 @@ This has not been tested at all in any GeoTools enabled application, but could p
326322
* check out the geoserver source
327323

328324
~~~bash
329-
svn co https://svn.codehaus.org/geoserver/trunk geoserver-trunk
325+
svn co https://svn.codehaus.org/geoserver/trunk geoserver-trunk
330326
~~~
331327

332328
* build the source
333329

334330
~~~bash
335-
cd geoserver-trunk
336-
mvn clean install
331+
cd geoserver-trunk
332+
mvn clean install
337333
~~~
338334

339335
* check that you can run the web app as
340336
of [The GeoServer Maven build guide](http://docs.geoserver.org/latest/en/developer/maven-guide/index.html#running-the-web-module-with-jetty)
341337

342338
~~~bash
343-
cd src/web/app
344-
mvn jetty:run
339+
cd src/web/app
340+
mvn jetty:run
345341
~~~
346342

347343
* in `$GEOSERVER_SOURCE/src/web/app/pom.xml` https://svn.codehaus.org/geoserver/trunk/src/web/app/pom.xml, add the
348344
following lines under the profiles section:
349345

350346
~~~xml
351-
<profile>
352-
<id>neo4j</id>
353-
<dependencies>
354-
<dependency>
355-
<groupId>org.neo4j</groupId>
356-
<artifactId>neo4j-spatial</artifactId>
357-
<version>0.19-neo4j-3.0.3</version>
358-
</dependency>
359-
</dependencies>
360-
</profile>
347+
<profile>
348+
<id>neo4j</id>
349+
<dependencies>
350+
<dependency>
351+
<groupId>org.neo4j</groupId>
352+
<artifactId>neo4j-spatial</artifactId>
353+
<version>0.19-neo4j-3.0.3</version>
354+
</dependency>
355+
</dependencies>
356+
</profile>
361357
~~~
362358

363359
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
461457
and therefor we recommend that if you need to access Neo4j server remotely, and want deeper access to Spatial functions,
462458
consider writing your own Procedures. The Neo4j 3.0 documentation provides some good information on how to do this,
463459
and you can also refer to
464-
the [Neo4j Spatial procedures source code](https://github.com/neo4j-contrib/spatial/blob/master/src/main/java/org/neo4j/gis/spatial/procedures/SpatialProcedures.java)
460+
the [Neo4j Spatial procedures source code](src/main/java/org/neo4j/gis/spatial/procedures/SpatialProcedures.java)
465461
for examples.
466462

467463
## Building Neo4j spatial ##
468464

469465
~~~bash
470-
git clone https://github.com/neo4j/spatial.git
471-
cd spatial
472-
mvn clean package
466+
git clone https://github.com/neo4j-contrib/spatial/spatial.git
467+
cd spatial
468+
mvn clean package
473469
~~~
474470

475471
### Building Neo4j Spatial Documentation ###
@@ -478,57 +474,57 @@ Add your GitHub credentials in your `~/.m2/settings.xml`
478474

479475
~~~xml
480476
<settings>
481-
<servers>
482-
<server>
483-
<id>github</id>
484-
<username>xxx@xxx.xx</username>
485-
<password>secret</password>
486-
</server>
487-
</servers>
477+
<servers>
478+
<server>
479+
<id>github</id>
480+
<username>xxx@xxx.xx</username>
481+
<password>secret</password>
482+
</server>
483+
</servers>
488484
</settings>
489485
~~~
490486

491487
To build and deploy:
492488

493489
~~~bash
494-
git clone https://github.com/neo4j/spatial.git
495-
cd spatial
496-
mvn clean install site -Pneo-docs-build
490+
git clone https://github.com/neo4j/spatial.git
491+
cd spatial
492+
mvn clean install site -Pneo-docs-build
497493
~~~
498494

499495
## Using Neo4j spatial in your Java project with Maven ##
500496

501497
Add the following repositories and dependency to your project's pom.xml:
502498

503499
~~~xml
504-
<repositories>
505-
<repository>
506-
<id>neo4j-contrib-releases</id>
507-
<url>https://raw.github.com/neo4j-contrib/m2/master/releases</url>
508-
<releases>
509-
<enabled>true</enabled>
510-
</releases>
511-
<snapshots>
512-
<enabled>false</enabled>
513-
</snapshots>
514-
</repository>
515-
<repository>
516-
<id>neo4j-contrib-snapshots</id>
517-
<url>https://raw.github.com/neo4j-contrib/m2/master/snapshots</url>
518-
<releases>
519-
<enabled>false</enabled>
520-
</releases>
521-
<snapshots>
522-
<enabled>true</enabled>
523-
</snapshots>
524-
</repository>
525-
</repositories>
526-
[...]
527-
<dependency>
528-
<groupId>org.neo4j</groupId>
529-
<artifactId>neo4j-spatial</artifactId>
530-
<version>0.30.0-neo4j-5.13.0</version>
531-
</dependency>
500+
<repositories>
501+
<repository>
502+
<id>neo4j-contrib-releases</id>
503+
<url>https://raw.github.com/neo4j-contrib/m2/master/releases</url>
504+
<releases>
505+
<enabled>true</enabled>
506+
</releases>
507+
<snapshots>
508+
<enabled>false</enabled>
509+
</snapshots>
510+
</repository>
511+
<repository>
512+
<id>neo4j-contrib-snapshots</id>
513+
<url>https://raw.github.com/neo4j-contrib/m2/master/snapshots</url>
514+
<releases>
515+
<enabled>false</enabled>
516+
</releases>
517+
<snapshots>
518+
<enabled>true</enabled>
519+
</snapshots>
520+
</repository>
521+
</repositories>
522+
[...]
523+
<dependency>
524+
<groupId>org.neo4j</groupId>
525+
<artifactId>neo4j-spatial</artifactId>
526+
<version>0.30.0-neo4j-5.13.0</version>
527+
</dependency>
532528
~~~
533529

534530
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
547543
### Compile ###
548544

549545
~~~bash
550-
git clone git://github.com/neo4j-contrib/spatial.git
551-
cd spatial
552-
mvn clean compile
546+
git clone git://github.com/neo4j-contrib/spatial.git
547+
cd spatial
548+
mvn clean compile
553549
~~~
554550

555551
### Run using JAVA command ###
556552

557553
~~~bash
558-
mvn dependency:copy-dependencies
559-
java -cp target/classes:target/dependency/* org.neo4j.gis.spatial.osm.OSMImporter osm-db two-street.osm
554+
mvn dependency:copy-dependencies
555+
java -cp target/classes:target/dependency/* org.neo4j.gis.spatial.osm.OSMImporter osm-db two-street.osm
560556
~~~
561557

562558
_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.
571567
### Run using 'mvn exec:java' ###
572568

573569
~~~bash
574-
mvn exec:java -Dexec.mainClass=org.neo4j.gis.spatial.osm.OSMImporter -Dexec.args="osm-db two-street.osm"
570+
mvn exec:java -Dexec.mainClass=org.neo4j.gis.spatial.osm.OSMImporter -Dexec.args="osm-db two-street.osm"
575571
~~~
576572

577573
Note that the OSMImporter cannot re-import the same data multiple times,
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j Spatial.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
package org.neo4j.gis.spatial.functions;
22+
23+
import org.neo4j.gis.spatial.Layer;
24+
import org.neo4j.gis.spatial.procedures.SpatialProcedures.GeometryResult;
25+
import org.neo4j.gis.spatial.utilities.SpatialApiBase;
26+
import org.neo4j.graphdb.Node;
27+
import org.neo4j.procedure.Description;
28+
import org.neo4j.procedure.Name;
29+
import org.neo4j.procedure.UserFunction;
30+
31+
public class SpatialFunctions extends SpatialApiBase {
32+
33+
@UserFunction("spatial.decodeGeometry")
34+
@Description("Returns a geometry of a layer node as the Neo4j geometry type, to be passed to other procedures or returned to a client")
35+
public Object decodeGeometry(
36+
@Name("layerName") String name,
37+
@Name("node") Node node) {
38+
39+
Layer layer = getLayerOrThrow(tx, spatial(), name);
40+
GeometryResult result = new GeometryResult(
41+
toNeo4jGeometry(layer, layer.getGeometryEncoder().decodeGeometry(node)));
42+
return result.geometry;
43+
}
44+
45+
@UserFunction("spatial.asMap")
46+
@Description("Returns a Map object representing the Geometry, to be passed to other procedures or returned to a client")
47+
public Object asMap(@Name("object") Object geometry) {
48+
return toGeometryMap(geometry);
49+
}
50+
51+
@UserFunction("spatial.asGeometry")
52+
@Description("Returns a geometry object as the Neo4j geometry type, to be passed to other functions or procedures or returned to a client")
53+
public Object asGeometry(@Name("geometry") Object geometry) {
54+
return toNeo4jGeometry(null, geometry);
55+
}
56+
57+
58+
}

0 commit comments

Comments
 (0)