Skip to content

Commit

Permalink
cleanup code (apply intellij code inspection fixes)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy2003 committed May 29, 2024
1 parent 4ed2740 commit fd1ab1f
Show file tree
Hide file tree
Showing 132 changed files with 1,119 additions and 1,250 deletions.
85 changes: 43 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ highlighted the need for a new approach to spatial libraries for Neo4j.

This library was originally written in 2010 when Neo4j was still releasing early 1.x versions.
This means it made use of internal Java API's that were deprecated over the years, some as early as Neo4j 2.x.
When Neo4j 4.0 was released, many deprecated API's were entirely removed.
When Neo4j 4.0 was released, many deprecated APIs were entirely removed.
And the transaction API was changed in a fundamental way.
This has meant that the spatial library needed a major refactoring to work with Neo4j 4.x:

Expand All @@ -69,7 +69,7 @@ This has meant that the spatial library needed a major refactoring to work with
It was therefor necessary to upgrade the GeoTools libraries to version 24.2.
This in turn required a re-write of the Neo4jDataStore interface since the older API had
long been deprecated, and was entirely unavailable in newer versions.
* Neo4j 4.1 was slightly stricter with regards to passing nodes as parameters, requiring the nodes
* Neo4j 4.1 was slightly stricter in regard to passing nodes as parameters, requiring the nodes
objects to have been created in the current transaction.
To work around this we added `.byId` versions of the `spatial.addNode` and `spatial.removeNode` procedures.
We also changed the `spatial.removeNode` procedures to return `nodeId` instead of `node`.
Expand All @@ -82,7 +82,7 @@ This has meant that the spatial library needed a major refactoring to work with
* 0.28.0 tackles the ability to import multiple OSM files. The initial solution for Neo4j 4.x made use
of schema indexes keyed by the label and property. However, that means that all OSM imports would share
the same index. If they are completely disjointed data sets, this would not matter. But if you import
overlapping OSM files or different versions of the same file file, a mangled partial merger would result.
overlapping OSM files or different versions of the same file, a mangled partial merger would result.
0.28.0 solves this by using different indexes, and keeping all imports completely separate.
The more complex problems of importing newer versions, and stitching together overlapping areas, are not
yet solved.
Expand Down Expand Up @@ -132,7 +132,7 @@ The key concepts of this library include:
* Multile CoordinationReferenceSystem support using GeoTools
* Support the concept of multiple geographic layers, each with its own CRS and Index
* Include an index capable of searching for complex geometries (in-graph RTree index)
* Support import and export in a number of known formats (eg. Shapefile and OSM)
* Support import and export in a number of known formats (e.g. Shapefile and OSM)
* Embed the library and Neo4j within GIS tools like uDig and GeoServer

Some key features include:
Expand Down Expand Up @@ -183,7 +183,7 @@ instructions on the spatial server plugin below.
## Layers and GeometryEncoders ##

The primary type that defines a collection of geometries is the Layer. A layer contains an index for querying. In
addition a Layer can be an EditableLayer if it is possible to add and modify geometries in the layer. The next most
addition, a Layer can be an EditableLayer if it is possible to add and modify geometries in the layer. The next most
important interface is the GeometryEncoder.

The DefaultLayer is the standard layer, making use of the WKBGeometryEncoder for storing all geometry types as byte[]
Expand All @@ -192,8 +192,9 @@ properties of one node per geometry instance.
The OSMLayer is a special layer supporting Open Street Map and storing the OSM model as a single fully connected graph.
The set of Geometries provided by this layer includes Points, LineStrings and Polygons, and as such cannot be exported
to Shapefile format, since that format only allows a single Geometry per layer. However, OMSLayer extends DynamicLayer,
which allow it to provide any number of sub-layers, each with a specific geometry type and in addition based on a OSM
tag filter. For example you can have a layer providing all cycle paths as LineStrings, or a layer providing all lakes as
which allow it to provide any number of sub-layers, each with a specific geometry type and in addition based on an OSM
tag filter. For example, you can have a layer providing all cycle paths as LineStrings, or a layer providing all lakes
as
Polygons. Underneath these are all still backed by the same fully connected graph, but exposed dynamically as apparently
separate geometry layers.

Expand All @@ -204,17 +205,17 @@ separate geometry layers.
Spatial data is divided in Layers and indexed by a RTree.

~~~java
GraphDatabaseService database = new GraphDatabaseFactory().newEmbeddedDatabase(storeDir);
try{
GraphDatabaseService database = new GraphDatabaseFactory().newEmbeddedDatabase(storeDir);
try{
ShapefileImporter importer = new ShapefileImporter(database);
importer.
importer.

importFile("roads.shp","layer_roads");
}finally{
database.
}finally{
database.

shutdown();
}
}
~~~

If using the server, the same can be achieved with spatial procedures (3.x only):
Expand All @@ -232,35 +233,35 @@ read this that will already be available. Refer to the unit tests in classes Tes
latest code for importing OSM data. At the time of writing the following worked:

~~~java
OSMImporter importer = new OSMImporter("sweden");
Map<String, String> config = new HashMap<String, String>();
config.put("neostore.nodestore.db.mapped_memory", "90M" );
config.put("dump_configuration", "true");
config.put("use_memory_mapped_buffers", "true");
BatchInserter batchInserter = BatchInserters.inserter(new File(dir), config);
importer.importFile(batchInserter, "sweden.osm", false);
batchInserter.shutdown();

GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase(dir);
importer.reIndex(db, 10000);
db.shutdown();
OSMImporter importer = new OSMImporter("sweden");
Map<String, String> config = new HashMap<String, String>();
config.put("neostore.nodestore.db.mapped_memory", "90M" );
config.put("dump_configuration", "true");
config.put("use_memory_mapped_buffers", "true");
BatchInserter batchInserter = BatchInserters.inserter(new File(dir), config);
importer.importFile(batchInserter, "sweden.osm", false);
batchInserter.shutdown();

GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase(dir);
importer.reIndex(db, 10000);
db.shutdown();
~~~

### Executing a spatial query ###

~~~java
GraphDatabaseService database = new GraphDatabaseFactory().newEmbeddedDatabase(storeDir);
try {
SpatialDatabaseService spatialService = new SpatialDatabaseService(database);
Layer layer = spatialService.getLayer("layer_roads");
SpatialIndexReader spatialIndex = layer.getIndex();
Search searchQuery = new SearchIntersectWindow(new Envelope(xmin, xmax, ymin, ymax));
spatialIndex.executeSearch(searchQuery);
List<SpatialDatabaseRecord> results = searchQuery.getResults();
} finally {
GraphDatabaseService database = new GraphDatabaseFactory().newEmbeddedDatabase(storeDir);
try {
SpatialDatabaseService spatialService = new SpatialDatabaseService(database);
Layer layer = spatialService.getLayer("layer_roads");
SpatialIndexReader spatialIndex = layer.getIndex();
Search searchQuery = new SearchIntersectWindow(new Envelope(xmin, xmax, ymin, ymax));
spatialIndex.executeSearch(searchQuery);
List<SpatialDatabaseRecord> results = searchQuery.getResults();
} finally {
database.shutdown();
}
}
~~~

If using the server, the same can be achieved with spatial procedures (3.x only):
Expand Down Expand Up @@ -360,7 +361,7 @@ This has not been tested at all in any GeoTools enabled application, but could p
~~~

The version specified on the version line can be changed to match the version you wish to work with (based on the
version of Neo4j itself you are using). Too see which versions are available see the list
version of Neo4j itself you are using). To see which versions are available see the list
at [Neo4j Spatial Releases](https://github.com/neo4j-contrib/m2/tree/master/releases/org/neo4j/neo4j-spatial).

* start the GeoServer webapp again with the added neo4j profile
Expand Down Expand Up @@ -437,7 +438,7 @@ The server plugin provides access to the internal spatial capabilities using thr
* A REST API for creating layers and adding nodes or geometries to layers.
* For usage information
see [Neo4j Spatial Manual REST](http://neo4j-contrib.github.io/spatial/#spatial-server-plugin)
* Note that this API provides only limited access to Spatial, with no access the the GeoPipes or import utilities
* Note that this API provides only limited access to Spatial, with no access the GeoPipes or import utilities
* This API was entirely removed when support for Neo4j 4.0 was added (version 0.27)
* An IndexProvider API (2.x only) for Cypher access using START node=node:geom({query})
* It is only possible to add nodes and query for nodes, and the resulting graph structure is not compatible with any
Expand Down Expand Up @@ -473,7 +474,7 @@ for examples.

### Building Neo4j Spatial Documentation ###

Add your Github credentials in your `~/.m2/settings.xml`
Add your GitHub credentials in your `~/.m2/settings.xml`

~~~xml
<settings>
Expand Down Expand Up @@ -531,17 +532,17 @@ Add the following repositories and dependency to your project's pom.xml:
~~~

The version specified on the last version line can be changed to match the version you wish to work with (based on the
version of Neo4j itself you are using). Too see which versions are available see the list
version of Neo4j itself you are using). To see which versions are available see the list
at [Neo4j Spatial Releases](https://github.com/neo4j-contrib/m2/tree/master/releases/org/neo4j/neo4j-spatial).

## Running Neo4j spatial code from the command-line ##

Some of the classes in Neoj4-Spatial include main() methods and can be run on the command-line.
For example there are command-line options for importing SHP and OSM data. See the main methods
in the OSMImporter and ShapefileImporter classes. Here we will describe how to setup the dependencies
in the OSMImporter and ShapefileImporter classes. Here we will describe how to set up the dependencies
for running the command-line, using the OSMImporter and the sample OSM file two-street.osm.
We will show two ways to run this on the command line, one with the java command itself, and the
other using the 'exec:java' target in maven. In both cases we use maven to setup the dependencies.
other using the 'exec:java' target in maven. In both cases we use maven to set up the dependencies.

### Compile ###

Expand Down
2 changes: 1 addition & 1 deletion neo.sld.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<StyledLayerDescriptor version="1.0.0"
xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd">
xsi:schemaLocation="http://www.opengis.net/sld https://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd">
<NamedLayer>
<Name>Example Neo4j Spatial OSM Style</Name>
<UserStyle>
Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
<properties>
<neo4j.version>5.13.0</neo4j.version>
<neo4j.java.version>17</neo4j.java.version>
Expand All @@ -23,11 +23,11 @@
<version>0.30.0-neo4j-5.13.0</version>
<name>Neo4j - Spatial Components</name>
<description>Spatial utilities and components for Neo4j</description>
<url>http://components.neo4j.org/${project.artifactId}/${project.version}</url>
<url>https://components.neo4j.org/${project.artifactId}/${project.version}</url>
<inceptionYear>2010</inceptionYear>
<packaging>jar</packaging>
<scm>
<url>http://github.com/neo4j/spatial/</url>
<url>https://github.com/neo4j/spatial/</url>
<connection>scm:git:git://github.com/neo4j/spatial.git</connection>
<developerConnection>scm:git:git@github.com:neo4j/spatial.git</developerConnection>
<tag>HEAD</tag>
Expand Down Expand Up @@ -261,7 +261,7 @@
<licenses>
<license>
<name>GNU General Public License, Version 3</name>
<url>http://www.gnu.org/licenses/gpl-3.0-standalone.html</url>
<url>https://www.gnu.org/licenses/gpl-3.0-standalone.html</url>
<comments>The software ("Software") developed and owned by Neo4j Sweden AB
(referred to in this notice as "Neo4j") is licensed under the GNU
GENERAL PUBLIC LICENSE Version 3 to all third parties and that license
Expand Down
4 changes: 2 additions & 2 deletions src/docs/dev/examples.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Also review the classes in the +org.neo4j.gis.spatial.query package+ for the ful
[[spatial-export-shapefile]]
== Export a shapefile

The ESRI Shapefile that we imported in the first example above was actually created by Neo4j-Spatial. It is possible to use the results of a query, or a DynamicLayer, to create a new Shapefile using the ShapefileExporter. If we were to export the complete layer created from importing a shapefile, we would not achieve much, but we can could use this capability to create shapefiles that are subsets of other layers, or that are created from data in another format.
The ESRI Shapefile that we imported in the first example above was actually created by Neo4j-Spatial. It is possible to use the results of a query, or a DynamicLayer, to create a new Shapefile using the ShapefileExporter. If we were to export the complete layer created from importing a shapefile, we would not achieve much, but we could use this capability to create shapefiles that are subsets of other layers, or that are created from data in another format.

[source,java,indent=0]
----
Expand All @@ -61,7 +61,7 @@ This example shows how we can import an OSM dataset, which contains data with a
include::{sourceDir}/org/neo4j/gis/spatial/TestsForDocs.java[tags=exportShapefileFromQuery]
----

This time we import the same OSM model, but query for all geometries inside a envelope, and export that to a new Shapefile.
This time we import the same OSM model, but query for all geometries inside an envelope, and export that to a new Shapefile.

[[spatial-geopipes]]
== GeoPipes
Expand Down
12 changes: 6 additions & 6 deletions src/docs/dev/geoserver2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Here we provide very basic instructions, with factors to consider regarding inst
* Choose the right version for the version of Neo4j Spatial you are going to use:
* Neo4j-Spatial trunk is currently coded to work with GeoTools 2.7, so this means we need to load it into GeoServer 2.1 or later. The version we tested against was geoserver-2.1-beta1
* If you want to deploy on the stable release of GeoServer 2.0.2, then you can use an older Neo4j-Spatial, or modify the code to work with GeoTools 2.6 (the differences are small). The last version of Neo4j Spatial that works with the GeoServer 2.0 series, is from the end of September 2010.
* If you already have a servlet container running, you can download the WAR version, otherwise download the BIN version (or the windows installer if on windows). Install and run using the included instructions in geoserver.
* Once installed, open a web browser on on http://localhost:8080/geoserver/web/ (or other location is you configured it differently) to test that geoserver is runnning correctly.
* If you already have a servlet container running, you can download the WAR version, otherwise download the BIN version (or the Windows installer if on Windows). Install and run using the included instructions in geoserver.
* Once installed, open a web browser on http://localhost:8080/geoserver/web/ (or other location is you configured it differently) to test that geoserver is runnning correctly.

=== Adding Neo4j Spatial

Expand All @@ -25,7 +25,7 @@ Install Neo4j-Spatial by copying the following JAR files into the in the GeoServ
* neo4j-index-1.2-1.2.M03.jar
* neo4j-spatial.jar

Getting this last jar can be achieved by using maven to compile from source, or by simply browsing to the maven repository website at http://m2.neo4j.org/org/neo4j/neo4j-spatial/
Getting this last jar can be achieved by using maven to compile from source, or by simply browsing to the maven repository website at http://m2.neo4j.org/org/neo4j/neo4j-spatial/

At the time of writing the latest JAR was:

Expand Down Expand Up @@ -57,7 +57,7 @@ image::Geoserver-3-path-to-neo4j-db.png[]

* One option for the database location is a database created using the unit tests in Neo4j Spatial. The rest of this wiki assumes that you ran the TestDynamicLayers unit test which loads an OSM dataset for the city of Malmö in Sweden, and then creates a number of Dynamic Layers (or views) on this data, which we can publish in GeoServer.
* If you do use the unit test for the sample database, then the location of the database will be in the target/var/neo4j-db directory of the Neo4j Source code.
* Type the URL as the full path to the neostore.id file in the database directory
* Type the URL as the full path to the neostore-id file in the database directory

== Publish from data source

Expand Down Expand Up @@ -117,6 +117,6 @@ image::Geoserver-12-layer-group-preview.png[]

== Controlling layer style

If you want to change the styles of the layers, one option is to go back to the layers list, select a layer, click the display tab and edit the styling information. This will also effect the preview in openlayers.
If you want to change the styles of the layers, one option is to go back to the layers list, select a layer, click the display tab and edit the styling information. This will also affect the preview in openlayers.

image::Geoserver-13-layers-preview-with-styles.png[]
image::Geoserver-13-layers-preview-with-styles.png[]
Loading

0 comments on commit fd1ab1f

Please sign in to comment.