Class Utilities

  • public class Utilities
    extends Object
    Daniele Romagnoli, GeoSolutions
    • Method Detail

      • getDefaultGeodeticDatum

        public static DefaultGeodeticDatum getDefaultGeodeticDatum​(String name,
                                                                   double equatorialRadius,
                                                                   double inverseFlattening,
                                                                   Unit<Length> unit)
        Build a DefaultGeodeticDatum given a set of parameters.
        name - the datum name
        equatorialRadius - the equatorial radius parameter
        inverseFlattening - the inverse flattening parameter
        unit - the UoM
        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.
      • getBaseCRS

        public static GeographicCRS getBaseCRS​(double equatorialRadius,
                                               double inverseFlattening)
        Build a base GeographicCRS given the parameters to specify a Geodetic Datum
      • getAttributeValue

        public 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.
        attributes - the attributes map
        attributeName - the requested attribute
        the value of the requested attribute as a String. Returns null in case of no attribute found.
      • parseUnit

        public static Unit<? extends Quantity<?>> parseUnit​(String uom)
        Return a Unit instance for the specified uom String.
      • 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.
        envelope - the crop envelope
        gridToWorldTransform - the grid2world transformation
        a Rectangle representing the crop region.
        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,
        Returns the intersection between the base envelope and the requested envelope.
        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 read
        wgs84BaseEnvelope2D - 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.
        the resulting intersection of envelopes. In case of empty intersection, this method is allowed to return null
      • getOriginalGridToWorld

        public static MathTransform getOriginalGridToWorld​(MathTransform raster2Model,
                                                           PixelInCell pixInCell)
        Retrieves the original grid to world transformation for this AbstractGridCoverage2DReader.
        pixInCell - specifies the datum of the transformation we want.
        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 ImageIO to do crop-on-read.

        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 used
        the adjusted requested envelope, empty if no requestedEnvelope has been specified, 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 occurs
      • 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.
        readP - the imageRead parameter to be set
        requestedRes - the requested resolutions from which to determine the decimation parameters.
      • buildCoverageName

        public static NameImpl buildCoverageName​(URL input)
      • 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.
        useJAI - 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 requested
        a GridCoverage
      • readImage

        public static PlanarImage readImage​(ImageReaderSpi spi,
                                            Object input,
                                            int imageIndex,
                                            boolean useJAI,
                                            ImageReadParam imageReadParam,
                                            boolean useMultithreading)
                                     throws IOException
        Returns a PlanarImage given a set of parameter specifying the type of read operation to be performed.
        input - the input 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 call.
        imageReadParam - an ImageReadParam specifying the read parameters
        useMultithreading - true if a JAI ImageRead operation is requested with support for multithreading. This parameter will be ignored if requesting a direct read operation.
        the read PlanarImage
      • ensureValidString

        public static final boolean ensureValidString​(String... strings)
      • checkFileReadable

        public static boolean checkFileReadable​(File file)
        Checks that a 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.
      • getFileInfo

        public static String getFileInfo​(File file)
        Creates a human readable message that describe the provided File object in terms of its properties.

        Useful for creating meaningful log messages.

        file - the File object to create a descriptive message for
        a String containing a descriptive message about the provided File.
      • loadPropertiesFromURL

        public static Properties loadPropertiesFromURL​(URL propsURL)