public class Utilities extends Object
Modifier and Type | Method and Description |
---|---|
static NameImpl |
buildCoverageName(URL input) |
static String |
buildIso8601Time(String date,
String time) |
static boolean |
checkFileReadable(File file)
Checks that a
File is a real file, exists and is readable. |
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,
GeneralEnvelope envelope2D)
Compute the coverage request and produce a grid coverage.
|
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,
GeneralEnvelope coverageEnvelope2D)
This method creates the GridCoverage2D from the underlying file given a specified envelope,
and a requested dimension.
|
static GridCoverage |
createCoverageFromImage(GridCoverageFactory coverageFactory,
String coverageName,
int imageIndex,
PlanarImage image,
MathTransform raster2Model,
CoordinateReferenceSystem spatialReferenceSystem2D,
GeneralEnvelope coverageEnvelope2D,
GridSampleDimension[] sampleDimensions)
Creates a
GridCoverage for the provided PlanarImage using the #raster2Model that was provided for this coverage. |
static boolean |
ensureValidString(String... strings) |
static GeneralEnvelope |
evaluateRequestedParams(GridEnvelope originalGridRange,
Envelope2D baseEnvelope2D,
CoordinateReferenceSystem spatialReferenceSystem2D,
MathTransform originalGridToWorld,
GeneralEnvelope requestedEnvelope,
Rectangle sourceRegion,
Rectangle requestedDim,
MathTransform2D readGridToWorld,
Envelope2D wgs84BaseEnvelope2D)
Evaluates the requested envelope and builds a new adjusted version of it fitting this
coverage envelope.
|
static String |
getAttributeValue(NamedNodeMap attributes,
String attributeName)
Simple method returning the value (as
String ) of the attribute with name attributeName from the input attributes map. |
static GeographicCRS |
getBaseCRS(double equatorialRadius,
double inverseFlattening)
Build a base
GeographicCRS given the parameters to specify a Geodetic Datum |
static Rectangle |
getCropRegion(GeneralEnvelope envelope,
MathTransform gridToWorldTransform)
Return a crop region from a specified envelope, leveraging on a grid to world transformation.
|
static DefaultGeodeticDatum |
getDefaultGeodeticDatum(String name,
double equatorialRadius,
double inverseFlattening,
Unit unit)
Build a
DefaultGeodeticDatum given a set of parameters. |
static Envelope |
getEnvelopeAsWGS84(Envelope envelope,
boolean get2D)
Get a WGS84 envelope for the specified envelope.
|
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"
|
static String |
getFileInfo(File file)
Creates a human readable message that describe the provided
File object in terms of
its properties. |
static ReferenceIdentifier[] |
getIdentifiers(String nameIdentifier) |
static GeneralEnvelope |
getIntersection(Envelope2D baseEnvelope2D,
CoordinateReferenceSystem spatialReferenceSystem2D,
GeneralEnvelope requestedEnvelope2D,
Rectangle requestedDim,
MathTransform2D readGridToWorld,
Envelope2D wgs84BaseEnvelope2D)
Returns the intersection between the base envelope and the requested envelope.
|
static CoordinateReferenceSystem |
getMercator2SPProjectedCRS(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 MathTransform |
getOriginalGridToWorld(MathTransform raster2Model,
PixelInCell pixInCell)
Retrieves the original grid to world transformation for this
AbstractGridCoverage2DReader . |
static GeneralEnvelope |
getRequestedEnvelope2D(GeneralEnvelope requestedEnvelope)
Return a 2D version of a requestedEnvelope
|
static Properties |
loadPropertiesFromURL(URL propsURL) |
static Unit<? extends Quantity> |
parseUnit(String uom)
Return a
Unit instance for the specified uom String. |
static PlanarImage |
readImage(ImageReaderSpi spi,
Object input,
int imageIndex,
boolean useJAI,
ImageReadParam imageReadParam,
boolean useMultithreading)
Returns a
PlanarImage given a set of parameter specifying the type of read operation
to be performed. |
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.
|
static void |
setReadParameters(OverviewPolicy overviewPolicy,
ImageReadParam readParam,
GeneralEnvelope requestedEnvelope,
Rectangle requestedDim,
double[] highestRes,
GridEnvelope gridRange,
PixelInCell pixelInCell)
Prepares the read parameters for doing an
ImageReader.read(int, ImageReadParam) . |
public static ReferenceIdentifier[] getIdentifiers(String nameIdentifier)
public static DefaultGeodeticDatum getDefaultGeodeticDatum(String name, double equatorialRadius, double inverseFlattening, Unit unit)
DefaultGeodeticDatum
given a set of parameters.name
- the datum nameequatorialRadius
- the equatorial radius parameterinverseFlattening
- the inverse flattening parameterunit
- the UoMpublic static File getFileFromCustomInput(Object input)
public static CoordinateReferenceSystem getMercator2SPProjectedCRS(double standardParallel, double centralMeridian, double natOriginLat, GeographicCRS sourceCRS, Hints hints) throws DataSourceException
DataSourceException
public static GeographicCRS getBaseCRS(double equatorialRadius, double inverseFlattening)
GeographicCRS
given the parameters to specify a Geodetic Datumpublic static String getAttributeValue(NamedNodeMap attributes, String attributeName)
String
) of the attribute with name attributeName
from the input attributes map.attributes
- the attributes mapattributeName
- the requested attributeString
. Returns null
in
case of no attribute found.public static Unit<? extends Quantity> parseUnit(String uom)
Unit
instance for the specified uom String.uom
- public static Envelope getEnvelopeAsWGS84(Envelope envelope, boolean get2D) throws FactoryException, TransformException
Envelope2D
or a more general GeneralEnvelope
instance.envelope
- get2D
- if true
, the requested envelope will be an
instance of Envelope2D
. If false
it will
be an instance of {@link GeneralEnvelopeEnvelope2D
in case of request for a
2D WGS84 Envelope, or a GeneralEnvelope
otherwise.FactoryException
TransformException
public static GeneralEnvelope getRequestedEnvelope2D(GeneralEnvelope requestedEnvelope) throws FactoryException, TransformException
requestedEnvelope
- the GeneralEnvelope
to be returned as 2D.FactoryException
TransformException
public static Rectangle getCropRegion(GeneralEnvelope envelope, MathTransform gridToWorldTransform) throws TransformException
envelope
- the crop envelopegridToWorldTransform
- the grid2world transformationRectangle
representing the crop region.TransformException
- in case a problem occurs when going back to raster space.public static GeneralEnvelope getIntersection(Envelope2D baseEnvelope2D, CoordinateReferenceSystem spatialReferenceSystem2D, GeneralEnvelope requestedEnvelope2D, Rectangle requestedDim, MathTransform2D readGridToWorld, Envelope2D wgs84BaseEnvelope2D) throws TransformException, FactoryException
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.null
TransformException
FactoryException
public static MathTransform getOriginalGridToWorld(MathTransform raster2Model, PixelInCell pixInCell)
AbstractGridCoverage2DReader
.pixInCell
- specifies the datum of the transformation we want.public static GeneralEnvelope evaluateRequestedParams(GridEnvelope originalGridRange, Envelope2D baseEnvelope2D, CoordinateReferenceSystem spatialReferenceSystem2D, MathTransform originalGridToWorld, GeneralEnvelope requestedEnvelope, Rectangle sourceRegion, Rectangle requestedDim, MathTransform2D readGridToWorld, Envelope2D wgs84BaseEnvelope2D) throws DataSourceException
While adjusting the requested envelope this methods also compute the source region as a
rectangle which is suitable for a successive read operation with ImageIO
to do
crop-on-read.
originalGridToWorld
- coordinateReferenceSystem
- 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 the
requestedEnvelope
.requestedDim
- is the requested region where to load data of the specified envelope.readGridToWorld
- the Grid to world transformation to be usedwgs84BaseEnvelope2D
- null
in 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).DataSourceException
- in case something bad occurspublic static GridCoverage createCoverageFromImage(GridCoverageFactory coverageFactory, String coverageName, int imageIndex, PlanarImage image, MathTransform raster2Model, CoordinateReferenceSystem spatialReferenceSystem2D, GeneralEnvelope coverageEnvelope2D, GridSampleDimension[] sampleDimensions) throws IOException
GridCoverage
for the provided PlanarImage
using the #raster2Model
that 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.
imageIndex
- image
- contains the data for the coverage to create.raster2Model
- is the MathTransform
that maps from the raster space to the model
space.GridCoverage
IOException
public static void setDecimationParameters(ImageReadParam readP, GridEnvelope baseGridRange, double[] requestedRes, double[] highestRes)
readP
- the imageRead parameter to be setrequestedRes
- the requested resolutions from which to determine the decimation
parameters.public static void setReadParameters(OverviewPolicy overviewPolicy, ImageReadParam readParam, GeneralEnvelope requestedEnvelope, Rectangle requestedDim, double[] highestRes, GridEnvelope gridRange, PixelInCell pixelInCell) throws IOException, TransformException
ImageReader.read(int, ImageReadParam)
.
It sets the passed ImageReadParam
in terms of decimation on reading using the
provided requestedEnvelope and requestedDim to evaluate the needed resolution.
overviewPolicy
- it can be one of Hints#VALUE_OVERVIEW_POLICY_IGNORE
, Hints#VALUE_OVERVIEW_POLICY_NEAREST
, Hints#VALUE_OVERVIEW_POLICY_QUALITY
or
Hints#VALUE_OVERVIEW_POLICY_SPEED
. It specifies the policy to compute the
overviews level upon request.readParam
- an instance of ImageReadParam
for setting the subsampling factors.requestedEnvelope
- the GeneralEnvelope
we are requesting.requestedDim
- the requested dimensions.gridRange
- IOException
TransformException
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, GeneralEnvelope coverageEnvelope2D) throws IOException
imageIndex
- coordinateReferenceSystem
- generalEnvelope
- mathTransform
- iUseJAI
- specify if the underlying read process should leverage on a JAI ImageRead
operation or a simple direct call to the read
method of a proper ImageReader
.useMultithreading
- specify if the underlying read process should use multithreading
when a JAI ImageRead operation is requestedoverviewPolicy
- the overview policy which need to be adoptedGridCoverage
IOException
public static PlanarImage readImage(ImageReaderSpi spi, Object input, int imageIndex, boolean useJAI, ImageReadParam imageReadParam, boolean useMultithreading) throws IOException
PlanarImage
given a set of parameter specifying the type of read operation
to be performed.imageIndex
- new
- FileImageInputStreamExtImplinput the input ImageInputStream
to be used for
reading the image.useJAI
- true
if we need to use a JAI ImageRead operation, false
if we
need a simple direct ImageReader.read(...)
call.imageReadParam
- an ImageReadParam
specifying the read parametersuseMultithreading
- true
if a JAI ImageRead operation is requested with support
for multithreading. This parameter will be ignored if requesting a direct read operation.PlanarImage
IOException
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, GeneralEnvelope envelope2D) throws IOException
null
in case of empty request.index
- imageReadParam
- isEmptyRequest
- needTransformation
- imageReaderSpi
- coverageName
- coverageFactory
- raster2Model
- coordinateReferenceSystem
- envelope2D
- IOException
- @TODO: handle more input typespublic static final boolean ensureValidString(String... strings)
public static boolean checkFileReadable(File file)
File
is a real file, exists and is readable.file
- the File
instance to check. Must not be null.true
in case the file is a real file, exists and is readable;
false
otherwise.public static String getFileInfo(File file)
File
object in terms of
its properties.
Useful for creating meaningful log messages.
public static Properties loadPropertiesFromURL(URL propsURL)
Copyright © 1996–2019 Geotools. All rights reserved.