Utilities { public static GridCoverage createCoverage(ImageReaderSpi spi, Object input, final int imageIndex, ImageReadParam imageReadParam, final boolean useJAI, final boolean useMultithreading, final boolean newTransform, final GridSampleDimension[] sampleDimensions, final String coverageName, GridCoverageFactory coverageFactory, MathTransform raster2Model, CoordinateReferenceSystem coordinateReferenceSystem, GeneralEnvelope coverageEnvelope2D) throws IOException { final PlanarImage image = readImage(spi, input, imageIndex, useJAI, imageReadParam, useMultithreading); if (newTransform) { final int ssWidth = image.getWidth(); final int ssHeight = image.getHeight(); final Rectangle sourceRegion = imageReadParam.getSourceRegion(); final double scaleX = sourceRegion.width / (1.0 * ssWidth); final double scaleY = sourceRegion.height / (1.0 * ssHeight); final double translateX = sourceRegion.x; final double translateY = sourceRegion.y; return Utilities.createCoverageFromImage(coverageFactory, coverageName, imageIndex, image, ConcatenatedTransform.create(ProjectiveTransform .create(new AffineTransform(scaleX, 0, 0, scaleY, translateX, translateY)), raster2Model), coordinateReferenceSystem, (GeneralEnvelope) null, sampleDimensions, true); } else { return Utilities.createCoverageFromImage(coverageFactory, coverageName, imageIndex, image, (MathTransform) null, (CoordinateReferenceSystem) null, coverageEnvelope2D, sampleDimensions, true); } } private  Utilities(); static ReferenceIdentifier[] getIdentifiers(final String nameIdentifier); static DefaultGeodeticDatum getDefaultGeodeticDatum(final String name,
            final double equatorialRadius, final double inverseFlattening, Unit unit); static File getFileFromCustomInput(Object input); @SuppressWarnings("deprecation") static CoordinateReferenceSystem getMercator2SPProjectedCRS(
            final double standardParallel, final double centralMeridian, final double natOriginLat,
            GeographicCRS sourceCRS, Hints hints); static GeographicCRS getBaseCRS(final double equatorialRadius,
            final double inverseFlattening); static String getAttributeValue(NamedNodeMap attributes, String attributeName); static Unit<? extends Quantity> parseUnit(final String uom); static Envelope getEnvelopeAsWGS84(final Envelope envelope, boolean get2D); static GeneralEnvelope getRequestedEnvelope2D(GeneralEnvelope requestedEnvelope); static Rectangle getCropRegion(GeneralEnvelope envelope,
            final MathTransform gridToWorldTransform); static GeneralEnvelope getIntersection(final Envelope2D baseEnvelope2D,
            final CoordinateReferenceSystem spatialReferenceSystem2D,
            GeneralEnvelope requestedEnvelope2D, Rectangle requestedDim,
            MathTransform2D readGridToWorld, final Envelope2D wgs84BaseEnvelope2D); static MathTransform getOriginalGridToWorld(MathTransform raster2Model,
            final PixelInCell pixInCell); static GeneralEnvelope evaluateRequestedParams(GridEnvelope originalGridRange,
            Envelope2D baseEnvelope2D, CoordinateReferenceSystem spatialReferenceSystem2D,
            MathTransform originalGridToWorld, GeneralEnvelope requestedEnvelope,
            Rectangle sourceRegion, Rectangle requestedDim, MathTransform2D readGridToWorld,
            Envelope2D wgs84BaseEnvelope2D); static GridCoverage createCoverageFromImage(final GridCoverageFactory coverageFactory,
            final String coverageName, int imageIndex, PlanarImage image,
            MathTransform raster2Model, final CoordinateReferenceSystem spatialReferenceSystem2D,
            GeneralEnvelope coverageEnvelope2D, final GridSampleDimension[] sampleDimensions,
            final boolean getGeophysics); static void setDecimationParameters(ImageReadParam readP, GridEnvelope baseGridRange,
            double[] requestedRes, double[] highestRes); static NameImpl buildCoverageName(URL input); static void setReadParameters(OverviewPolicy overviewPolicy, ImageReadParam readParam,
            GeneralEnvelope requestedEnvelope, Rectangle requestedDim, double[] highestRes,
            GridEnvelope gridRange, PixelInCell pixelInCell); static GridCoverage createCoverage(ImageReaderSpi spi, Object input,
            final int imageIndex, ImageReadParam imageReadParam, final boolean useJAI,
            final boolean useMultithreading, final boolean newTransform,
            final GridSampleDimension[] sampleDimensions, final String coverageName,
            GridCoverageFactory coverageFactory, MathTransform raster2Model,
            CoordinateReferenceSystem coordinateReferenceSystem, GeneralEnvelope coverageEnvelope2D); static PlanarImage readImage(final ImageReaderSpi spi, final Object input,
            final int imageIndex, final boolean useJAI, final ImageReadParam imageReadParam,
            final boolean useMultithreading); static GridCoverage compute(Object input, final int imageIndex,
            final boolean needTransformation, final boolean isEmptyRequest, final boolean useJAI,
            ImageReadParam imageReadParam, final boolean useMultithreading,
            final GridSampleDimension[] sampleDimensions, final ImageReaderSpi imageReaderSpi,
            final String coverageName, final GridCoverageFactory coverageFactory,
            final MathTransform raster2Model,
            final CoordinateReferenceSystem coordinateReferenceSystem,
            final GeneralEnvelope envelope2D); final static boolean ensureValidString(final String... strings); static String buildIso8601Time(String date, String time); static boolean checkFileReadable(final File file); static String getFileInfo(final File file); static Properties loadPropertiesFromURL(URL propsURL);  }
@Test public void testCreateCoverage() throws IOException{ GridCoverageFactory coverageFactory = new GridCoverageFactory(GeoTools.getDefaultHints()); String coverageName = "test"; int imageIndex = 0; PlanarImage image = ConstantDescriptor.create(10f, 10f, new Byte[]{1}, GeoTools.getDefaultHints()); MathTransform raster2Model = new AffineTransform2D(AffineTransform.getScaleInstance(2, 2)); CoordinateReferenceSystem spatialReferenceSystem2D = DefaultGeographicCRS.WGS84; Rectangle bounds = image.getBounds(); GridGeometry2D gg2D = new GridGeometry2D(new GridEnvelope2D(bounds), raster2Model, spatialReferenceSystem2D); GeneralEnvelope coverageEnvelope2D = new GeneralEnvelope(gg2D.getEnvelope()); GridSampleDimension[] sampleDimensions = new GridSampleDimension[]{new GridSampleDimension("testDim")}; boolean getGeophysics = false; GridCoverage2D coverage1 = (GridCoverage2D) Utilities.createCoverageFromImage(coverageFactory , coverageName , imageIndex, image , raster2Model , spatialReferenceSystem2D, null, sampleDimensions, getGeophysics); GridCoverage2D coverage2 = (GridCoverage2D) Utilities.createCoverageFromImage(coverageFactory , coverageName , imageIndex, image , null , null, coverageEnvelope2D, sampleDimensions, getGeophysics); assertTrue(coverage1.getEnvelope2D().boundsEquals(coverage2.getEnvelope2D(), 0, 1, 0.01d)); assertSame(coverage1.getRenderedImage(), coverage2.getRenderedImage()); }