Neo4j Spatial:不能运行空间 [英] Neo4j Spatial: can't run spatial

查看:180
本文介绍了Neo4j Spatial:不能运行空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在有限的文档和例子中,我想出了如何使用Neo4j Spatial来处理我的项目,但我无法完成工作。将OSM映射加载到数据库。但是为了检查它是否被加载,我试图执行空间查询。



尝试运行我的代码时,出现以下错误:

  import.java:69:error:can not 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库的命令时,我得到了上面的错误。

我读到了Neo4j的github上的说明,并看到了这个提示:


注意:neo4j-spatial对com.tinkerpop.gremlin.groovy包中的
GremlinGroovyPipeline具有强制依赖性。
neo4j中的依赖项是'provided'类型的,所以当在你自己的Java项目中使用
neo4j-spatial时,确保将以下
依赖项添加到你的pom.xml中。 / p>

但是,我没有使用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;
导入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;
$ b $ 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));
尝试{
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);
尝试{
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);
//搜索searchQuery = new SearchIntersectWindow(bbox);
// spatialIndex.executeSearch(searchQuery);
//列表< SpatialDatabaseRecord> results = searchQuery.getResults();
List< SpatialDatabaseRecord> results = GeoPipeline
.startIntersectSearch(layer,bbox)
.toSpatialDatabaseRecordList();
doGeometryTestsOnResults(bbox,results);
} finally {
database.shutdown();

$ b $ private static void doGeometryTestsOnResults(Envelope bbox,List< SpatialDatabaseRecord> results){
System.out.println(Found+ results.size()+ + bbox中的几何图形);
Geometry geometry = results.get(0).getGeometry();
System.out.println(第一个几何体是+几何体);
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)上运行了所有内容。



非常感谢任何帮助。

解决方案

最好的方法是在你可以将它们包含到你的类路径中的地方获得所有必需的依赖关系, p>

  mvn依赖:copy-dependencies 


在neo4j-spatial中为

,并找到要包含在目标/代码中的库,请参阅 http://maven.apache.org/plugins/maven-dependency-plugin/usage.html


I have been trying to work with Neo4j Spatial for my project, but I can't make it work.

With limited documentation and examples I figured out how to load OSM map to the database. But to check if it is loaded, I am trying to execute a spatial query.

While trying to run my code I get this error:

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

I understand what's wrong (it can't find the required library), but I don't know how to fix it. The reason is when I run Neo4j Spatial tests, LayerTest.java and TestSpatial.java do include GeoPipeline library and it works perfectly fine. However, when I created my simple java file to test Neo4j, and trying to execute commands that depend GeoPipeline library I get the error above.

I read the instructions on github for Neo4j and saw this note:

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.

However, I am not using Maven to build my app. It is a simple java file, that I want to run to test if I get how everything works.

here is the code from my java file:

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);
    }

}

It is very simple right now, but I can't make it work. How do I include com.tinkerpop.gremlin.groovy.GremlinGroovyPipeline in my app, so it works?

I run everything on Ubuntu 12.04 and java version "1.7.0_25", Java(TM) SE Runtime Environment (build 1.7.0_25-b15).

Any help is greatly appreciated.

解决方案

the best way to get all the required dependencies in a place where you can include them in your classpath is to run

mvn dependency:copy-dependencies

in neo4j-spatial, and find the libs to include in target/deps, see http://maven.apache.org/plugins/maven-dependency-plugin/usage.html

这篇关于Neo4j Spatial:不能运行空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆