Package org.geotools.coverage.io.util
Class Utilities
- Object
-
- Utilities
-
public class Utilities extends Object
- Author:
- Daniele Romagnoli, GeoSolutions
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static NameImplbuildCoverageName(URL input)static StringbuildIso8601Time(String date, String time)static booleancheckFileReadable(File file)Checks that aFileis a real file, exists and is readable.static GridCoveragecompute(Object input, int imageIndex, boolean needTransformation, boolean isEmptyRequest, boolean useJAI, ImageReadParam imageReadParam, boolean useMultithreading, GridSampleDimension[] sampleDimensions, ImageReaderSpi imageReaderSpi, String coverageName, GridCoverageFactory coverageFactory, MathTransform raster2Model, CoordinateReferenceSystem coordinateReferenceSystem, GeneralBounds envelope2D)Compute the coverage request and produce a grid coverage.static GridCoveragecreateCoverage(ImageReaderSpi spi, Object input, int imageIndex, ImageReadParam imageReadParam, boolean useJAI, boolean useMultithreading, boolean newTransform, GridSampleDimension[] sampleDimensions, String coverageName, GridCoverageFactory coverageFactory, MathTransform raster2Model, CoordinateReferenceSystem coordinateReferenceSystem, GeneralBounds coverageEnvelope2D)This method creates the GridCoverage2D from the underlying file given a specified envelope, and a requested dimension.static GridCoveragecreateCoverageFromImage(GridCoverageFactory coverageFactory, String coverageName, int imageIndex, PlanarImage image, MathTransform raster2Model, CoordinateReferenceSystem spatialReferenceSystem2D, GeneralBounds coverageEnvelope2D, GridSampleDimension[] sampleDimensions)Creates aGridCoveragefor the providedPlanarImageusing theMathTransformthat was provided for this coverage.static booleanensureValidString(String... strings)static GeneralBoundsevaluateRequestedParams(GridEnvelope originalGridRange, ReferencedEnvelope baseEnvelope2D, CoordinateReferenceSystem spatialReferenceSystem2D, MathTransform originalGridToWorld, GeneralBounds requestedEnvelope, Rectangle sourceRegion, Rectangle requestedDim, MathTransform2D readGridToWorld, ReferencedEnvelope wgs84BaseEnvelope2D)Evaluates the requested envelope and builds a new adjusted version of it fitting this coverage envelope.static StringgetAttributeValue(NamedNodeMap attributes, String attributeName)Simple method returning the value (asString) of the attribute with nameattributeNamefrom the input attributes map.static GeographicCRSgetBaseCRS(double equatorialRadius, double inverseFlattening)Build a baseGeographicCRSgiven the parameters to specify a Geodetic Datumstatic RectanglegetCropRegion(GeneralBounds envelope, MathTransform gridToWorldTransform)Return a crop region from a specified envelope, leveraging on a grid to world transformation.static DefaultGeodeticDatumgetDefaultGeodeticDatum(String name, double equatorialRadius, double inverseFlattening, Unit<Length> unit)Build aDefaultGeodeticDatumgiven a set of parameters.static BoundsgetEnvelopeAsWGS84(Bounds bounds, boolean get2D)Get a WGS84 envelope for the specified envelope.static FilegetFileFromCustomInput(Object input)Temp utility method which allows to get the real file name from a custom input File, where "custom" means a file having a special name structured as "originalFileName:imageIndex"static StringgetFileInfo(File file)Creates a human readable message that describe the providedFileobject in terms of its properties.static ReferenceIdentifier[]getIdentifiers(String nameIdentifier)static GeneralBoundsgetIntersection(ReferencedEnvelope baseEnvelope2D, CoordinateReferenceSystem spatialReferenceSystem2D, GeneralBounds requestedEnvelope2D, Rectangle requestedDim, MathTransform2D readGridToWorld, ReferencedEnvelope wgs84BaseEnvelope2D)Returns the intersection between the base envelope and the requested envelope.static CoordinateReferenceSystemgetMercator2SPProjectedCRS(double standardParallel, double centralMeridian, double natOriginLat, GeographicCRS sourceCRS, Hints hints)Simple utility method which allows to build a Mercator2SP Projected CRS given the set of required parameters.static MathTransformgetOriginalGridToWorld(MathTransform raster2Model, PixelInCell pixInCell)Retrieves the original grid to world transformation for thisAbstractGridCoverage2DReader.static GeneralBoundsgetRequestedEnvelope2D(GeneralBounds requestedEnvelope)Return a 2D version of a requestedEnvelopestatic PropertiesloadPropertiesFromURL(URL propsURL)static Unit<? extends Quantity<?>>parseUnit(String uom)Return aUnitinstance for the specified uom String.static PlanarImagereadImage(ImageReaderSpi spi, Object input, int imageIndex, boolean useJAI, ImageReadParam imageReadParam, boolean useMultithreading)Returns aPlanarImagegiven a set of parameter specifying the type of read operation to be performed.static voidsetDecimationParameters(ImageReadParam readP, GridEnvelope baseGridRange, double[] requestedRes, double[] highestRes)This method is responsible for evaluating possible subsampling factors once the best resolution level has been found in case we have support for overviews, or starting from the original coverage in case there are no overviews available.static voidsetReadParameters(OverviewPolicy overviewPolicy, ImageReadParam readParam, GeneralBounds requestedEnvelope, Rectangle requestedDim, double[] highestRes, GridEnvelope gridRange, PixelInCell pixelInCell)Prepares the read parameters for doing anImageReader.read(int, ImageReadParam).
-
-
-
Method Detail
-
getIdentifiers
public static ReferenceIdentifier[] getIdentifiers(String nameIdentifier)
-
getDefaultGeodeticDatum
public static DefaultGeodeticDatum getDefaultGeodeticDatum(String name, double equatorialRadius, double inverseFlattening, Unit<Length> unit)
Build aDefaultGeodeticDatumgiven a set of parameters.- Parameters:
name- the datum nameequatorialRadius- the equatorial radius parameterinverseFlattening- the inverse flattening parameterunit- the UoM- Returns:
- a properly built Datum.
-
getFileFromCustomInput
public static File getFileFromCustomInput(Object input)
Temp utility method which allows to get the real file name from a custom input File, where "custom" means a file having a special name structured as "originalFileName:imageIndex"
-
getMercator2SPProjectedCRS
public static CoordinateReferenceSystem getMercator2SPProjectedCRS(double standardParallel, double centralMeridian, double natOriginLat, GeographicCRS sourceCRS, Hints hints) throws DataSourceException
Simple utility method which allows to build a Mercator2SP Projected CRS given the set of required parameters. It will be used by several Terascan products.- Throws:
DataSourceException
-
getBaseCRS
public static GeographicCRS getBaseCRS(double equatorialRadius, double inverseFlattening)
Build a baseGeographicCRSgiven the parameters to specify a Geodetic Datum
-
getAttributeValue
public static String getAttributeValue(NamedNodeMap attributes, String attributeName)
Simple method returning the value (asString) of the attribute with nameattributeNamefrom the input attributes map.- Parameters:
attributes- the attributes mapattributeName- the requested attribute- Returns:
- the value of the requested attribute as a
String. Returnsnullin case of no attribute found.
-
parseUnit
public static Unit<? extends Quantity<?>> parseUnit(String uom)
Return aUnitinstance for the specified uom String.
-
getEnvelopeAsWGS84
public static Bounds getEnvelopeAsWGS84(Bounds bounds, boolean get2D) throws FactoryException, TransformException
Get a WGS84 envelope for the specified envelope. The get2D parameter allows to specify if we need the returned coverage as anReferencedEnvelopeor a more generalGeneralEnvelopeinstance.if
true, the requested envelope will be an instance ofReferencedEnvelope. Iffalseit will be an instance ofGeneralBounds- Returns:
- a WGS84 envelope as
Envelope2Din case of request for a 2D WGS84 Envelope, or aGeneralBoundsotherwise. - Throws:
FactoryExceptionTransformException
-
getRequestedEnvelope2D
public static GeneralBounds getRequestedEnvelope2D(GeneralBounds requestedEnvelope) throws FactoryException, TransformException
Return a 2D version of a requestedEnvelope- Parameters:
requestedEnvelope- theGeneralEnvelopeto be returned as 2D.- Returns:
- the 2D requested envelope
- Throws:
FactoryExceptionTransformException
-
getCropRegion
public static Rectangle getCropRegion(GeneralBounds envelope, MathTransform gridToWorldTransform) throws TransformException
Return a crop region from a specified envelope, leveraging on a grid to world transformation.- Parameters:
envelope- the crop envelopegridToWorldTransform- the grid2world transformation- Returns:
- a
Rectanglerepresenting the crop region. - Throws:
TransformException- in case a problem occurs when going back to raster space.
-
getIntersection
public static GeneralBounds getIntersection(ReferencedEnvelope baseEnvelope2D, CoordinateReferenceSystem spatialReferenceSystem2D, GeneralBounds requestedEnvelope2D, Rectangle requestedDim, MathTransform2D readGridToWorld, ReferencedEnvelope wgs84BaseEnvelope2D) throws TransformException, FactoryException
Returns the intersection between the base envelope and the requested envelope.- Parameters:
baseEnvelope2D- the base envelope.requestedEnvelope2D- the requested 2D envelope to be intersected with the base envelope.requestedDim- is the requested region where to load data of the specified envelope.readGridToWorld- the Grid to world transformation to be used in readwgs84BaseEnvelope2D- a WGS84 version of the baseEnvelope to be used to try finding an intersection in wgs84 in case it is impossible to compute an intersection of the base envelope with the specified requested envelope.- Returns:
- the resulting intersection of envelopes. In case of empty intersection, this method is allowed to return
null - Throws:
TransformExceptionFactoryException
-
getOriginalGridToWorld
public static MathTransform getOriginalGridToWorld(MathTransform raster2Model, PixelInCell pixInCell)
Retrieves the original grid to world transformation for thisAbstractGridCoverage2DReader.- Parameters:
pixInCell- specifies the datum of the transformation we want.- Returns:
- the original grid to world transformation
-
evaluateRequestedParams
public static GeneralBounds evaluateRequestedParams(GridEnvelope originalGridRange, ReferencedEnvelope baseEnvelope2D, CoordinateReferenceSystem spatialReferenceSystem2D, MathTransform originalGridToWorld, GeneralBounds requestedEnvelope, Rectangle sourceRegion, Rectangle requestedDim, MathTransform2D readGridToWorld, ReferencedEnvelope wgs84BaseEnvelope2D) throws DataSourceException
Evaluates the requested envelope and builds a new adjusted version of it fitting this coverage envelope.While adjusting the requested envelope this methods also compute the source region as a rectangle which is suitable for a successive read operation with
ImageIOto do crop-on-read.- Parameters:
requestedEnvelope- is the envelope we are requested to load.sourceRegion- represents the area to load in raster space. This parameter cannot be null since it gets filled with whatever the crop region is depending on therequestedEnvelope.requestedDim- is the requested region where to load data of the specified envelope.readGridToWorld- the Grid to world transformation to be used- Returns:
- the adjusted requested envelope, empty if no requestedEnvelope has been specified,
nullin case the requested envelope does not intersect the coverage envelope or in case the adjusted requested envelope is covered by a too small raster region (an empty region). - Throws:
DataSourceException- in case something bad occurs
-
createCoverageFromImage
public static GridCoverage createCoverageFromImage(GridCoverageFactory coverageFactory, String coverageName, int imageIndex, PlanarImage image, MathTransform raster2Model, CoordinateReferenceSystem spatialReferenceSystem2D, GeneralBounds coverageEnvelope2D, GridSampleDimension[] sampleDimensions) throws IOException
Creates aGridCoveragefor the providedPlanarImageusing theMathTransformthat was provided for this coverage.This method is vital when working with coverages that have a raster to model transformation that is not a simple scale and translate.
- Parameters:
image- contains the data for the coverage to create.raster2Model- is theMathTransformthat maps from the raster space to the model space.- Returns:
- a
GridCoverage - Throws:
IOException
-
setDecimationParameters
public static void setDecimationParameters(ImageReadParam readP, GridEnvelope baseGridRange, double[] requestedRes, double[] highestRes)
This method is responsible for evaluating possible subsampling factors once the best resolution level has been found in case we have support for overviews, or starting from the original coverage in case there are no overviews available.- Parameters:
readP- the imageRead parameter to be setrequestedRes- the requested resolutions from which to determine the decimation parameters.
-
setReadParameters
public static void setReadParameters(OverviewPolicy overviewPolicy, ImageReadParam readParam, GeneralBounds requestedEnvelope, Rectangle requestedDim, double[] highestRes, GridEnvelope gridRange, PixelInCell pixelInCell) throws IOException, TransformException
Prepares the read parameters for doing anImageReader.read(int, ImageReadParam).It sets the passed
ImageReadParamin terms of decimation on reading using the provided requestedEnvelope and requestedDim to evaluate the needed resolution.- Parameters:
overviewPolicy- it can be one ofHints#VALUE_OVERVIEW_POLICY_IGNORE,Hints#VALUE_OVERVIEW_POLICY_NEAREST,Hints#VALUE_OVERVIEW_POLICY_QUALITYorHints#VALUE_OVERVIEW_POLICY_SPEED. It specifies the policy to compute the overviews level upon request.readParam- an instance ofImageReadParamfor setting the subsampling factors.requestedEnvelope- theGeneralBoundswe are requesting.requestedDim- the requested dimensions.- Throws:
IOExceptionTransformException
-
createCoverage
public static GridCoverage createCoverage(ImageReaderSpi spi, Object input, int imageIndex, ImageReadParam imageReadParam, boolean useJAI, boolean useMultithreading, boolean newTransform, GridSampleDimension[] sampleDimensions, String coverageName, GridCoverageFactory coverageFactory, MathTransform raster2Model, CoordinateReferenceSystem coordinateReferenceSystem, GeneralBounds coverageEnvelope2D) throws IOException
This method creates the GridCoverage2D from the underlying file given a specified envelope, and a requested dimension.- Parameters:
useJAI- specify if the underlying read process should leverage on a JAI ImageRead operation or a simple direct call to thereadmethod of a properImageReader.useMultithreading- specify if the underlying read process should use multithreading when a JAI ImageRead operation is requested- Returns:
- a
GridCoverage - Throws:
IOException
-
readImage
public static PlanarImage readImage(ImageReaderSpi spi, Object input, int imageIndex, boolean useJAI, ImageReadParam imageReadParam, boolean useMultithreading) throws IOException
Returns aPlanarImagegiven a set of parameter specifying the type of read operation to be performed.- Parameters:
input- the input to be used for reading the image.useJAI-trueif we need to use a JAI ImageRead operation,falseif we need a simple directImageReader.read(...)call.imageReadParam- anImageReadParamspecifying the read parametersuseMultithreading-trueif a JAI ImageRead operation is requested with support for multithreading. This parameter will be ignored if requesting a direct read operation.- Returns:
- the read
PlanarImage - Throws:
IOException
-
compute
public static GridCoverage compute(Object input, int imageIndex, boolean needTransformation, boolean isEmptyRequest, boolean useJAI, ImageReadParam imageReadParam, boolean useMultithreading, GridSampleDimension[] sampleDimensions, ImageReaderSpi imageReaderSpi, String coverageName, GridCoverageFactory coverageFactory, MathTransform raster2Model, CoordinateReferenceSystem coordinateReferenceSystem, GeneralBounds envelope2D) throws IOException
Compute the coverage request and produce a grid coverage. The produced grid coverage may benullin case of empty request.- Throws:
IOException- @TODO: handle more input types
-
ensureValidString
public static final boolean ensureValidString(String... strings)
-
checkFileReadable
public static boolean checkFileReadable(File file)
Checks that aFileis a real file, exists and is readable.- Parameters:
file- theFileinstance to check. Must not be null.- Returns:
truein case the file is a real file, exists and is readable;falseotherwise.
-
getFileInfo
public static String getFileInfo(File file)
Creates a human readable message that describe the providedFileobject in terms of its properties.Useful for creating meaningful log messages.
-
loadPropertiesFromURL
public static Properties loadPropertiesFromURL(URL propsURL)
-
-