|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.opensha.commons.geo.Region
org.opensha.commons.geo.GriddedRegion
public class GriddedRegion
A GriddedRegion is a Region that has been
discretized in latitude and longitude. Each node in a gridded region
represents a small area that is some number of degrees in width and height
and is identified by a unique Location at the geographic (lat-lon)
center of the node.
In the adjacent figure,
the heavy black line marks the border of the Region . The light
gray dots mark the Locations of nodes outside the region, and
black dots those inside the region. The dashed grey line marks the border,
inside which, a Location will be associated with a grid node.
See indexForLocation(Location) for more details on
rules governing whether a grid node is inside a region and whether a
Location will be associated with a grid node.
A GriddedRegion may be initialized several ways (e.g. as a
circle, an area of uniform degree-width and -height, or a buffer around a
linear feature). See constructor documentation for illustrative examples.
Each constructor comes in two formats, one that takes a single 'spacing'
value, and one that takes two spacing values, one each for latitude and
longitude.
The Locations of the grid nodes are indexed internally in order
of increasing longitude then latitude starting with the node at the lowest
latitude and longitude in the region. GriddedRegions are
iterable as a shorthand for getNodeList().iterator().
To ensure grid nodes fall on specific lat-lon values, all constructors take
an anchor Location argument. This location can be anywhere in-
or outside the region to be gridded. If the region contains the anchor
location, the anchor will coincide with a grid node. For example, given a
grid spacing of 1° and an anchor Location of 22.1°N
-134.7°W, grid nodes within any region will fall at whole valued
latitudes + 0.1° and longitudes - 0.7°. If an anchor
Location is null, it is automatically set as the
Location defined by the minimum latitude and longitude of the region's
border.
NOTE: Due to rounding errors and the use of
an Area internally to define a Region's border,
Region.contains(Location) may not always return the expected result
near a border. See Region.contains(Location) for further details. For
a GriddedRegion, this results in values returned by calls
getMinGridLat() etc. for which there may not be any grid nodes. To
guarantee node coverage for a GriddedRegion, say for eventual
map output, 'best-practice' dictates expanding a region slightly.
Region,
Serialized Form| Field Summary | |
|---|---|
static Location |
ANCHOR_0_0
Convenience reference for an anchor at (0°, 0°). |
static String |
XML_METADATA_ANCHOR_NAME
|
static String |
XML_METADATA_GRID_SPACING_NAME
|
static String |
XML_METADATA_NAME
|
static String |
XML_METADATA_NUM_POINTS_NAME
|
| Fields inherited from class org.opensha.commons.geo.Region |
|---|
XML_METADATA_OUTLINE_NAME |
| Constructor Summary | |
|---|---|
GriddedRegion(Location center,
double radius,
double latSpacing,
double lonSpacing,
Location anchor)
Initializes a circular GriddedRegion. |
|
GriddedRegion(Location center,
double radius,
double spacing,
Location anchor)
Initializes a circular GriddedRegion. |
|
GriddedRegion(LocationList border,
BorderType type,
double latSpacing,
double lonSpacing,
Location anchor)
Initializes a GriddedRegion from a list of border locations. |
|
GriddedRegion(LocationList border,
BorderType type,
double spacing,
Location anchor)
Initializes a GriddedRegion from a list of border locations. |
|
GriddedRegion(LocationList line,
double buffer,
double latSpacing,
double lonSpacing,
Location anchor)
Initializes a GriddedRegion as a buffered area around a
line. |
|
GriddedRegion(LocationList line,
double buffer,
double spacing,
Location anchor)
Initializes a GriddedRegion as a buffered area around a
line. |
|
GriddedRegion(Location loc1,
Location loc2,
double latSpacing,
double lonSpacing,
Location anchor)
Initializes a GriddedRegion from a pair of
Locations. |
|
GriddedRegion(Location loc1,
Location loc2,
double spacing,
Location anchor)
Initializes a GriddedRegion from a pair of
Locations. |
|
GriddedRegion(Region region,
double latSpacing,
double lonSpacing,
Location anchor)
Initializes a GriddedRegion with a Region. |
|
GriddedRegion(Region region,
double spacing,
Location anchor)
Initializes a GriddedRegion with a Region. |
|
| Method Summary | |
|---|---|
void |
addInterior(Region region)
Overridden to throw an UnsupportedOperationException when
called. |
Area |
areaForIndex(int index)
Returns the Region that bounds a node |
GriddedRegion |
clone()
Returns an exact, independent copy of this GriddedRegion. |
boolean |
equals(Object obj)
|
boolean |
equalsRegion(GriddedRegion gr)
Compares this GriddedRegion to another and returns
true if they are the same with respect to aerial extent
(both exterior and interior borders), grid node spacing, and location. |
static GriddedRegion |
fromXMLMetadata(Element root)
Initializes a new Region from stored metadata. |
double |
getLatSpacing()
Returns the longitudinal grid node spacing for this region. |
Location |
getLocation(int index)
Alternative to locationForIndex(int index) |
double |
getLonSpacing()
Returns the latitudinal grid node spacing for this region. |
double |
getMaxGridLat()
Returns the maximum grid latitude. |
double |
getMaxGridLon()
Returns the maximum grid longitude. |
double |
getMinGridLat()
Returns the minimum grid latitude. |
double |
getMinGridLon()
Returns the minimum grid longitude. |
int |
getNodeCount()
Returns the total number of grid nodes in this region. |
LocationList |
getNodeList()
Returns the locations of all the nodes in the region as a LocationList. |
int |
getNumLocations()
Alternative to getNodeCount(). |
double |
getSpacing()
Returns the grid node spacing for this region. |
int |
hashCode()
|
int |
indexForLocation(Location loc)
Returns the index of the grid node associated with a given Location or -1 if the associated grid node is ouside this
gridded region. |
List<Integer> |
indicesForBounds(Rectangle2D rect)
Returns the list of grid indices spanned by the bounds of the supplied region. |
boolean |
isEmpty()
Returns whether this region contains any grid nodes. |
boolean |
isSpacingUniform()
Returns whether the lat and lon spacing are the same. |
Iterator<Location> |
iterator()
|
Location |
locationForIndex(int index)
Returns the Location at a given grid index. |
int |
move(int idx,
Direction dir)
Returns the index of the node at the supplied Direction from
the node at the supplied index. |
GriddedRegion |
subRegion(Region region)
Creates a new GriddedRegion from this (the parent) and
another Region. |
Element |
toXMLMetadata(Element root)
|
| Methods inherited from class org.opensha.commons.geo.Region |
|---|
contains, contains, distanceToLocation, equalsRegion, getBorder, getExtent, getGlobalRegion, getInteriors, getMaxLat, getMaxLon, getMinLat, getMinLon, getName, getShape, intersect, isRectangular, main, setName, toString, toXMLMetadata, union |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final String XML_METADATA_NAME
public static final String XML_METADATA_GRID_SPACING_NAME
public static final String XML_METADATA_ANCHOR_NAME
public static final String XML_METADATA_NUM_POINTS_NAME
public static final Location ANCHOR_0_0
| Constructor Detail |
|---|
public GriddedRegion(Location loc1,
Location loc2,
double latSpacing,
double lonSpacing,
Location anchor)
GriddedRegion from a pair of
Locations. When viewed in a Mercator projection, the region will
be a rectangle. If either both latitude or both longitude values are the
same, an exception is thrown.Shape interface, Locations that fall on northern or
eastern borders of this region are considered inside. See
Region.Region(Location, Location) for implementation details.
loc1 - the first Locationloc2 - the second LocationlatSpacing - of grid nodeslonSpacing - of grid nodesanchor - Location for grid; may be null
IllegalArgumentException - if the latitude or longitude values in
the Locations provided are the same or
spacing is outside the range 0° <
spacing
≤ 5°
NullPointerException - if either Location argument is
nullRegion.Region(Location, Location)
public GriddedRegion(Location loc1,
Location loc2,
double spacing,
Location anchor)
GriddedRegion from a pair of
Locations. When viewed in a Mercator projection, the region will
be a rectangle. If either both latitude or both longitude values are the
same, an exception is thrown.Shape interface, Locations that fall on northern or
eastern borders of this region are considered inside. See
Region.Region(Location, Location) for implementation details.
loc1 - the first Locationloc2 - the second Locationspacing - of grid nodesanchor - Location for grid; may be null
IllegalArgumentException - if the latitude or longitude values in
the Locations provided are the same or
spacing is outside the range 0° <
spacing
≤ 5°
NullPointerException - if either Location argument is
nullRegion.Region(Location, Location)
public GriddedRegion(LocationList border,
BorderType type,
double latSpacing,
double lonSpacing,
Location anchor)
GriddedRegion from a list of border locations.
The border type specifies whether lat-lon values are treated as points in
an orthogonal coordinate system or as connecting great circles.
border - Locationstype - the BorderType to use when initializing; a
null value defaults to
BorderType.MERCATOR_LINEARlatSpacing - of grid nodeslonSpacing - of grid nodesanchor - Location for grid; may be null
IllegalArgumentException - if the border does not have
at least 3 points or spacing is outside the range
0° < spacing ≤ 5°
NullPointerException - if the border is
nullRegion.Region(LocationList, BorderType)
public GriddedRegion(LocationList border,
BorderType type,
double spacing,
Location anchor)
GriddedRegion from a list of border locations.
The border type specifies whether lat-lon values are treated as points in
an orthogonal coordinate system or as connecting great circles.
border - Locationstype - the BorderType to use when initializing; a
null value defaults to
BorderType.MERCATOR_LINEARspacing - of grid nodesanchor - Location for grid; may be null
IllegalArgumentException - if the border does not have
at least 3 points or spacing is outside the range
0° < spacing ≤ 5°
NullPointerException - if the border is
nullRegion.Region(LocationList, BorderType)
public GriddedRegion(Location center,
double radius,
double latSpacing,
double lonSpacing,
Location anchor)
GriddedRegion. Internally, the
centerpoint and radius are used to create a circular region composed of
straight line segments that span 10° wedges.
In the adjacent figure, the heavy
black line marks the border of the Region. The light gray
dots mark the Locations of nodes outside the region, and
black dots those inside the region. The dashed grey line marks the
border, inside which, a Location will be associated with a
grid node. See indexForLocation(Location) for more
details on rules governing whether a grid node is inside a region and
whether a Location will be associated with a grid node.
center - of the circleradius - of the circlelatSpacing - of grid nodeslonSpacing - of grid nodesanchor - Location for grid; may be null
IllegalArgumentException - if radius is outside the
range 0 km < radius ≤ 1000 km or spacing
is outside the range 0° < spacing ≤
5°
NullPointerException - if center is nullRegion.Region(Location, double)
public GriddedRegion(Location center,
double radius,
double spacing,
Location anchor)
GriddedRegion. Internally, the
centerpoint and radius are used to create a circular region composed of
straight line segments that span 10° wedges.
In the adjacent figure, the heavy
black line marks the border of the Region. The light gray
dots mark the Locations of nodes outside the region, and
black dots those inside the region. The dashed grey line marks the
border, inside which, a Location will be associated with a
grid node. See indexForLocation(Location) for more
details on rules governing whether a grid node is inside a region and
whether a Location will be associated with a grid node.
center - of the circleradius - of the circlespacing - of grid nodesanchor - Location for grid; may be null
IllegalArgumentException - if radius is outside the
range 0 km < radius ≤ 1000 km or spacing
is outside the range 0° < spacing ≤
5°
NullPointerException - if center is nullRegion.Region(Location, double)
public GriddedRegion(LocationList line,
double buffer,
double latSpacing,
double lonSpacing,
Location anchor)
GriddedRegion as a buffered area around a
line. In the adjacent figure, the heavy black line marks the border of
the Region.
The light gray dots
mark the Locations of nodes outside the region, and black
dots those inside the region. The dashed grey line marks the border,
inside which, a Location will be associated with a grid
node. See indexForLocation(Location) for more
details on rules governing whether a grid node is inside a region and
whether a Location will be associated with a grid node.
line - at center of buffered regionbuffer - distance from linelatSpacing - of grid nodeslonSpacing - of grid nodesanchor - Location for grid; may be null
NullPointerException - if line is null
IllegalArgumentException - if buffer is outside the
range 0 km < buffer ≤ 500 km or spacing
is outside the range 0° < spacing ≤
5°Region.Region(LocationList, double)
public GriddedRegion(LocationList line,
double buffer,
double spacing,
Location anchor)
GriddedRegion as a buffered area around a
line. In the adjacent figure, the heavy black line marks the border of
the Region.
The light gray dots
mark the Locations of nodes outside the region, and black
dots those inside the region. The dashed grey line marks the border,
inside which, a Location will be associated with a grid
node. See indexForLocation(Location) for more
details on rules governing whether a grid node is inside a region and
whether a Location will be associated with a grid node.
line - at center of buffered regionbuffer - distance from linespacing - of grid nodesanchor - Location for grid; may be null
NullPointerException - if line is null
IllegalArgumentException - if buffer is outside the
range 0 km < buffer ≤ 500 km or spacing
is outside the range 0° < spacing ≤
5°Region.Region(LocationList, double)
public GriddedRegion(Region region,
double latSpacing,
double lonSpacing,
Location anchor)
GriddedRegion with a Region.
region - to use as border for new GriddedRegionlatSpacing - of grid nodeslonSpacing - of grid nodesanchor - Location for grid; may be null
IllegalArgumentException - if spacing
is outside the range 0° < spacing ≤
5°
NullPointerException - if region is nullRegion.Region(Region)
public GriddedRegion(Region region,
double spacing,
Location anchor)
GriddedRegion with a Region.
region - to use as border for new GriddedRegionspacing - of grid nodesanchor - Location for grid; may be null
IllegalArgumentException - if spacing
is outside the range 0° < spacing ≤
5°
NullPointerException - if region is nullRegion.Region(Region)| Method Detail |
|---|
public double getLatSpacing()
public double getLonSpacing()
public double getSpacing()
getLatSpacing().
public boolean isSpacingUniform()
true if lat and lon spacing are the same;
false otherwise.public int getNodeCount()
public int getNumLocations()
public boolean isEmpty()
true if region has no grid nodes; false
otherwise
public int move(int idx,
Direction dir)
Direction from
the node at the supplied index.
idx - to move fromdir - to move
Direction or -1 if no node exists
NullPointerException - if supplied index is not a valid grid indexpublic boolean equalsRegion(GriddedRegion gr)
GriddedRegion to another and returns
true if they are the same with respect to aerial extent
(both exterior and interior borders), grid node spacing, and location.
This method ignores the names of the GriddedRegions. Use
GriddedRegion.equals(Object) to include name comparison.
gr - the Regions to compare
true if this Region has the same
geometry as the supplied Region, false
otherwiseequals(Object)public boolean equals(Object obj)
equals in class Regionpublic int hashCode()
hashCode in class Regionpublic GriddedRegion clone()
GriddedRegion.
clone in class RegionRegionpublic GriddedRegion subRegion(Region region)
GriddedRegion from this (the parent) and
another Region. The border of the new region is the
intersection of the borders of the parent and the passed-in region.
The new region also inherits the grid
spacing and node-alignment of the parent. The method returns
null if the two regions do not overlap.GriddedRegion may be devoid of grid
nodes, e.g. in cases where the sub-region is too small to contain any
nodes of the parent grid. Such a situation may arise if the sub-region
represents the area of influence of a small magnitude earthquake or
aftershock. If the closest point to the sub-region in the parent grid is
desired, then compute the subRegionCentroid and use:
if (newGriddedRegion.isEmpty()) {
int idx = indexForLocation(subRegionCentroid);
if (idx != -1) {
Location loc = locationForIndex(idx);
}
}
region - to use as border for sub-region
null if the the sub-region
does not intersect its parent (this)isEmpty()public void addInterior(Region region)
UnsupportedOperationException when
called. The border of a GriddedRegion may only be set on
initialization. To create a GriddedRegion that has interiors
(donut-holes), first create a Region with the required
border and interiors using Region.addInterior(Region) and then
use it to initialize a GriddedRegion.
addInterior in class Regionregion - to use as an interior or negative space
UnsupportedOperationExceptionRegion.addInterior(Region)public Iterator<Location> iterator()
iterator in interface Iterable<Location>public LocationList getNodeList()
LocationList.
public Location locationForIndex(int index)
Location at a given grid index. This method is
intended for random access of nodes in this gridded region; to cycle over
all nodes, iterate over the region.
index - of location to retrieve
Location or null if index is out of
rangepublic List<Integer> indicesForBounds(Rectangle2D rect)
rect - to process
IllegalArgumentException - if the supplied rectangle is not
completely enclosed by thei Regionpublic Area areaForIndex(int index)
Region that bounds a node
index - of the node of interest
public Location getLocation(int index)
index -
public int indexForLocation(Location loc)
Location or -1 if the associated grid node is ouside this
gridded region. For a Location to be associated with a node,
it must fall within the square region on which the node is centered. Note
that this allows for some Locations that are outside the
region border to still be associated with a node. Conversely, a
Region.contains(Location) may return true while this
method returns -1. Users interested in node association should always use
this method alone and test for -1 return value.
Region.contains(Location) should NOT be used a as a test
prior to calling this method. contains() or indexForLocation(). The arrows in
the figure point towards the interior of the Region. The
dots mark the centered Location of each grid node and the
numbers indicate the index value of each. Remember that both methods test
for insidedness according to the rules defined in the Shape
interface.
| Location | contains(Location) |
indexForLocation(Location) |
|---|---|---|
| A | true |
-1 |
| B | false |
3 |
| C | false |
3 |
| D | false |
-1 |
| E | true |
3 |
| F | true |
3 |
| G | true |
4 |
loc - the Location to match to a grid node index
public double getMinGridLat()
Double.NaN.
Region.contains(Location)public double getMaxGridLat()
Double.NaN.
Region.contains(Location)public double getMinGridLon()
Double.NaN.
Region.contains(Location)public double getMaxGridLon()
Double.NaN.
Region.contains(Location)public Element toXMLMetadata(Element root)
toXMLMetadata in interface XMLSaveabletoXMLMetadata in class Regionpublic static GriddedRegion fromXMLMetadata(Element root)
Region from stored metadata.
root - metadata element
GriddedRegion
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||