Neo4j Spatial数据导入
  KCokDZgOiPyZ 2023年11月02日 46 0


首先,安装neo4j数据库。我的开发环境是Ubuntu,安装过程参考官网:​​Neo4j Debian Packages​​​,安装后配置:​​Post-installation tasks​​。

然后安装Neo4j Spatial的插件,参加Github介绍:​​neo4j-contrib/spatial​​。即把下载的文件解压到安装目录的plugins目录下$NEO4J_HOME/plugins。

接下来,我们使用Java代码在客户端插入数据到neo4j数据库。
我使用Maven构建工程(需要使用Java8进行maven编译)。pom文件如下:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>cn.tzy</groupId>
<artifactId>neo4j</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>neo4j</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<repositories>
<repository>
<id>repo2.maven.org</id>
<name>maven2 repository</name>
<url>http://repo2.maven.org/maven2/</url>
</repository>
<repository>
<id>osgeo</id>
<name>Open Source Geospatial Foundation Repository</name>
<url>http://download.osgeo.org/webdav/geotools/</url>
</repository>
<repository>
<id>neo4j-contrib-releases</id>
<url>https://raw.github.com/neo4j-contrib/m2/master/releases</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>neo4j-contrib-snapshots</id>
<url>https://raw.github.com/neo4j-contrib/m2/master/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>3.0.4</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-spatial</artifactId>
<version>0.23-neo4j-3.0.4</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

导入shapefile文件的代码入下:

package cn.tzy.neo4j;

import java.io.File;
import java.io.IOException;

import org.neo4j.gis.spatial.ShapefileImporter;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;

public class Neo4jEx {

public static void main(String[] args) throws IOException {
File storeDir = new File("C:/Users/theone/Desktop/spatial.db");
GraphDatabaseService database = new GraphDatabaseFactory().newEmbeddedDatabase(storeDir);

try (Transaction tx = database.beginTx()) {
ShapefileImporter importer = new ShapefileImporter(database);
importer.importFile("F:/2016/Data/World/continent.shp", "continent");

tx.success();
} finally {
database.shutdown();


【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  kG7ef0NqClb6   2023年11月13日   28   0   0 java
  u2N3sQ7nC0dn   2023年11月13日   20   0   0 java
  rCd1NYtlhh0U   2023年11月13日   23   0   0 java
  rCd1NYtlhh0U   2023年11月13日   29   0   0 java
  Ydqp9G8hCwM0   2023年11月13日   27   0   0 java
KCokDZgOiPyZ
作者其他文章 更多