Skip to content
Create a gist now

Instantly share code, notes, and snippets.

neo4j spatial football stadiums
package org.neo4j.gis.spatial;
import org.neo4j.gis.spatial.indexprovider.SpatialIndexProvider;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.index.Index;
import org.neo4j.kernel.EmbeddedGraphDatabase;
import java.util.ArrayList;
import java.util.List;
public class SampleSpatialGraph {
public static void main(String[] args) throws IOException {
List<String> lines = readFile("/path/to/stadiums.csv");
EmbeddedGraphDatabase db = new EmbeddedGraphDatabase("/path/to/neo4j-community-1.9.M05/data/graph.db");
Index<Node> index = createSpatialIndex(db, "stadiumsLocation");
Transaction tx = db.beginTx();
for (String stadium : lines) {
String[] columns = stadium.split(",");
Node stadiumNode = db.createNode();
stadiumNode.setProperty("wkt", String.format("POINT(%s %s)", columns[4], columns[3]));
stadiumNode.setProperty("name", columns[0]);
index.add(stadiumNode, "dummy", "value");
private static Index<Node> createSpatialIndex(EmbeddedGraphDatabase db, String indexName) {
return db.index().forNodes(indexName, SpatialIndexProvider.SIMPLE_WKT_CONFIG);
private static List<String> readFile(String stadiumsFile) throws IOException {
List<String> lines = new ArrayList<String>();
BufferedReader br = new BufferedReader(new FileReader(stadiumsFile));
String line = br.readLine();
while (line != null) {
line = br.readLine();
return lines;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.