neo4j-contrib / spatial

Neo4j Spatial is a library of utilities for Neo4j that faciliates the enabling of spatial operations on data. In particular you can add spatial indexes to already located data, and perform spatial operations on the data like searching for data within specified regions or within a specified distance of a point of interest. In addition classes are provided to expose the data to geotools and thereby to geotools enabled applications like geoserver and uDig.
http://neo4j-contrib.github.io/spatial
Other
777 stars 191 forks source link

Add Index Configuration Feature to Neo4j Spatial #410

Open Andy2003 opened 1 month ago

Andy2003 commented 1 month ago

Overview

This PR introduces a new feature allowing users to configure spatial indexes in Neo4j Spatial. Previously, it was not possible to index the same Node with two separate indexes. This update addresses that limitation by introducing customizable index configurations, including a new referenceRelationshipType option.

Key Changes:

Index Configuration Options:

Code Enhancements:

Tests and Validation:

Usage:

// create 1st index
CALL spatial.addLayer('point1','NativePoint','point1:point1BB', '{"referenceRelationshipType": "RTREE_P1_TYPE"}')

// create 2nd index
CALL spatial.addLayer('point2','NativePoint','point2:point2BB', '{"referenceRelationshipType": "RTREE_P2_TYPE"}')

Now you can add the same Node to both indexes:

UNWIND range(1,$count) as i
CREATE (n:Point {
    id: i,
    point1: point( { latitude: 56.0, longitude: 12.0 } ),
    point2: point( { latitude: 57.0, longitude: 13.0 } )
})

MATCH (p:Point)
WITH (count(p) / 10) AS pages, collect(p) AS nodes
UNWIND range(0, pages) AS i CALL {
    WITH i, nodes
    CALL spatial.addNodes('point1', nodes[(i * 10)..((i + 1) * 10)]) YIELD count
    RETURN count AS count
} IN TRANSACTIONS OF 1 ROWS
RETURN sum(count) AS count

MATCH (p:Point)
WITH (count(p) / 10) AS pages, collect(p) AS nodes
UNWIND range(0, pages) AS i CALL {
    WITH i, nodes
    CALL spatial.addNodes('point2', nodes[(i * 10)..((i + 1) * 10)]) YIELD count
    RETURN count AS count
} IN TRANSACTIONS OF 1 ROWS
RETURN sum(count) AS count