Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/0.15-neo4j-2.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
craigtaverner committed Jul 29, 2016
2 parents 64d8780 + 1dd1e6b commit 635ed05
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 97 deletions.
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,8 @@ Precompiled versions of the plugin file ready for download and use:

* [for Neo4j 2.0.4](https://github.com/neo4j-contrib/m2/blob/master/releases/org/neo4j/neo4j-spatial/0.12-neo4j-2.0.4/neo4j-spatial-0.12-neo4j-2.0.4-server-plugin.zip?raw=true)
* [for Neo4j 2.1.8](https://github.com/neo4j-contrib/m2/blob/master/releases/org/neo4j/neo4j-spatial/0.13-neo4j-2.1.8/neo4j-spatial-0.13-neo4j-2.1.8-server-plugin.zip?raw=true)
* [for Neo4j 2.2.6](https://github.com/neo4j-contrib/m2/blob/master/releases/org/neo4j/neo4j-spatial/0.14-neo4j-2.2.6/neo4j-spatial-0.14-neo4j-2.2.6-server-plugin.zip?raw=true)
* [for Neo4j 2.2.7](https://github.com/neo4j-contrib/m2/blob/master/releases/org/neo4j/neo4j-spatial/0.14-neo4j-2.2.7/neo4j-spatial-0.14-neo4j-2.2.7-server-plugin.zip?raw=true)
* [for Neo4j 2.3.0](https://github.com/neo4j-contrib/m2/blob/master/releases/org/neo4j/neo4j-spatial/0.15-neo4j-2.3.0/neo4j-spatial-0.15-neo4j-2.3.0-server-plugin.zip?raw=true)
* [for Neo4j 2.3.1](https://github.com/neo4j-contrib/m2/blob/master/releases/org/neo4j/neo4j-spatial/0.15-neo4j-2.3.1/neo4j-spatial-0.15-neo4j-2.3.1-server-plugin.zip?raw=true)
* [for Neo4j 2.3.2](https://github.com/neo4j-contrib/m2/blob/master/releases/org/neo4j/neo4j-spatial/0.15-neo4j-2.3.2/neo4j-spatial-0.15-neo4j-2.3.2-server-plugin.zip?raw=true)
* [for Neo4j 2.3.3](https://github.com/neo4j-contrib/m2/blob/master/releases/org/neo4j/neo4j-spatial/0.15-neo4j-2.3.3/neo4j-spatial-0.15-neo4j-2.3.3-server-plugin.zip?raw=true)
* [for Neo4j 2.3.4](https://github.com/neo4j-contrib/m2/blob/master/releases/org/neo4j/neo4j-spatial/0.15-neo4j-2.3.4/neo4j-spatial-0.15-neo4j-2.3.4-server-plugin.zip?raw=true)
* [for Neo4j 3.0.1](https://github.com/neo4j-contrib/m2/blob/master/releases/org/neo4j/neo4j-spatial/0.16-neo4j-3.0.1/neo4j-spatial-0.16-neo4j-3.0.1-server-plugin.jar?raw=true)
* [for Neo4j 2.3.4](https://github.com/neo4j-contrib/m2/blob/master/releases/org/neo4j/neo4j-spatial/0.15.2-neo4j-2.3.4/neo4j-spatial-0.15.2-neo4j-2.3.4-server-plugin.zip?raw=true)
* [for Neo4j 3.0.3](https://github.com/neo4j-contrib/m2/blob/master/releases/org/neo4j/neo4j-spatial/0.18-neo4j-3.0.3/neo4j-spatial-0.18-neo4j-3.0.3-server-plugin.jar?raw=true)

For versions up to 0.15-neo4j-2.3.4:
Expand Down
47 changes: 26 additions & 21 deletions src/main/java/org/geotools/data/neo4j/Neo4jSpatialDataStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,23 @@ public Neo4jSpatialDataStore(GraphDatabaseService database) {
* @return layer names
*/
public String[] getTypeNames() throws IOException {
if (typeNames == null) {
List<String> notEmptyTypes = new ArrayList<String>();
String[] allTypeNames = spatialDatabase.getLayerNames();
for (int i = 0; i < allTypeNames.length; i++) {
// discard empty layers
System.out.print( "loading layer " + allTypeNames[i] );
Layer layer = spatialDatabase.getLayer(allTypeNames[i]);
if (!layer.getIndex().isEmpty()) {
notEmptyTypes.add(allTypeNames[i]);
}
}
typeNames = notEmptyTypes.toArray(new String[] {});
}
return typeNames;
if (typeNames == null) {
try (Transaction tx = database.beginTx()) {
List<String> notEmptyTypes = new ArrayList<String>();
String[] allTypeNames = spatialDatabase.getLayerNames();
for (int i = 0; i < allTypeNames.length; i++) {
// discard empty layers
System.out.print("loading layer " + allTypeNames[i]);
Layer layer = spatialDatabase.getLayer(allTypeNames[i]);
if (!layer.getIndex().isEmpty()) {
notEmptyTypes.add(allTypeNames[i]);
}
}
typeNames = notEmptyTypes.toArray(new String[]{});
tx.success();
}
}
return typeNames;
}

/**
Expand Down Expand Up @@ -260,13 +263,15 @@ public FeatureWriter<SimpleFeatureType, SimpleFeature> getFeatureWriter(String t

public ReferencedEnvelope getBounds(String typeName) {
ReferencedEnvelope result = boundsIndex.get(typeName);
if (result == null) {
Envelope bbox = Utilities.fromNeo4jToJts(
spatialDatabase.getLayer(typeName).getIndex().getBoundingBox());
result = convertEnvelopeToRefEnvelope(typeName, bbox);
boundsIndex.put(typeName, result);
}
return result;
if (result == null) {
Layer layer = spatialDatabase.getLayer(typeName);
if (layer != null) {
Envelope bbox = Utilities.fromNeo4jToJts(layer.getIndex().getBoundingBox());
result = convertEnvelopeToRefEnvelope(typeName, bbox);
boundsIndex.put(typeName, result);
}
}
return result;
}

public SpatialDatabaseService getSpatialDatabaseService() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.geotools.feature.simple.SimpleFeatureBuilder;
import org.neo4j.gis.spatial.Layer;
import org.neo4j.gis.spatial.SpatialDatabaseRecord;
import org.neo4j.graphdb.Transaction;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;

Expand Down Expand Up @@ -76,30 +77,39 @@ public SimpleFeatureType getFeatureType() {
*
*/
public boolean hasNext() throws IOException {
return results != null && results.hasNext();
if (results == null) return false;
try (Transaction tx = layer.getSpatialDatabase().getDatabase().beginTx()) {
boolean ans = results.hasNext();
tx.success();
return ans;
}
}

/**
*
*/
public SimpleFeature next() throws IOException, IllegalArgumentException, NoSuchElementException {
if (results == null) return null;

SpatialDatabaseRecord record = results.next();
if (record == null) return null;

builder.reset();
builder.set(FEATURE_PROP_GEOM, record.getGeometry());

if (extraPropertyNames != null) {
for (int i = 0; i < extraPropertyNames.length; i++) {
if (record.hasProperty(extraPropertyNames[i])) {
builder.set(extraPropertyNames[i], record.getProperty(extraPropertyNames[i]));
}
}
}

return builder.buildFeature(record.getId());

try (Transaction tx = layer.getSpatialDatabase().getDatabase().beginTx()) {
SpatialDatabaseRecord record = results.next();
if (record == null) return null;

builder.reset();

builder.set(FEATURE_PROP_GEOM, record.getGeometry());

if (extraPropertyNames != null) {
for (int i = 0; i < extraPropertyNames.length; i++) {
if (record.hasProperty(extraPropertyNames[i])) {
builder.set(extraPropertyNames[i], record.getProperty(extraPropertyNames[i]));
}
}
}
tx.success();

return builder.buildFeature(record.getId());
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public Layer createLayer(String name, Class<? extends GeometryEncoder> geometryE

Layer layer = DefaultLayer.makeLayerAndNode(this, name, geometryEncoderClass, layerClass);
getSpatialRoot().createRelationshipTo(layer.getLayerNode(), SpatialRelationshipTypes.LAYER);
if (encoderConfig != null) {
if (encoderConfig != null && encoderConfig.length() > 0) {
GeometryEncoder encoder = layer.getGeometryEncoder();
if (encoder instanceof Configurable) {
((Configurable) encoder).setConfiguration(encoderConfig);
Expand Down
103 changes: 53 additions & 50 deletions src/main/java/org/neo4j/gis/spatial/osm/OSMImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,6 @@ public String[] getTags()
ArrayList<String> tags = new ArrayList<String>();
for ( String key : stats.keySet() )
{
if ( key.equals( "waterway" ) )
{
System.out.println( "debug[" + key + "]: "
+ stats.get( key ) );
}
if ( stats.get( key ) > threshold ) tags.add( key );
}
Collections.sort( tags );
Expand Down Expand Up @@ -243,9 +238,9 @@ public void reIndex( GraphDatabaseService database, int commitInterval,
{
if ( commitInterval < 1 )
throw new IllegalArgumentException( "commitInterval must be >= 1" );
System.out.println( "Re-indexing with GraphDatabaseService: "
+ database + " (class: " + database.getClass()
+ ")" );
log("Re-indexing with GraphDatabaseService: "
+ database + " (class: " + database.getClass()
+ ")");

setLogContext( "Index" );
SpatialDatabaseService spatialDatabase = new SpatialDatabaseService(
Expand Down Expand Up @@ -328,10 +323,12 @@ public void reIndex( GraphDatabaseService database, int commitInterval,
tx.close();
}

long stopTime = System.currentTimeMillis();
log( "info | Re-indexing elapsed time in seconds: "
+ ( 1.0 * ( stopTime - startTime ) / 1000.0 ) );
stats.dumpGeomStats();
if (verboseLog) {
long stopTime = System.currentTimeMillis();
log("info | Re-indexing elapsed time in seconds: "
+ (1.0 * (stopTime - startTime) / 1000.0));
stats.dumpGeomStats();
}
}

private static class GeometryMetaData
Expand Down Expand Up @@ -645,8 +642,6 @@ protected void createOSMNode( Map<String, Object> nodeProps )
createRelationship( currentNode, changesetNode,
OSMRelation.CHANGESET );
nodeCount++;
debugNodeWithId( currentNode, "node_osm_id", new long[] { 8090260,
273534207 } );
}

private void addOSMNodeTags( boolean allPoints,
Expand Down Expand Up @@ -701,10 +696,6 @@ protected void createOSMWay( Map<String, Object> wayProperties,
wayProperties.put( "name", name );
}
String way_osm_id = (String) wayProperties.get( "way_osm_id" );
if ( way_osm_id.equals( "28338132" ) )
{
System.out.println( "Debug way: " + way_osm_id );
}
T changesetNode = getChangesetNode( wayProperties );
T way = addNode( INDEX_NAME_WAY, wayProperties, "way_osm_id" );
createRelationship( way, changesetNode, OSMRelation.CHANGESET );
Expand Down Expand Up @@ -1862,7 +1853,7 @@ public void importFile( OSMWriter<?> osmWriter, String dataset,
boolean allPoints, Charset charset ) throws IOException,
XMLStreamException
{
System.out.println( "Importing with osm-writer: " + osmWriter );
log( "Importing with osm-writer: " + osmWriter );
osmWriter.getOrCreateOSMDataset( layerName );
osm_dataset = osmWriter.getDatasetId();

Expand Down Expand Up @@ -1972,12 +1963,12 @@ else if ( tagPath.equals( "[osm, relation, member]" ) )
{
if ( countXMLTags < 10 )
{
log( "Starting tag at depth " + depth + ": "
debug( "Starting tag at depth " + depth + ": "
+ currentXMLTags.get( depth ) + " - "
+ currentXMLTags.toString() );
for ( int i = 0; i < parser.getAttributeCount(); i++ )
{
log( "\t" + currentXMLTags.toString() + ": "
debug( "\t" + currentXMLTags.toString() + ": "
+ parser.getAttributeLocalName( i ) + "["
+ parser.getAttributeNamespace( i ) + ","
+ parser.getAttributePrefix( i ) + ","
Expand Down Expand Up @@ -2021,15 +2012,17 @@ else if ( currentXMLTags.toString().equals(
osmWriter.finish();
this.osm_dataset = osmWriter.getDatasetId();
}
describeTimes( startTime, times );
osmWriter.describeMissing();
osmWriter.describeLoaded();
if (verboseLog) {
describeTimes(startTime, times);
osmWriter.describeMissing();
osmWriter.describeLoaded();

long stopTime = System.currentTimeMillis();
log( "info | Elapsed time in seconds: "
long stopTime = System.currentTimeMillis();
log("info | Elapsed time in seconds: "
+ ( 1.0 * ( stopTime - startTime ) / 1000.0 ) );
stats.dumpGeomStats();
stats.printTagStats();
stats.dumpGeomStats();
stats.printTagStats();
}
}

private void describeTimes( long startTime, long[] times )
Expand Down Expand Up @@ -2148,49 +2141,59 @@ public static double distance( double lonA, double latA, double lonB,
return WGS84.orthodromicDistance( lonA, latA, lonB, latB );
}

private void log( PrintStream out, String message, Exception e )
{
if ( logContext != null )
{
private void log(PrintStream out, String message) {
if (logContext != null) {
message = logContext + "[" + contextLine + "]: " + message;
}
out.println( message );
if ( e != null )
{
e.printStackTrace( out );
out.println(message);
}

private void log(String message) {
if (verboseLog) {
log(System.out, message);
}
}

private void log( String message )
{
log( System.out, message, null );
private void debug(String message) {
if (debugLog) {
log(System.out, message);
}
}

private void error( String message )
{
log( System.err, message, null );
private void error(String message) {
log(System.err, message);
}

private void error( String message, Exception e )
{
log( System.err, message, e );
private void error(String message, Exception e) {
log(System.err, message);
e.printStackTrace(System.err);
}

private String logContext = null;
private int contextLine = 0;
private boolean debugLog = false;
private boolean verboseLog = true;

// "2008-06-11T12:36:28Z"
private DateFormat timestampFormat = new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss'Z'" );
"yyyy-MM-dd'T'HH:mm:ss'Z'");

private void setLogContext( String context )
{
public void setDebug(boolean verbose) {
this.debugLog = verbose;
this.verboseLog |= verbose;
}

public void setVerbose(boolean verbose) {
this.verboseLog = verbose;
this.debugLog &= verbose;
}

private void setLogContext(String context) {
logContext = context;
contextLine = 0;
}

private void incrLogContext()
{
private void incrLogContext() {
contextLine++;
}

Expand Down
Loading

0 comments on commit 635ed05

Please sign in to comment.