public class Regions extends Object
Note that intersection and union operations will discard any grid
information if GriddedRegions are supplied as arguments.
To build complex gridded regions (e.g. circular or buffered, or via
intersections and unions) create a Region first and use
toGridded(Region, double, double, Location).
| Constructor and Description |
|---|
Regions() |
| Modifier and Type | Method and Description |
|---|---|
static GriddedRegion |
copyOf(GriddedRegion region)
Creates a copy of a
GriddedRegion. |
static Region |
copyOf(Region region)
Creates an exact copy of a
Region. |
static Region |
create(String name,
LocationList border,
BorderType type)
Creates a
Region from a list of border locations. |
static Region |
createBuffered(String name,
LocationList line,
double buffer)
Creates a Region
as a buffered area around a line. |
static Region |
createCircular(String name,
Location center,
double radius)
Creates a circular
Region. |
static GriddedRegion |
createGridded(String name,
LocationList border,
BorderType type,
double latSpacing,
double lonSpacing,
Location anchor)
Creates a
GriddedRegion from a list of border locations. |
static Region |
createRectangular(String name,
Location loc1,
Location loc2)
Creates a
Region from a pair of Location s. |
static GriddedRegion |
createRectangularGridded(String name,
Location loc1,
Location loc2,
double latSpacing,
double lonSpacing,
Location anchor)
Creates a
GriddedRegion from a pair of Location s. |
static Region |
global()
Convenience method to return a
Region spanning the entire globe. |
static Region |
intersectionOf(String name,
Region r1,
Region r2)
Returns the intersection of two
Regions. |
static GriddedRegion |
toGridded(Region region,
double latSpacing,
double lonSpacing,
Location anchor)
Creates a
GriddedRegion with the same shape as the supplied
Region. |
static Region |
unionOf(String name,
Region r1,
Region r2)
Returns the union of two
Regions. |
public static Region create(String name, LocationList border, BorderType type)
Region 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. The border
LocationList does not need to repeat the first Location at
the end of the list.name - of the Region; may be nullborder - Locationstype - the BorderType to use when initializing; a null
value defaults to BorderType.MERCATOR_LINEARRegionIllegalArgumentException - if the border does not have at
least 3 points, defines a Region that is empty, or consists
of more than a single closed path.NullPointerException - if the border is nullpublic static GriddedRegion createGridded(String name, LocationList border, BorderType type, double latSpacing, double lonSpacing, Location anchor)
Creates a
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. The
border LocationList does not need to repeat the first
Location at the end of the list. If the supplied
anchor Location is null, it is automatically set to the
Location defined by the minimum latitude and longitude of the region's
border.
name - of the GriddedRegion; may be nullborder - 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 nullGriddedRegionIllegalArgumentException - if the border does not have at
least 3 points, defines a Region that is empty, or consists
of more than a single closed path; or spacing is outside
the range 0° < spacing ≤ 5°NullPointerException - if the border is nullpublic static Region createRectangular(String name, Location loc1, Location loc2)
Region from a pair of Location s. When viewed in
a Mercator projection, the Region will be a rectangle. If either
both latitude or both longitude values in the Locations are the
same, an exception is thrown.
Note: Internally, the size of the region is expanded by a very
small value (~1m) to ensure that calls to Region.contains(Location)
for any Location on the north or east border of the region will
return true and that any double precision rounding issues do not
clip the south and west borders (e.g. 45.0 may be interpreted as
44.9999...). See also the rules governing insidedness in the Shape
interface.
name - of the Region; may be nullloc1 - the first Locationloc2 - the second LocationRegionIllegalArgumentException - if the latitude or longitude values in the
Locations provided are the sameNullPointerException - if either Location argument is
nullpublic static GriddedRegion createRectangularGridded(String name, Location loc1, Location loc2, double latSpacing, double lonSpacing, Location anchor)
GriddedRegion from a pair of Location s. When
viewed in a Mercator projection, the Region will be a rectangle. If
either both latitude or both longitude values in the Locations are
the same, an exception is thrown. If the supplied anchor Location
is null, it is automatically set to the Location defined by the
minimum latitude and longitude of the region's border.
Note: Internally, the size of the region is expanded by a very
small value (~1m) to ensure that calls to Region.contains(Location)
for any Location on the north or east border of the region will
return true and that any double precision rounding issues do not
clip the south and west borders (e.g. 45.0 may be interpreted as
44.9999...). See also the rules governing insidedness in the Shape
interface.
name - of the GriddedRegion; may be nullloc1 - the first Locationloc2 - the second LocationlatSpacing - of grid nodeslonSpacing - of grid nodesanchor - Location for grid; may be nullGriddedRegionIllegalArgumentException - 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
nullpublic static Region createCircular(String name, Location center, double radius)
Creates a circular
Region. Internally, the centerpoint and radius are used to create a
circular region composed of straight line segments that span 10° wedges.
Passing the resultant region
toGridded(Region, double, double, Location) yields a
GriddedRegion like that 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
GriddedRegion.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.
name - of the Region; may be nullcenter - of the circleradius - of the circleRegionIllegalArgumentException - if radius is outside the range 0
km < radius ≤ 1000 kmNullPointerException - if center is nullpublic static Region createBuffered(String name, LocationList line, double buffer)
Creates a Region
as a buffered area around a line.
Passing the resultant region
toGridded(Region, double, double, Location) yields a
GriddedRegion like that in the adjacent figure. 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
GriddedRegion.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.
name - of the Region; may be nullline - at center of buffered Regionbuffer - distance from lineRegion around a lineNullPointerException - if line is nullIllegalArgumentException - if buffer is outside the range 0
km < buffer ≤ 500 kmpublic static Region copyOf(Region region)
Region.region - to copyRegionNullPointerException - if the supplied Region is nullpublic static GriddedRegion copyOf(GriddedRegion region)
GriddedRegion.region - to copyGriddedRegionNullPointerException - if the supplied GriddedRegion is
nullpublic static GriddedRegion toGridded(Region region, double latSpacing, double lonSpacing, Location anchor)
GriddedRegion with the same shape as the supplied
Region. If the supplied anchor Location is null, it
is automatically set to the Location defined by the minimum latitude and
longitude of the region's border.region - to use as basis for new GriddedRegionlatSpacing - of grid nodeslonSpacing - of grid nodesanchor - Location for grid; may be nullGriddedRegionIllegalArgumentException - if spacing is outside the range 0°
< spacing ≤ 5°NullPointerException - if the supplied Region is nullpublic static Region intersectionOf(String name, Region r1, Region r2)
Regions. If the Regions do
not overlap, the method returns null.name - of the Region; may be nullr1 - the first Regionr2 - the second RegionRegion defined by the intersection of r1 and
r2 or null if they do not overlapIllegalArgumentException - if either supplied Region is not a
single closed RegionNullPointerException - if either supplied Region is
nullpublic static Region unionOf(String name, Region r1, Region r2)
Regions. If the Regions do not
overlap, the method returns null.name - of the Region; may be nullr1 - the first Regionr2 - the second RegionRegion defined by the union of r1 and
r2 or null if they do not overlapIllegalArgumentException - if either supplied Region is not a
single closed RegionNullPointerException - if either supplied Region is
nullpublic static Region global()
Region spanning the entire globe.Region extending from -180° to +180° longitude and -90°
to +90° latitude