2

Hello i'm new in neo4j and i would like to use OSM + Neo4j Spatial. I have a maven project and my Neo4j version is 2.3.0-M01

I have a simple code just for importing an OSM file but it displays some errors in the import files: GraphDatabaseService, EmbeddedGraphDatabase and BatchInserter.

package testOSM;

import java.nio.charset.Charset;
import org.neo4j.gis.spatial.osm.OSMImporter;

import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.kernel.EmbeddedGraphDatabase;
import org.neo4j.kernel.impl.batchinsert.BatchInserter;

public class TestOsm {

    private static final String DB_PATH = "/community/data/graph.db";

    public static void main(final String[] args){

        OSMImporter importer = new OSMImporter("clz_map.osm");
        importer.setCharset(Charset.forName("UTF-8"));
        BatchInserter batchInserter = BatchInserter.inserter(DB_PATH);

        try{
            importer.importFile(batchInserter, "clz_map.osm", false);
            GraphDatabaseService db = new EmbeddedGraphDatabase(DB_PATH);
            importer.reIndex(db);
            db.shutdown();
            }

        catch(Exception e){
            System.out.println(e.getMessage());
            }

        batchInserter.shutdown();    
    }  
}

May be my problem is with the versions, because i'm using Neo4j 2.3-M01, but i don't know exactly how should i set the versions e.g. here

<dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j-graph-collections</artifactId>
    <version>0.7.1-neo4j-2.0.2-SNAPSHOT</version>
    <type>jar</type>
</dependency>

My pom.xml is based on https://github.com/neo4j-contrib/spatial/blob/master/pom.xml

Plus:

 <repository>
    <id>neo4j</id>
    <url>http://m2.neo4j.org/content/repositories/releases/</url>
    <releases>
    <enabled>true</enabled>
    </releases>
  </repository>
<dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j</artifactId>
    <version>2.3.0-M01</version>
    <scope>provided</scope>
    </dependency>
    <dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j-kernel</artifactId>
    <version>2.3.0-M01</version>
 </dependency>

You can have a look into my git repository https://github.com/amhg/OSM

Thank you in advance!

marhg
  • 659
  • 1
  • 17
  • 30

3 Answers3

1

there are API changes since the last released version. Looking at https://github.com/neo4j-contrib/spatial/blob/master/pom.xml#L4 , it seems you can use Neo4j 2.2.3 if you build that project yourself with

mvn install

and then include version 0.15-neo4j-2.2.3 of the spatial plugin into your pom.xml from the local mvn repo.

Peter Neubauer
  • 6,311
  • 1
  • 21
  • 24
  • Thank you Peter, i didn't install maven correctly but now i set my maven environment, it took me some time due to some jdk versions. But now i'm able to run mvn install for my maven project and i also added the Spatial version – marhg Jul 30 '15 at 16:13
1

I took a look at your pom.xml and it looks like you copied the pom.xml from Neo4j Spatial. This is not what you want.

Since you are trying to write a new application that uses Neo4j Spatial, you should have a pom that is new and refers to neo4j-spatial as a dependency, not a pom that is in any way similar to the neo4j-spatial pom. There is a section in the README that describes how to add neo4j-spatial as a dependency to your own pom.

So I would suggest you do the following:

Craig Taverner
  • 759
  • 4
  • 5
  • Thank you Craig, know i understand how should i write my pom.xml file and what should it contained. – marhg Jul 30 '15 at 16:00
1

For anyone else that runs into this, here is how to do it: https://github.com/maxdemarzi/OSM

Notice a small differences between 2.2.x and 2.3 (7/30-currently on M2). Just needed the right dependencies.

Max De Marzi
  • 1,098
  • 6
  • 11
  • Thank you Max, i'm currently working with the new code. But there are some errors e.g. Exception in thread "main" java.lang.IllegalStateException: Misaligned file size 68 for DynamicArrayStore[fileName:neostore.nodestore.db.labels, blockSize:60], expected version length 25 at org.neo4j.kernel.impl.store.AbstractDynamicStore (and there are more packets displayed) ----AND--- Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (default-cli) on project MyOsm: Command execution failed. Process exited with an error: 1 (Exit value: 1) -> [Help 1] – marhg Jul 30 '15 at 16:17