Package org.geotools.coverage.util
Class CoverageUtilities
- Object
-
- CoverageUtilities
-
public final class CoverageUtilities extends Object
A set of utilities methods for the Grid Coverage package. Those methods are not really rigorous; must of them should be seen as temporary implementations.- Since:
- 2.4
- Author:
- Martin Desruisseaux (IRD), Simone Giannecchini, GeoSolutions
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CoverageUtilities.UCUM
Unified Code for Units of Measure (UCUM)
-
Field Summary
Fields Modifier and Type Field Description static double
AFFINE_IDENTITY_EPS
static AffineTransform
AXES_SWAP
Axes transposition for swapping Lat and Lon axes.static AffineTransform
CENTER_TO_CORNER
AffineTransform
that can be used to go from an image datum placed at the center of pixels to one that is placed at ULC.static AffineTransform
CORNER_TO_CENTER
AffineTransform
that can be used to go from an image datum placed at the ULC corner of pixels to one that is placed at center.static AffineTransform
IDENTITY_TRANSFORM
Identity affine transformation.static InternationalString
NODATA
Public name for standard No Data category.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
checkEmptySourceRegion(ImageReadParam readParameters, Rectangle dimensions)
Checks that the provideddimensions
when intersected with the source region used by the providedImageReadParam
instance does not result in an emptyRectangle
.static double[]
getBackgroundValues(GridCoverage2D coverage)
Retrieves a best guess for the sample value to use for background, inspecting the categories of the providedGridCoverage2D
.static CoordinateReferenceSystem
getCRS2D(Coverage coverage)
Returns a two-dimensional CRS for the given coverage.static ReferencedEnvelope
getEnvelope2D(Coverage coverage)
Returns a two-dimensional envelope for the given coverage.static CoordinateReferenceSystem
getHorizontalCRS(Coverage coverage)
Returns a two-dimensional horizontal CRS for the given coverage.static double
getMosaicThreshold(int dataType)
Returns a suitable threshold depending on theDataBuffer
type.static NoDataContainer
getNoDataProperty(GridCoverage2D coverage)
Utility method for extracting NoData property from inputGridCoverage2D
.static double[]
getResolution(AffineTransform gridToCRS)
Computes the resolutions for the provided "grid to world" transformation The returned resolution array is of length of 2.static ROI
getROIProperty(GridCoverage2D coverage)
Utility method for extracting ROI property from inputGridCoverage2D
.static int
getVisibleBand(Object image)
Returns the visible band in the specifiedRenderedImage
orPropertySource
.static boolean
isScaleTranslate(MathTransform transform, double EPS)
Checks if the transformation is a pure scale/translate instance (using the provided tolerance factor)static boolean
isSimpleGridToWorldTransform(AffineTransform gridToCRS, double EPS)
Tries to estimate if the supplied affine transform is either a scale and translate transform or if it contains a rotations which is an integer multiple of PI/2.static Properties
loadPropertiesFromURL(URL propsURL)
Extract Properties from a specified URLstatic void
setNoDataProperty(Map<String,Object> properties, Object noData)
Utility method for setting NoData to the inputMap
static void
setROIProperty(Map<String,Object> properties, ROI roi)
Utility method for setting ROI to the inputMap
static Number
suggestNoDataValue(int dataType)
Returns a suitable no data value depending on theDataBuffer
type.static boolean
uses(GridCoverage coverage, RenderedImage image)
Returnstrue
if the specified grid coverage or any of its source uses the following image.
-
-
-
Field Detail
-
NODATA
public static final InternationalString NODATA
Public name for standard No Data category.
-
AXES_SWAP
public static final AffineTransform AXES_SWAP
Axes transposition for swapping Lat and Lon axes.
-
IDENTITY_TRANSFORM
public static final AffineTransform IDENTITY_TRANSFORM
Identity affine transformation.
-
CENTER_TO_CORNER
public static final AffineTransform CENTER_TO_CORNER
AffineTransform
that can be used to go from an image datum placed at the center of pixels to one that is placed at ULC.
-
CORNER_TO_CENTER
public static final AffineTransform CORNER_TO_CENTER
AffineTransform
that can be used to go from an image datum placed at the ULC corner of pixels to one that is placed at center.
-
AFFINE_IDENTITY_EPS
public static final double AFFINE_IDENTITY_EPS
- See Also:
- Constant Field Values
-
-
Method Detail
-
getCRS2D
public static CoordinateReferenceSystem getCRS2D(Coverage coverage) throws TransformException
Returns a two-dimensional CRS for the given coverage. This method performs a best effort; the returned CRS is not garanteed to be the most appropriate one.- Parameters:
coverage
- The coverage for which to obtains a two-dimensional CRS.- Returns:
- The two-dimensional CRS.
- Throws:
TransformException
- if the CRS can't be reduced to two dimensions.
-
getHorizontalCRS
public static CoordinateReferenceSystem getHorizontalCRS(Coverage coverage) throws TransformException
Returns a two-dimensional horizontal CRS for the given coverage. This method performs a best effort; the returned CRS is not garanteed to succed.- Parameters:
coverage
- The coverage for which to obtains a two-dimensional horizontal CRS.- Returns:
- The two-dimensional horizontal CRS.
- Throws:
TransformException
- if the CRS can't be reduced to two dimensions.
-
getEnvelope2D
public static ReferencedEnvelope getEnvelope2D(Coverage coverage) throws MismatchedDimensionException
Returns a two-dimensional envelope for the given coverage. This method performs a best effort; the returned envelope is not garanteed to be the most appropriate one.- Parameters:
coverage
- The coverage for which to obtains a two-dimensional envelope.- Returns:
- The two-dimensional envelope.
- Throws:
MismatchedDimensionException
- if the envelope can't be reduced to two dimensions.
-
getNoDataProperty
public static NoDataContainer getNoDataProperty(GridCoverage2D coverage)
Utility method for extracting NoData property from inputGridCoverage2D
.- Returns:
- A
NoDataContainer
object containing input NoData definition
-
getROIProperty
public static ROI getROIProperty(GridCoverage2D coverage)
Utility method for extracting ROI property from inputGridCoverage2D
.- Returns:
- A
ROI
object
-
setNoDataProperty
public static void setNoDataProperty(Map<String,Object> properties, Object noData)
Utility method for setting NoData to the inputMap
- Parameters:
properties
-Map
where the nodata will be setnoData
- May be aRange
,double[]
,double
orNoDataContainer
-
setROIProperty
public static void setROIProperty(Map<String,Object> properties, ROI roi)
Utility method for setting ROI to the inputMap
- Parameters:
properties
-Map
where the ROI will be setroi
-ROI
instance to set
-
getBackgroundValues
public static double[] getBackgroundValues(GridCoverage2D coverage)
Retrieves a best guess for the sample value to use for background, inspecting the categories of the providedGridCoverage2D
.- Parameters:
coverage
- to use for guessing background values.- Returns:
- an array of double values to use as a background.
-
uses
public static boolean uses(GridCoverage coverage, RenderedImage image)
Returnstrue
if the specified grid coverage or any of its source uses the following image.
-
getVisibleBand
public static int getVisibleBand(Object image)
Returns the visible band in the specifiedRenderedImage
orPropertySource
. This method fetch the"GC_VisibleBand"
property. If this property is undefined, then the visible band default to the first one.- Parameters:
image
- The image for which to fetch the visible band, ornull
.- Returns:
- The visible band.
-
isScaleTranslate
public static boolean isScaleTranslate(MathTransform transform, double EPS)
Checks if the transformation is a pure scale/translate instance (using the provided tolerance factor)- Parameters:
transform
- TheMathTransform
to check.EPS
- The tolerance factor.- Returns:
true
if the provided transformation is a simple scale and translate,false
otherwise.
-
getResolution
public static double[] getResolution(AffineTransform gridToCRS)
Computes the resolutions for the provided "grid to world" transformation The returned resolution array is of length of 2.- Parameters:
gridToCRS
- The grid to world transformation.
-
isSimpleGridToWorldTransform
public static boolean isSimpleGridToWorldTransform(AffineTransform gridToCRS, double EPS)
Tries to estimate if the supplied affine transform is either a scale and translate transform or if it contains a rotations which is an integer multiple of PI/2.- Parameters:
gridToCRS
- an instance ofAffineTransform
to check against.EPS
- tolerance value for comparisons.- Returns:
true
if this transform is "simple",false
otherwise.
-
checkEmptySourceRegion
public static boolean checkEmptySourceRegion(ImageReadParam readParameters, Rectangle dimensions)
Checks that the provideddimensions
when intersected with the source region used by the providedImageReadParam
instance does not result in an emptyRectangle
. Finally, in case the region intersection is not empty, set it as new source region for the providedImageReadParam
.Input parameters cannot be null.
- Parameters:
readParameters
- an instance ofImageReadParam
for which we want to check the source region element.dimensions
- an instance ofRectangle
to use for the check.- Returns:
true
if the intersection is not empty,false
otherwise.
-
getMosaicThreshold
public static double getMosaicThreshold(int dataType)
Returns a suitable threshold depending on theDataBuffer
type.Remember that the threshold works with >=.
- Parameters:
dataType
- to create a low threshold for.- Returns:
- a minimum threshold value suitable for this data type.
-
suggestNoDataValue
public static Number suggestNoDataValue(int dataType)
Returns a suitable no data value depending on theDataBuffer
type.- Parameters:
dataType
- to create a low threshold for.- Returns:
- a no data value suitable for this data type.
-
loadPropertiesFromURL
public static Properties loadPropertiesFromURL(URL propsURL)
Extract Properties from a specified URL
-
-