2 // Java Spatial Index Library
3 // Copyright (C) 2002 Infomatiq Limited
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 package com.infomatiq.jsi;
21 import java.util.Properties;
24 * Defines methods that must be implemented by all
25 * spatial indexes. This includes the RTree and its variants.
27 * @author aled.morris@infomatiq.co.uk
30 public interface SpatialIndex {
33 * Initializes any implementation dependent properties
34 * of the spatial index. For example, RTree implementations
35 * will have a NodeSize property.
37 * @param props The set of properties used to initialize the spatial index.
39 public void init(Properties props);
42 * Adds a new rectangle to the spatial index
44 * @param r The rectangle to add to the spatial index.
45 * @param id The ID of the rectangle to add to the spatial index.
46 * The result of adding more than one rectangle with
47 * the same ID is undefined.
49 public void add(Rectangle r, int id);
52 * Deletes a rectangle from the spatial index
54 * @param r The rectangle to delete from the spatial index
55 * @param id The ID of the rectangle to delete from the spatial
58 * @return true if the rectangle was deleted
59 * false if the rectangle was not found, or the
60 * rectangle was found but with a different ID
62 public boolean delete(Rectangle r, int id);
65 * Finds all rectangles that are nearest to the passed rectangle, and calls
66 * execute() on the passed IntProcedure for each one.
68 * @param p The point for which this method finds the
71 * @param ip The IntProcedure whose execute() method is is called
72 * for each nearest neighbour.
74 * @param distance The furthest distance away from the rectangle
75 * to search. Rectangles further than this will not be found.
77 * This should be as small as possible to minimise
80 * Use Float.POSITIVE_INFINITY to guarantee that the nearest rectangle is found,
81 * no matter how far away, although this will slow down the algorithm.
83 public void nearest(Point p, IntProcedure v, float distance);
86 * Finds all rectangles that intersect the passed rectangle.
88 * @param r The rectangle for which this method finds
89 * intersecting rectangles.
91 * @param ip The IntProcedure whose execute() method is is called
92 * for each intersecting rectangle.
94 public void intersects(Rectangle r, IntProcedure ip);
97 * Finds all rectangles contained by the passed rectangle.
99 * @param r The rectangle for which this method finds
100 * contained rectangles.
102 * @param v The visitor whose visit() method is is called
103 * for each contained rectangle.
105 public void contains(Rectangle r, IntProcedure ip);
108 * Returns the number of entries in the spatial index
114 * Returns the bounds of all the entries in the spatial index,
115 * or null if there are no entries.
117 public Rectangle getBounds();
120 * Returns a string identifying the type of
121 * spatial index, and the version number,
122 * eg "SimpleIndex-0.1"
124 public String getVersion();