OperationJAI.doOperation throws NullPointerException when working on GridSampleDimension without categories. ------------------------------------------------------------------------------------------------------------
Key: GEOT-1741 URL: http://jira.codehaus.org/browse/GEOT-1741 Project: GeoTools Issue Type: Bug Components: core coverage Affects Versions: 2.5-M0, 2.4.1 Reporter: Daniele Romagnoli Assignee: Martin Desruisseaux Attachments: test1.tif A Rescale operation performed on a GridCoverage built with a single GridSampleDimension without categories results in a NullPointerException thrown by the OperationJAI class when calling deriveSampleDimension(...). Basically, the deriveSampledDimension method invoked by the doOperation method contains the code: Category[] categoryArray = (Category[]) sampleDim.getCategories().toArray(); The GridSampleDimension constructor allows the creation of a Sample Dimension without categories. In such a case, the getCategories method returns null. Here below there is a standalone test case which reproduces the problem (test data is in attachment): ------------------------------------------------------------------------------------------------------ package org.geotools.coverage.processing; import java.awt.Rectangle; import java.io.File; import javax.imageio.ImageIO; import javax.media.jai.PlanarImage; import junit.framework.TestCase; import org.geotools.coverage.CoverageFactoryFinder; import org.geotools.coverage.GridSampleDimension; import org.geotools.coverage.grid.GeneralGridRange; import org.geotools.coverage.grid.GridCoverage2D; import org.geotools.coverage.grid.GridCoverageFactory; import org.geotools.coverage.processing.operation.Rescale; import org.geotools.geometry.GeneralEnvelope; import org.geotools.referencing.crs.DefaultGeographicCRS; import org.geotools.referencing.operation.builder.GridToEnvelopeMapper; import org.opengis.parameter.ParameterValueGroup; import org.opengis.referencing.operation.MathTransform; public class OperationJAITest extends TestCase { private PlanarImage image; public OperationJAITest(String name) { super(name); } protected void setUp() throws Exception { image = PlanarImage.wrapRenderedImage(ImageIO.read(new File( "c:/test1.tif"))); super.setUp(); } protected void tearDown() throws Exception { super.tearDown(); } public void test() { // // // // Setting SampleDimensions // // // final GridSampleDimension[] bands = new GridSampleDimension[1]; bands[0] = new GridSampleDimension("GRAY").geophysics(false); // // // // Preparing coverage properties // // // final GeneralGridRange gridRange = new GeneralGridRange(new Rectangle( 0, 0, image.getWidth(), image.getHeight())); final GeneralEnvelope envelope = new GeneralEnvelope(new double[] { 40.0, 40.0 }, new double[] { 40.004, 40.004 }); final GridToEnvelopeMapper geMapper = new GridToEnvelopeMapper(); geMapper.setEnvelope(envelope); geMapper.setGridRange(gridRange); final MathTransform raster2Model = geMapper.createTransform(); // // // // Creating the coverage // // // final GridCoverageFactory gcf = CoverageFactoryFinder .getGridCoverageFactory(null); final GridCoverage2D gc = gcf.create("coverage", image, DefaultGeographicCRS.WGS84, raster2Model, bands, null, null); // // // // Rescale operation // // // final DefaultProcessor proc = new DefaultProcessor(null); Rescale rescale = new Rescale(); ParameterValueGroup parameters = proc.getOperation("Rescale") .getParameters(); parameters.parameter("Source").setValue(gc); parameters.parameter("constants").setValue(new double[] { 0.005d }); parameters.parameter("offsets").setValue(new double[] { 0.0d }); GridCoverage2D gc2d = (GridCoverage2D) rescale.doOperation(parameters, null); } } -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Geotools-devel mailing list Geotools-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-devel