Package ucar.unidata.gis
Class SpatialGrid
java.lang.Object
ucar.unidata.gis.SpatialGrid
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
clear all the grid cellsfindClosest
(Point2D pt) Find the closest marked cell to the given pointboolean
markIfClear
(Rectangle2D rect, Object o) Check if the given rect intersects an already drawn one.void
print()
print the gridvoid
setGrid
(Rectangle2D bbox, Rectangle2D cellSize) Set the grid scale.void
setOverlap
(int overlap) Set how much the data may overlap.
-
Constructor Details
-
SpatialGrid
public SpatialGrid(int nx, int ny) Constructor- Parameters:
nx
- maximum number of grid columnsny
- maximum number of grid rows
-
-
Method Details
-
setGrid
Set the grid scale.- Parameters:
bbox
- bounding box we are only interested in points inside of thiscellSize
- 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
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 drawo
- store this object- Returns:
- true if inside the bounding box and no intersection
-
findClosest
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
-