Neo4j Community Edition - The world's leading Graph Database with Cypher query language and ACID transactions.
—
Neo4j's spatial data types provide support for geographic and geometric data with point representations, coordinate systems, and spatial operations for location-aware applications.
Represents a point in space with coordinates and coordinate reference system (CRS) information.
/**
* Represents a point in space with coordinates and CRS
*/
public interface Point {
/**
* Get the coordinate reference system for this point
* @return CRS information
*/
CRS getCRS();
/**
* Get the coordinates of this point
* @return List of coordinate values
*/
List<Coordinate> getCoordinates();
/**
* Get the spatial dimension of this point
* @return Number of dimensions (2D, 3D, etc.)
*/
int getDimension();
/**
* Get the SRID (Spatial Reference Identifier)
* @return SRID value
*/
int getSRID();
}Represents a single coordinate value within a point.
/**
* Represents a coordinate value
*/
public interface Coordinate {
/**
* Get the coordinate value
* @return Coordinate value as double
*/
double getCoordinate();
}Defines the coordinate reference system for spatial data.
/**
* Coordinate Reference System definition
*/
public interface CRS {
/**
* Get the CRS code (e.g., 4326 for WGS-84)
* @return CRS code
*/
int getCode();
/**
* Get the CRS type (e.g., "link", "name")
* @return CRS type string
*/
String getType();
/**
* Get additional CRS properties
* @return Map of CRS properties
*/
Map<String, Object> getProperties();
/**
* Get the coordinate system URL or identifier
* @return CRS href or name
*/
String getHref();
}Base interface for geometric objects (extends spatial functionality).
/**
* Base interface for geometric objects
*/
public interface Geometry {
/**
* Get the geometry type (e.g., "Point", "LineString", "Polygon")
* @return Geometry type string
*/
String getGeometryType();
/**
* Get the coordinate reference system
* @return CRS information
*/
CRS getCRS();
/**
* Check if this geometry is empty
* @return true if geometry contains no points
*/
boolean isEmpty();
}Usage Examples:
import org.neo4j.graphdb.spatial.Point;
import org.neo4j.graphdb.spatial.CRS;
import org.neo4j.graphdb.spatial.Coordinate;
// Creating spatial queries with points
try (Transaction tx = graphDb.beginTx()) {
// Create a node with a point property (latitude/longitude)
Node location = tx.createNode(label("Location"));
location.setProperty("name", "New York City");
// Point will be created by Neo4j spatial functions in Cypher
String createPointQuery = """
MATCH (loc:Location {name: 'New York City'})
SET loc.coordinates = point({latitude: 40.7128, longitude: -74.0060})
RETURN loc.coordinates as point
""";
Result result = tx.execute(createPointQuery);
if (result.hasNext()) {
Map<String, Object> record = result.next();
Point point = (Point) record.get("point");
// Access point properties
System.out.println("CRS Code: " + point.getCRS().getCode());
System.out.println("Coordinates: " + point.getCoordinates());
System.out.println("Dimensions: " + point.getDimension());
}
tx.commit();
}
// Spatial distance queries
try (Transaction tx = graphDb.beginTx()) {
String spatialQuery = """
MATCH (loc:Location)
WHERE distance(loc.coordinates, point({latitude: 40.7589, longitude: -73.9851})) < 5000
RETURN loc.name, loc.coordinates,
distance(loc.coordinates, point({latitude: 40.7589, longitude: -73.9851})) as distance
ORDER BY distance
""";
Result spatialResults = tx.execute(spatialQuery);
spatialResults.forEachRemaining(record -> {
String name = (String) record.get("loc.name");
Point coordinates = (Point) record.get("loc.coordinates");
Double distance = (Double) record.get("distance");
System.out.printf("Location: %s, Distance: %.2f meters%n", name, distance);
});
tx.commit();
}Neo4j provides built-in spatial functions for working with points:
point({latitude: lat, longitude: lon}) - Create a WGS-84 pointpoint({x: x, y: y}) - Create a Cartesian pointpoint({x: x, y: y, crs: 'cartesian-3d', z: z}) - Create a 3D Cartesian pointdistance(point1, point2) - Calculate distance between two pointspoint.latitude, point.longitude, point.x, point.y - Access coordinate componentsCommon CRS codes used in Neo4j:
Install with Tessl CLI
npx tessl i tessl/maven-org-neo4j--neo4j