jnidzwetzki / spatial-index-java

Spatial indexing algorithms for java
Apache License 2.0
16 stars 2 forks source link
index n-dimensional r-tree spatial-index

Spatial indexing algorithms for java (sia4j)

Implementation of spatial indexing algorithms in java. At the moment, only an r-tree index is implemented by this project.

Build Status

Features of the R-tree implementation

Examples

Building the r-tree and execute a rane query

// Two entries with a two-dimensional bounding box
final SpatialIndexEntry entry1 = new SpatialIndexEntry(new Hyperrectangle(1d, 2d, 1d, 2d), "abc");
final SpatialIndexEntry entry2 = new SpatialIndexEntry(new Hyperrectangle(10d, 20d, 10d, 20d), "def");

final SpatialIndexBuilder index = new RTreeBuilder();
index.bulkInsert(Arrays.asList(entry1, entry2);

// Query data
final Hyperrectangle queryBox = new Hyperrectangle(1d, 1.5d, 1d, 1.5d);
final List<? extends SpatialIndexEntry> resultList = index.getEntriesForRegion(queryBox);

Write the r-tree into a file and read into memory

// Write and read to file
final File tempFile = File.createTempFile("rtree-", "-test");
final RandomAccessFile raf = new RandomAccessFile(tempFile, "rw");      
index.writeToFile(raf);
raf.close();

final AbstractRTreeReader indexRead = new RTreeMemoryReader();
final RandomAccessFile rafRead = new RandomAccessFile(tempFile, "r");
indexRead.readFromFile(rafRead);
rafRead.close();

Write the r-tree into a file and access the file via memory mapped io

// Write and read to file
final File tempFile = File.createTempFile("rtree-", "-test");
final RandomAccessFile raf = new RandomAccessFile(tempFile, "rw");      
index.writeToFile(raf);
raf.close();

final AbstractRTreeReader indexRead = new RTreeMMFReader();
final RandomAccessFile rafRead = new RandomAccessFile(tempFile, "r");
indexRead.readFromFile(rafRead);
rafRead.close();