return name + "\t" + duration;
}
}
private void runTestPointSetGeoptimaIntersection(String tracePath, String dbPath, String layerName, boolean testMultiPoint) throws ParseException, IOException, XMLStreamException {
GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(dbPath).setConfig( Neo4jTestCase.NORMAL_CONFIG ).newGraphDatabase();
SpatialDatabaseService spatial = new SpatialDatabaseService(graphDb);
System.out.println("Opened database with node count=" + ((GraphDatabaseAPI) graphDb).getDependencyResolver().resolveDependency(NodeManager.class).getNumberOfIdsInUse(Node.class));
System.out.println("Searching for '"+layerName+"' in "+spatial.getLayerNames().length+" layers:");
for(String name:spatial.getLayerNames()){
System.out.println("\t"+name);
}
//OSMLayer layer = (OSMLayer) spatial.getOrCreateLayer(layerName, OSMGeometryEncoder.class, OSMLayer.class);
Layer layer = spatial.getLayer(layerName);
assertNotNull("Layer index should not be null", layer.getIndex());
assertNotNull("Layer index envelope should not be null", layer.getIndex().getBoundingBox());
Envelope bbox = Utilities.fromNeo4jToJts(layer.getIndex().getBoundingBox());
TestOSMImport.debugEnvelope(bbox, layerName, Constants.PROP_BBOX);
TestOSMImport.checkIndexAndFeatureCount(layer);
HashMap<String,Performance> performances = new LinkedHashMap<String,Performance>();
// Import the sample data of points on a path (drive test)
ArrayList<Coordinate> coordinates = new ArrayList<Coordinate>();
BufferedReader locations = new BufferedReader(new FileReader(tracePath));
String line;
Performance performance = new Performance("import");
while ((line = locations.readLine()) != null) {
String[] fields = line.split("\\s");
if(fields.length>1) {
double latitude = Double.parseDouble(fields[0]);
double longitude = Double.parseDouble(fields[1]);
coordinates.add(new Coordinate(longitude,latitude));
}
}
locations.close();
performance.stop(coordinates.size());
performances.put(performance.name,performance);
// Slow Test, iterating over all Point objects
double distanceInKm = 0.01;
HashSet<Node> results = new HashSet<Node>();
System.out.println("Searching for geometries near "+coordinates.size()+" locations: " + coordinates.get(0) + " ... "
+ coordinates.get(coordinates.size() - 1));
performance = new Performance("search points");
try (Transaction tx = graphDb.beginTx()) {
for (Coordinate coordinate : coordinates) {
List<Node> res = GeoPipeline.startNearestNeighborLatLonSearch(layer, coordinate, distanceInKm)
.sort("OrthodromicDistance").toNodeList();
results.addAll(res);
}
printResults(results);
performance.stop(results);
tx.success();
}
performances.put(performance.name,performance);
System.out.println("Point search took "+performance.duration()+" seconds to find "+results.size()+" results");
// Faster tests with LineString and MultiPoint
GeometryFactory geometryFactory = new GeometryFactory();
CoordinateArraySequence cseq = new CoordinateArraySequence(coordinates.toArray(new Coordinate[0]));
HashMap<String,Geometry> testGeoms = new LinkedHashMap<String,Geometry>();
testGeoms.put("LineString", geometryFactory.createLineString(cseq));
testGeoms.put("LineString.buffer(0.001)", testGeoms.get("LineString").buffer(0.001));
testGeoms.put("LineString.buffer(0.0001)", testGeoms.get("LineString").buffer(0.0001));
testGeoms.put("LineString.buffer(0.00001)", testGeoms.get("LineString").buffer(0.00001));
testGeoms.put("Simplified.LS.buffer(0.0001)", TopologyPreservingSimplifier.simplify(testGeoms.get("LineString").buffer(0.0001),0.00005));
if (testMultiPoint) {
testGeoms.put("MultiPoint", geometryFactory.createMultiPoint(cseq));
testGeoms.put("MultiPoint.buffer(0.001)", testGeoms.get("MultiPoint").buffer(0.001));
testGeoms.put("MultiPoint.buffer(0.0001)", testGeoms.get("MultiPoint").buffer(0.0001));
testGeoms.put("MultiPoint.buffer(0.00001)", testGeoms.get("MultiPoint").buffer(0.00001));
testGeoms.put("Simplified.MP.buffer(0.0001)", TopologyPreservingSimplifier.simplify(testGeoms.get("MultiPoint").buffer(0.0001),0.00005));
}
for (Entry<String, Geometry> entry: testGeoms.entrySet()) {
String gname = entry.getKey();
Geometry geometry = entry.getValue();
System.out.println("Searching for geometries near Geometry: " + gname);
performance = new Performance(gname);
try (Transaction tx = graphDb.beginTx()) {
List<Node> res = runSearch(GeoPipeline.startIntersectSearch(layer, geometry), true);
performance.stop(res);
performances.put(performance.name,performance);
System.out.println("Geometry search took " + performance.duration() + " seconds to find " + res.size() + " results");
tx.success();
}
}
// Print summary of results
System.out.println("\nActivity\tDuration\tResults\tOverlap");
for(Performance perf: performances.values()) {
System.out.println(perf.name + "\t" + perf.duration() + "\t" + perf.count + "\t" + perf.overlaps(results));
}
// Finished
graphDb.shutdown();
}