@Test public void testCreateWithoutBands() throws NoSuchAuthorityCodeException, FactoryException { String name = "Test Grid Coverage"; BufferedImage image = new BufferedImage(10, 10, BufferedImage.TYPE_BYTE_GRAY); WritableRaster raster = image.getRaster(); int[] pixel = {0}; for (int x = 0; x < 10; x++) { for (int y = 0; y < 10; y++) { pixel[0] = x * y; raster.setPixel(x, y, pixel); } } GeneralEnvelope env = new GeneralEnvelope(new Rectangle2D.Double(10, 10, 10, 10)); CoordinateReferenceSystem crs = CRS.decode("EPSG:4326"); env.setCoordinateReferenceSystem(crs); GridCoverage2D coverage = null; try { coverage = new GridCoverageFactory().create(name, raster, env, null); } catch (NullPointerException e) { fail( "NullPointerException was thrown despite the javadocs indicating that 'bands' is nullable"); } int[] dest = new int[1]; coverage.evaluate(new Point2D.Double(15, 14), dest); assertEquals(20, dest[0]); AffineTransform tx = AffineTransform.getTranslateInstance(10, 10); MathTransform mathTx = ProjectiveTransform.create(new GeneralMatrix(tx)); try { coverage = new GridCoverageFactory().create(name, raster, crs, mathTx, null); } catch (NullPointerException e) { fail( "NullPointerException was thrown despite the javadocs indicating that 'bands' is nullable"); } coverage.evaluate(new Point2D.Double(15, 14), dest); assertEquals(20, dest[0]); }
public GridCoverage2D create( final CharSequence name, final ImageFunction function, final GridGeometry2D gridGeometry, final GridSampleDimension[] bands, final Map<?, ?> properties) { final MathTransform transform = gridGeometry.getGridToCRS2D(); if (!(transform instanceof AffineTransform)) { throw new IllegalArgumentException(Errors.format(ErrorKeys.NOT_AN_AFFINE_TRANSFORM)); } final AffineTransform at = (AffineTransform) transform; if (at.getShearX() != 0 || at.getShearY() != 0) { throw new IllegalArgumentException("Shear and rotation not supported"); } final double xScale = at.getScaleX(); final double yScale = at.getScaleY(); final double xTrans = -at.getTranslateX() / xScale; final double yTrans = -at.getTranslateY() / yScale; final GridEnvelope range = gridGeometry.getGridRange(); final PlanarImage image = new ImageWorker() .function( function, range.getSpan(0), range.getSpan(1), (float) xScale, (float) yScale, (float) xTrans, (float) yTrans) .getPlanarImage(); return create(name, image, gridGeometry, bands, null, properties); }
GridCoverageFactory extends AbstractFactory { public GridCoverage2D create( final CharSequence name, final ImageFunction function, final GridGeometry2D gridGeometry, final GridSampleDimension[] bands, final Map<?, ?> properties) { final MathTransform transform = gridGeometry.getGridToCRS2D(); if (!(transform instanceof AffineTransform)) { throw new IllegalArgumentException(Errors.format(ErrorKeys.NOT_AN_AFFINE_TRANSFORM)); } final AffineTransform at = (AffineTransform) transform; if (at.getShearX() != 0 || at.getShearY() != 0) { throw new IllegalArgumentException("Shear and rotation not supported"); } final double xScale = at.getScaleX(); final double yScale = at.getScaleY(); final double xTrans = -at.getTranslateX() / xScale; final double yTrans = -at.getTranslateY() / yScale; final GridEnvelope range = gridGeometry.getGridRange(); final PlanarImage image = new ImageWorker() .function( function, range.getSpan(0), range.getSpan(1), (float) xScale, (float) yScale, (float) xTrans, (float) yTrans) .getPlanarImage(); return create(name, image, gridGeometry, bands, null, properties); } }
GridCoverageFactory extends AbstractFactory { public GridCoverage2D create( final CharSequence name, final ImageFunction function, final GridGeometry2D gridGeometry, final GridSampleDimension[] bands, final Map<?, ?> properties) { final MathTransform transform = gridGeometry.getGridToCRS2D(); if (!(transform instanceof AffineTransform)) { throw new IllegalArgumentException(Errors.format(ErrorKeys.NOT_AN_AFFINE_TRANSFORM)); } final AffineTransform at = (AffineTransform) transform; if (at.getShearX() != 0 || at.getShearY() != 0) { throw new IllegalArgumentException("Shear and rotation not supported"); } final double xScale = at.getScaleX(); final double yScale = at.getScaleY(); final double xTrans = -at.getTranslateX() / xScale; final double yTrans = -at.getTranslateY() / yScale; final GridEnvelope range = gridGeometry.getGridRange(); final PlanarImage image = new ImageWorker() .function( function, range.getSpan(0), range.getSpan(1), (float) xScale, (float) yScale, (float) xTrans, (float) yTrans) .getPlanarImage(); return create(name, image, gridGeometry, bands, null, properties); } GridCoverageFactory();  GridCoverageFactory(final Hints userHints); }
GridCoverageFactory extends AbstractFactory { public GridCoverage2D create( final CharSequence name, final ImageFunction function, final GridGeometry2D gridGeometry, final GridSampleDimension[] bands, final Map<?, ?> properties) { final MathTransform transform = gridGeometry.getGridToCRS2D(); if (!(transform instanceof AffineTransform)) { throw new IllegalArgumentException(Errors.format(ErrorKeys.NOT_AN_AFFINE_TRANSFORM)); } final AffineTransform at = (AffineTransform) transform; if (at.getShearX() != 0 || at.getShearY() != 0) { throw new IllegalArgumentException("Shear and rotation not supported"); } final double xScale = at.getScaleX(); final double yScale = at.getScaleY(); final double xTrans = -at.getTranslateX() / xScale; final double yTrans = -at.getTranslateY() / yScale; final GridEnvelope range = gridGeometry.getGridRange(); final PlanarImage image = new ImageWorker() .function( function, range.getSpan(0), range.getSpan(1), (float) xScale, (float) yScale, (float) xTrans, (float) yTrans) .getPlanarImage(); return create(name, image, gridGeometry, bands, null, properties); } GridCoverageFactory();  GridCoverageFactory(final Hints userHints); GridCoverage2D create(
            final CharSequence name,
            final ImageFunction function,
            final GridGeometry2D gridGeometry,
            final GridSampleDimension[] bands,
            final Map<?, ?> properties); GridCoverage2D create(
            final CharSequence name, final float[][] matrix, final Envelope envelope); GridCoverage2D create(
            final CharSequence name, final WritableRaster raster, final Envelope envelope); GridCoverage2D create(
            final CharSequence name,
            final WritableRaster raster,
            final Envelope envelope,
            final double[] minValues,
            final double[] maxValues,
            final Unit<?> units,
            final Color[][] colors,
            final RenderingHints hints); GridCoverage2D create(
            final CharSequence name,
            final WritableRaster raster,
            final CoordinateReferenceSystem crs,
            final MathTransform gridToCRS,
            final double[] minValues,
            final double[] maxValues,
            final Unit<?> units,
            final Color[][] colors,
            final RenderingHints hints); GridCoverage2D create(
            final CharSequence name,
            final WritableRaster raster,
            final Envelope envelope,
            GridSampleDimension[] bands); GridCoverage2D create(
            final CharSequence name,
            final WritableRaster raster,
            final CoordinateReferenceSystem crs,
            final MathTransform gridToCRS,
            GridSampleDimension[] bands); GridCoverage2D create(
            final CharSequence name, final RenderedImage image, final Envelope envelope); GridCoverage2D create(
            final CharSequence name,
            final RenderedImage image,
            Envelope envelope,
            final GridSampleDimension[] bands,
            final GridCoverage[] sources,
            final Map<?, ?> properties); GridCoverage2D create(
            final CharSequence name,
            final RenderedImage image,
            final CoordinateReferenceSystem crs,
            final MathTransform gridToCRS,
            final GridSampleDimension[] bands,
            final GridCoverage[] sources,
            final Map<?, ?> properties); GridCoverage2D create(
            final CharSequence name,
            final RenderedImage image,
            GridGeometry2D gridGeometry,
            final GridSampleDimension[] bands,
            final GridCoverage[] sources,
            final Map<?, ?> properties); }
GridCoverageFactory extends AbstractFactory { public GridCoverage2D create( final CharSequence name, final ImageFunction function, final GridGeometry2D gridGeometry, final GridSampleDimension[] bands, final Map<?, ?> properties) { final MathTransform transform = gridGeometry.getGridToCRS2D(); if (!(transform instanceof AffineTransform)) { throw new IllegalArgumentException(Errors.format(ErrorKeys.NOT_AN_AFFINE_TRANSFORM)); } final AffineTransform at = (AffineTransform) transform; if (at.getShearX() != 0 || at.getShearY() != 0) { throw new IllegalArgumentException("Shear and rotation not supported"); } final double xScale = at.getScaleX(); final double yScale = at.getScaleY(); final double xTrans = -at.getTranslateX() / xScale; final double yTrans = -at.getTranslateY() / yScale; final GridEnvelope range = gridGeometry.getGridRange(); final PlanarImage image = new ImageWorker() .function( function, range.getSpan(0), range.getSpan(1), (float) xScale, (float) yScale, (float) xTrans, (float) yTrans) .getPlanarImage(); return create(name, image, gridGeometry, bands, null, properties); } GridCoverageFactory();  GridCoverageFactory(final Hints userHints); GridCoverage2D create(
            final CharSequence name,
            final ImageFunction function,
            final GridGeometry2D gridGeometry,
            final GridSampleDimension[] bands,
            final Map<?, ?> properties); GridCoverage2D create(
            final CharSequence name, final float[][] matrix, final Envelope envelope); GridCoverage2D create(
            final CharSequence name, final WritableRaster raster, final Envelope envelope); GridCoverage2D create(
            final CharSequence name,
            final WritableRaster raster,
            final Envelope envelope,
            final double[] minValues,
            final double[] maxValues,
            final Unit<?> units,
            final Color[][] colors,
            final RenderingHints hints); GridCoverage2D create(
            final CharSequence name,
            final WritableRaster raster,
            final CoordinateReferenceSystem crs,
            final MathTransform gridToCRS,
            final double[] minValues,
            final double[] maxValues,
            final Unit<?> units,
            final Color[][] colors,
            final RenderingHints hints); GridCoverage2D create(
            final CharSequence name,
            final WritableRaster raster,
            final Envelope envelope,
            GridSampleDimension[] bands); GridCoverage2D create(
            final CharSequence name,
            final WritableRaster raster,
            final CoordinateReferenceSystem crs,
            final MathTransform gridToCRS,
            GridSampleDimension[] bands); GridCoverage2D create(
            final CharSequence name, final RenderedImage image, final Envelope envelope); GridCoverage2D create(
            final CharSequence name,
            final RenderedImage image,
            Envelope envelope,
            final GridSampleDimension[] bands,
            final GridCoverage[] sources,
            final Map<?, ?> properties); GridCoverage2D create(
            final CharSequence name,
            final RenderedImage image,
            final CoordinateReferenceSystem crs,
            final MathTransform gridToCRS,
            final GridSampleDimension[] bands,
            final GridCoverage[] sources,
            final Map<?, ?> properties); GridCoverage2D create(
            final CharSequence name,
            final RenderedImage image,
            GridGeometry2D gridGeometry,
            final GridSampleDimension[] bands,
            final GridCoverage[] sources,
            final Map<?, ?> properties);  }