Class SpatialGrid

java.lang.Object
ucar.unidata.gis.SpatialGrid

public class SpatialGrid extends Object
Fast implementation for tracking data overlap and closest point in a 2D region. The region of interest is divided into non-overlapping cells. Each cell may contain zero or one data objects. This allows quickly finding if a data object may be drawn (markIfClear) and closest drawn object to a point (findClosest).
Version:
$Id: SpatialGrid.java,v 1.14 2005/05/13 18:29:33 jeffmc Exp $
Author:
caron, with design help from russ
  • Constructor Details

    • SpatialGrid

      public SpatialGrid(int nx, int ny)
      Constructor
      Parameters:
      nx - maximum number of grid columns
      ny - maximum number of grid rows
  • Method Details

    • setGrid

      public void setGrid(Rectangle2D bbox, Rectangle2D cellSize)
      Set the grid scale.
      Parameters:
      bbox - bounding box we are only interested in points inside of this
      cellSize - divide the bounding box into cells of this size. maximum number of grid cells is nx x ny
    • setOverlap

      public void setOverlap(int overlap)
      Set how much the data may overlap.
      Parameters:
      overlap - percent overlap
    • print

      public void print()
      print the grid
    • clear

      public void clear()
      clear all the grid cells
    • markIfClear

      public boolean markIfClear(Rectangle2D rect, Object o)
      Check if the given rect intersects an already drawn one. If not, set the corresponding cell as marked, store object, return true, meaning "ok to draw".
      Parameters:
      rect - the bounding box of the thing we want to draw
      o - store this object
      Returns:
      true if inside the bounding box and no intersection
    • findClosest

      public Object findClosest(Point2D pt)
      Find the closest marked cell to the given point
      Parameters:
      pt - find the closest marked cell to this point
      Returns:
      the object associated with the closest cell, or null if none