Class Regions
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).
- Author:
- U.S. Geological Survey
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic GriddedRegioncopyOf(GriddedRegion region) Creates a copy of aGriddedRegion.static RegionCreates an exact copy of aRegion.static Regioncreate(String name, LocationList border, BorderType type) Creates aRegionfrom a list of border locations.static RegioncreateBuffered(String name, LocationList line, double buffer)
Creates a Regionas a buffered area around a line.static RegioncreateCircular(String name, Location center, double radius)
Creates a circular
Region.static GriddedRegioncreateGridded(String name, LocationList border, BorderType type, double latSpacing, double lonSpacing, Location anchor)
Creates a
GriddedRegionfrom a list of border locations.static RegioncreateRectangular(String name, Location loc1, Location loc2) Creates aRegionfrom a pair ofLocations.static GriddedRegioncreateRectangularGridded(String name, Location loc1, Location loc2, double latSpacing, double lonSpacing, Location anchor) Creates aGriddedRegionfrom a pair ofLocations.static Regionglobal()Convenience method to return aRegionspanning the entire globe.static RegionintersectionOf(String name, Region r1, Region r2) Returns the intersection of twoRegions.static GriddedRegionCreates aGriddedRegionwith the same shape as the suppliedRegion.static RegionReturns the union of twoRegions.
-
Constructor Details
-
Regions
public Regions()
-
-
Method Details
-
create
Creates aRegionfrom 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 borderLocationListdoes not need to repeat the firstLocationat the end of the list.- Parameters:
name- of theRegion; may benullborder-Locationstype- theBorderTypeto use when initializing; anullvalue defaults toBorderType.MERCATOR_LINEAR- Returns:
- a new
Region - Throws:
IllegalArgumentException- if theborderdoes not have at least 3 points, defines aRegionthat is empty, or consists of more than a single closed path.NullPointerException- if theborderisnull
-
createGridded
public static GriddedRegion createGridded(String name, LocationList border, BorderType type, double latSpacing, double lonSpacing, Location anchor)
Creates a
GriddedRegionfrom 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
LocationListdoes not need to repeat the firstLocationat the end of the list. If the suppliedanchor Locationisnull, it is automatically set to the Location defined by the minimum latitude and longitude of the region's border.- Parameters:
name- of theGriddedRegion; may benullborder-Locationstype- theBorderTypeto use when initializing; anullvalue defaults toBorderType.MERCATOR_LINEARlatSpacing- of grid nodeslonSpacing- of grid nodesanchor-Locationfor grid; may benull- Returns:
- a new
GriddedRegion - Throws:
IllegalArgumentException- if theborderdoes not have at least 3 points, defines aRegionthat is empty, or consists of more than a single closed path; orspacingis outside the range 0° <spacing≤ 5°NullPointerException- if theborderisnull
-
createRectangular
Creates aRegionfrom a pair ofLocations. When viewed in a Mercator projection, theRegionwill be a rectangle. If either both latitude or both longitude values in theLocations 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 anyLocationon the north or east border of the region will returntrueand 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 theShapeinterface.- Parameters:
name- of theRegion; may benullloc1- the firstLocationloc2- the secondLocation- Returns:
- a new rectangular (broadly-defined)
Region - Throws:
IllegalArgumentException- if the latitude or longitude values in theLocations provided are the sameNullPointerException- if eitherLocationargument isnull
-
createRectangularGridded
public static GriddedRegion createRectangularGridded(String name, Location loc1, Location loc2, double latSpacing, double lonSpacing, Location anchor) Creates aGriddedRegionfrom a pair ofLocations. When viewed in a Mercator projection, theRegionwill be a rectangle. If either both latitude or both longitude values in theLocations are the same, an exception is thrown. If the suppliedanchor Locationisnull, 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 anyLocationon the north or east border of the region will returntrueand 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 theShapeinterface.- Parameters:
name- of theGriddedRegion; may benullloc1- the firstLocationloc2- the secondLocationlatSpacing- of grid nodeslonSpacing- of grid nodesanchor-Locationfor grid; may benull- Returns:
- a new rectangular (broadly-defined)
GriddedRegion - Throws:
IllegalArgumentException- if the latitude or longitude values in theLocations provided are the same orspacingis outside the range 0° <spacing≤ 5°NullPointerException- if eitherLocationargument isnull
-
createCircular
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 aGriddedRegionlike that in the adjacent figure. The heavy black line marks the border of theRegion. The light gray dots mark theLocations of nodes outside the region, and black dots those inside the region. The dashed grey line marks the border, inside which, aLocationwill be associated with a grid node. SeeGriddedRegion.indexForLocation(Location)for more details on rules governing whether a grid node is inside a region and whether aLocationwill be associated with a grid node.- Parameters:
name- of theRegion; may benullcenter- of the circleradius- of the circle- Returns:
- a new circular
Region - Throws:
IllegalArgumentException- ifradiusis outside the range 0 km <radius≤ 1000 kmNullPointerException- ifcenterisnull
-
createBuffered
Creates a Regionas a buffered area around a line.Passing the resultant region
toGridded(Region, double, double, Location)yields aGriddedRegionlike that in the adjacent figure. The light gray dots mark theLocations of nodes outside the region, and black dots those inside the region. The dashed grey line marks the border, inside which, aLocationwill be associated with a grid node. SeeGriddedRegion.indexForLocation(Location)for more details on rules governing whether a grid node is inside a region and whether aLocationwill be associated with a grid node.- Parameters:
name- of theRegion; may benullline- at center of bufferedRegionbuffer- distance from line- Returns:
- a new buffered
Regionaround a line - Throws:
NullPointerException- iflineisnullIllegalArgumentException- ifbufferis outside the range 0 km <buffer≤ 500 km
-
copyOf
Creates an exact copy of aRegion.- Parameters:
region- to copy- Returns:
- a copy of the supplied
Region - Throws:
NullPointerException- if the suppliedRegionisnull
-
copyOf
Creates a copy of aGriddedRegion.- Parameters:
region- to copy- Returns:
- a copy of the supplied
GriddedRegion - Throws:
NullPointerException- if the suppliedGriddedRegionisnull
-
toGridded
public static GriddedRegion toGridded(Region region, double latSpacing, double lonSpacing, Location anchor) Creates aGriddedRegionwith the same shape as the suppliedRegion. If the suppliedanchor Locationisnull, it is automatically set to the Location defined by the minimum latitude and longitude of the region's border.- Parameters:
region- to use as basis for newGriddedRegionlatSpacing- of grid nodeslonSpacing- of grid nodesanchor-Locationfor grid; may benull- Returns:
- a new
GriddedRegion - Throws:
IllegalArgumentException- ifspacingis outside the range 0° <spacing≤ 5°NullPointerException- if the suppliedRegionisnull
-
intersectionOf
Returns the intersection of twoRegions. If theRegions do not overlap, the method returnsnull.- Parameters:
name- of theRegion; may benullr1- the firstRegionr2- the secondRegion- Returns:
- a new
Regiondefined by the intersection ofr1andr2ornullif they do not overlap - Throws:
IllegalArgumentException- if either suppliedRegionis not a single closedRegionNullPointerException- if either suppliedRegionisnull
-
unionOf
Returns the union of twoRegions. If theRegions do not overlap, the method returnsnull.- Parameters:
name- of theRegion; may benullr1- the firstRegionr2- the secondRegion- Returns:
- a new
Regiondefined by the union ofr1andr2ornullif they do not overlap - Throws:
IllegalArgumentException- if either suppliedRegionis not a single closedRegionNullPointerException- if either suppliedRegionisnull
-
global
Convenience method to return aRegionspanning the entire globe.- Returns:
- a
Regionextending from -180° to +180° longitude and -90° to +90° latitude
-