Package noaa.coastwatch.util
Class EarthArea
java.lang.Object
noaa.coastwatch.util.EarthArea
The
EarthArea
class represents irregularly shaped areas on a
sphere. In cases where simple north, south, east, and west bounds
are inadequate for describing an area, the earth area class may be
used to set up and query if a certain earth location is inside an
irregular shape. The area information is maintained using a set of
1x1 degree grid squares covering the entire globe. Each grid
square is referenced by its lower-left corner -- for example the
grid square (10, 20) covers the area between 10N to 11N and 20E to
21E. All earth locations must have a latitude range of [-90..90]
and longitude range of [-180..180).- Since:
- 3.1.1
- Author:
- Peter Hollemans
-
Nested Class Summary
Modifier and TypeClassDescriptionclass
The earth area iterator is used to loop over all grid squares in an earth area. -
Constructor Summary
ConstructorDescriptionCreates an empty earth area with no locations.EarthArea
(EarthTransform trans, DataLocation min, DataLocation max) Creates a new earth area from the specified parameters. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(EarthLocation loc) Adds an earth location to this area.void
addAll()
Adds all earth locations to this area.clone()
Creates an independent copy of this area.boolean
contains
(int[] square) Determines if a grid square is contained in this area.boolean
contains
(EarthLocation loc) Determines if an earth location is contained in this area.boolean
Returns true if this area exactly equals another area.void
expand()
Expands the current area by 1 degree in all directions.void
explore
(EarthTransform trans, DataLocation min, DataLocation max, EarthLocation start) Explores within data location boundaries using an earth transform to find all locations within an area.double
Gets the coverage of this area as a fraction of the total area of the earth.int[]
Gets the geographic extremes in this area.int
getIndex
(int lat, int lon) Computes a square index based on a grid square.int
getIndex
(EarthLocation loc) Computes a square index based on an earth location.Iterator<int[]>
Returns an iterator over the grid square elements.intersection
(EarthArea area) Computes the intersection between this area and another.boolean
isEmpty()
Returns true if this earth area contains no grid squares.Iterator<int[]>
iterator()
void
remove
(EarthLocation loc) Removes an earth location from this area.Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
EarthArea
public EarthArea()Creates an empty earth area with no locations. -
EarthArea
Creates a new earth area from the specified parameters. The parameters are used to perform an exploration of the area to include all earth locations. The exploration is started at the center of the data location boundaries. After exploration, an expansion of one grid square is performed.- Parameters:
trans
- an earth transform to use for exploration.min
- the minimum data location to explore.max
- the maximum data location to explore.
-
-
Method Details
-
getCoverage
public double getCoverage()Gets the coverage of this area as a fraction of the total area of the earth. The coverage is an estimate based on the 1x1 degree grid squares coveraged by the area.- Returns:
- the coverage of this area as a fraction in the range [0..1].
- Since:
- 3.8.0
-
intersection
Computes the intersection between this area and another. The resulting area includes only grid squares which occur both in this area and in the other area.- Parameters:
area
- the other earth area to compute the intersection.- Returns:
- a new earth area containing only grid squares in common.
-
isEmpty
public boolean isEmpty()Returns true if this earth area contains no grid squares. -
getIterator
Returns an iterator over the grid square elements. Each object returned by the iterator contains the lower-leftint[]
coordinates of the grid square as [lat, lon]. -
iterator
-
contains
Determines if an earth location is contained in this area.- Parameters:
loc
- the earth location to search for.- Returns:
- true if earth location is in this area, or false if not.
-
contains
public boolean contains(int[] square) Determines if a grid square is contained in this area.- Parameters:
square
- the grid square lower-left corner as [lat, lon].- Returns:
- true if grid square is in this area, or false if not.
-
add
Adds an earth location to this area.- Parameters:
loc
- the earth location to add.
-
addAll
public void addAll()Adds all earth locations to this area. -
remove
Removes an earth location from this area.- Parameters:
loc
- the earth location to remove.
-
getIndex
public int getIndex(int lat, int lon) Computes a square index based on a grid square.- Parameters:
lat
- the grid square lower-left corner latitude in the range [-90,89].lon
- the grid square lower-left corner longitude in the range [-180,179].- Returns:
- the index for the square or -1 if the grid square is invalid.
-
getIndex
Computes a square index based on an earth location.- Parameters:
loc
- the earth location to convert.- Returns:
- the index for the square or -1 if the earth location is invalid.
-
expand
public void expand()Expands the current area by 1 degree in all directions. If the current area is as follows:. . . . . . . . . . . . . . * * . . . * * . . . . . * . . . . . . . . . . . . . . .
then the expanded area includes the boundary points:. . . . . . . x x x x . x x * * x . x * * x x . x x * x . . . x x x . . . . . . . .
-
explore
Explores within data location boundaries using an earth transform to find all locations within an area. The new grid squares are added to the area. The exploration terminates when squares that are already part of the area are encountered, the data location boundaries are hit, or the earth transform returns an invalid data location.- Parameters:
trans
- an earth transform to use for exploration.min
- the minimum data location to explore.max
- the maximum data location to explore.start
- the starting earth location for exploration.
-
getExtremes
public int[] getExtremes()Gets the geographic extremes in this area. If this earth area crosses the 180E/180W border, the east and west extremes are adjusted so they both fall in the range [0..360]. Otherwise they fall in the range [-180..180].- Returns:
- the geographic extremes as [north, south, east, west].
-
equals
Returns true if this area exactly equals another area. -
clone
Creates an independent copy of this area.
-