Java Spatial Index
Java Makefile
Latest commit fc57cd1 Sep 30, 2015 @aled Merge pull request #38 from lipiji/patch-1
add maven dependency example

Build Status


The Java Spatial Index project aims to maintain a high performance Java version of the RTree spatial indexing algorithm as described in the 1984 paper "R-trees: A Dynamic Index Structure for Spatial Searching" by Antonin Guttman. (PDF on CiteSeerX)

The JSI spatial index is deliberately limited in features, and does a small number of things well. It particular, it is fast.

The code is open source, and released under the GNU Lesser General Public License, version 2.1 or later.


It is highly recommended to start by looking at the jsi-examples repository at

Briefly, you need to initialize the RTree like this:

// Create and initialize an rtree
SpatialIndex si = new RTree();

Then add some rectangles; each one has an ID.

final Rectangle[] rects = new Rectangle[100];
rects[0] = new Rectangle(0, 10, 0, 10);
rects[1] = new Rectangle(0, 11, 1, 20);
si.add(rects[0], 0);
si.add(rects[1], 1);

and finally query for the 3 nearest rectangles to (36.3, 84.3) by calling the nearestN() method.

  new Point(36.3f, 84.3f),      // the point for which we want to find nearby rectangles
  new TIntProcedure() {         // a procedure whose execute() method will be called with the results
    public boolean execute(int i) {"Rectangle " + i + " " + rects[i] + ", distance=" + rects[i].distance(p));
      return true;              // return true here to continue receiving results
  3,                            // the number of nearby rectangles to find
  Float.MAX_VALUE               // Don't bother searching further than this. MAX_VALUE means search everything

A binary distribution that contains the JSI jar and all the runtime dependencies is available from

Alternatively, maven users can use this repository in their pom.xml:

  <name>sourceforge jsi repository</name>



To build the JSI library from source, install maven 3 and run the following:

% cd <location-of-pom.xml>
% mvn package

This will generate the binary package (jsi-x.y.z.jar) in the target subdirectory.

The following is a list of useful maven targets:

eclipse:eclipse (generate eclipse project files; see below)
-Dtest=ReferenceCompareTest_10000 test
assembly:single (create package only)

To import the project into eclipse, run mvn eclipse:eclipse, and then set the M2_REPO variable in Window -> Preferences -> Java -> Build Path -> Classpath Variables to point to your local maven repository (e.g. ~/.m2/repository)


These are the steps needed to check that the JSI library is working correctly. Note this will take a very long time to run:

% cd <location-of-pom.xml>
% mvn test [This runs a short and quick test]
% mvn -Dtest=ReferenceCompareTest_1000 test [Long test]
% mvn -Dtest=ReferenceCompareTest_10000 test [Very long test]
% mvn -Dtest=ReferenceCompareTest_100000 test [Ridiculously long test]

If any errors occur, please raise an issue at