2013-08-17 51 views
1

我一直在努力为我的项目使用Neo4j Spatial,但我无法使它工作。Neo4j空间:不能运行空间

由于有限的文档和示例,我想出了如何将OSM映射加载到数据库。但是为了检查它是否被加载,我试图执行空间查询。

试图运行我的代码,我得到这个错误:

import.java:69: error: cannot access GremlinGroovyPipeline 
         .startIntersectSearch(layer, bbox) 
         ^
class file for com.tinkerpop.gremlin.groovy.GremlinGroovyPipeline not found 

我明白了什么是错的(它无法找到所需的库),但我不知道如何解决它。原因是当我运行Neo4j Spatial测试时,LayerTest.java和TestSpatial.java确实包含GeoPipeline库,并且它工作得很好。然而,当我创建我的简单java文件来测试Neo4j,并试图执行依赖GeoPipeline库的命令时,我得到了上面的错误。

我阅读GitHub上的指示Neo4j的,看到这样一个字条:

Note: neo4j-spatial has a mandatory dependency on GremlinGroovyPipeline from the com.tinkerpop.gremlin.groovy package. The dependency in neo4j is type 'provided', so when using neo4j-spatial in your own Java project, make sure to add the following dependency to your pom.xml, too.

不过,我没有使用Maven构建我的应用程序。这是一个简单的java文件,我想运行它来测试我是否知道一切正常。

这里是从我的java文件中的代码:

package org.neo4j.gis.spatial; 

import java.io.File; 
import java.io.IOException; 
import java.nio.charset.Charset; 
import java.util.ArrayList; 
import java.util.Arrays; 
import java.util.HashMap; 
import java.util.List; 
import java.util.Map; 

import org.geotools.data.DataStore; 
import org.geotools.data.neo4j.Neo4jSpatialDataStore; 
import org.geotools.data.simple.SimpleFeatureCollection; 
import org.neo4j.gis.spatial.osm.OSMDataset; 
import org.neo4j.gis.spatial.osm.OSMDataset.Way; 
import org.neo4j.gis.spatial.osm.OSMGeometryEncoder; 
import org.neo4j.gis.spatial.osm.OSMImporter; 
import org.neo4j.gis.spatial.osm.OSMLayer; 
import org.neo4j.gis.spatial.osm.OSMRelation; 
import org.neo4j.gis.spatial.pipes.osm.OSMGeoPipeline; 
import org.neo4j.graphdb.Direction; 
import org.neo4j.graphdb.Node; 
import org.neo4j.graphdb.Relationship; 

import com.vividsolutions.jts.geom.Envelope; 
import com.vividsolutions.jts.geom.Geometry; 

import org.neo4j.kernel.impl.batchinsert.BatchInserter; 
import org.neo4j.kernel.impl.batchinsert.BatchInserterImpl; 
import org.neo4j.kernel.EmbeddedGraphDatabase; 
import org.neo4j.graphdb.GraphDatabaseService; 
import org.neo4j.gis.spatial.pipes.GeoPipeline; 

class SpatialOsmImport { 
    public static void main(String[] args) 
    { 
     OSMImporter importer = new OSMImporter("ott.osm"); 
     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 = new BatchInserterImpl("target/dependency", config); 
     importer.setCharset(Charset.forName("UTF-8")); 
     try{ 
      importer.importFile(batchInserter, "ott.osm", false); 
      batchInserter.shutdown(); 
      GraphDatabaseService db = new EmbeddedGraphDatabase("target/dependency"); 
      importer.reIndex(db, 10000); 
      db.shutdown(); 
     } 
     catch(Exception e) 
     { 
      System.out.println(e.getMessage()); 
     } 

     GraphDatabaseService database = new EmbeddedGraphDatabase("target/dependency"); 
     try{ 
      SpatialDatabaseService spatialService = new SpatialDatabaseService(database); 
      Layer layer = spatialService.getLayer("layer_roads"); 
      LayerIndexReader spatialIndex = layer.getIndex(); 
      System.out.println("Have " + spatialIndex.count() + " geometries in " + spatialIndex.getBoundingBox()); 

      Envelope bbox = new Envelope(-75.80, 45.19, -75.7, 45.23); 
      // Search searchQuery = new SearchIntersectWindow(bbox); 
      // spatialIndex.executeSearch(searchQuery); 
      // List<SpatialDatabaseRecord> results = searchQuery.getResults(); 
      List<SpatialDatabaseRecord> results = GeoPipeline 
         .startIntersectSearch(layer, bbox) 
         .toSpatialDatabaseRecordList(); 
      doGeometryTestsOnResults(bbox, results); 
     } finally { 
      database.shutdown(); 
     } 
    } 
    private static void doGeometryTestsOnResults(Envelope bbox, List<SpatialDatabaseRecord> results) { 
     System.out.println("Found " + results.size() + " geometries in " + bbox); 
     Geometry geometry = results.get(0).getGeometry(); 
     System.out.println("First geometry is " + geometry); 
     geometry.buffer(2); 
    } 

} 

这是非常简单的权利,但我不能使它发挥作用。如何在我的应用程序中包含com.tinkerpop.gremlin.groovy.GremlinGroovyPipeline,因此它有效?

我在Ubuntu 12.04和Java版本“1.7.0_25”,Java(TM)SE运行时环境(build 1.7.0_25-b15)上运行了所有东西。

任何帮助,非常感谢。

回答

0

让所有的地方所需要的依赖,你可以将它们包含在类路径的最佳方法是运行

mvn dependency:copy-dependencies 
在Neo4j的空间

,并找到库的目标/ DEPS包括,请参阅http://maven.apache.org/plugins/maven-dependency-plugin/usage.html

+0

尽管如此,我仍然认为我做得不对。我曾尝试使用maven创建我自己的项目并包含依赖项,但我仍然失败。 在上面的例子中,我刚刚创建了一个java文件,并试图通过它导入所有内容。哪个不行。我尝试了你的建议,但我仍然无法弄清楚如何使它工作。你有没有关于如何在neo4j空间上构建应用的教程? – rahanar

+0

如果你不使用maven构建,你仍然可以从他们的仓库获得依赖关系。转到[Maven Central](http://search.maven.org)并搜索诸如'g:“com.tinkerpop.gremlin”和a:“gremlin-groovy”'之类的东西。找到正确的版本并将其放在你的类路径中。 – jjaderberg