2

System: Eclipse IDE in Windows 10 VM Java 8

My code segment that the exception is being thrown:

private void displayLayers(File rasterFile) throws Exception {
    Hints hints = new Hints();

    reader = new RPFTOCReader(rasterFile, hints);


    final MapContent map = new MapContent();
    map.setTitle("Jonathan's attempt");

    Style rasterStyle = createGreyscaleStyle();
    Layer rasterLayer = new GridReaderLayer(reader, rasterStyle);

    map.addLayer(rasterLayer);


    frame = new JMapFrame(map);
    frame.setSize(800, 600);
    frame.enableStatusBar(true);
    frame.enableToolBar(true);

    JMenuBar menuBar = new JMenuBar();
    frame.setJMenuBar(menuBar);
    menuBar.add(new JMenu("Raster"));

    frame.setVisible(true);
}

the createGreyscaleStyle() method is the same one from this tutorial.

Exception:

    Jan 02, 2018 2:37:41 PM it.geosolutions.imageio.gdalframework.GDALUtilities loadGDAL
    INFO: GDAL Native Library loaded (version: 2.2.1)
    Exception in thread "main" java.lang.NegativeArraySizeException
        at it.geosolutions.imageio.gdalframework.GDALImageReader.readDatasetRaster(GDALImageReader.java:331)
        at it.geosolutions.imageio.gdalframework.GDALImageReader.read(GDALImageReader.java:952)
        at org.geotools.coverageio.RasterLayerResponse.readRaster(RasterLayerResponse.java:440)
        at org.geotools.coverageio.RasterLayerResponse.createCoverage(RasterLayerResponse.java:210)
        at org.geotools.coverageio.RasterLayerResponse.compute(RasterLayerResponse.java:180)
        at org.geotools.coverageio.BaseGridCoverage2DReader.requestCoverage(BaseGridCoverage2DReader.java:606)
        at org.geotools.coverageio.BaseGridCoverage2DReader.read(BaseGridCoverage2DReader.java:387)
        at org.geotools.raster.ImageLab.createGreyscaleStyle(ImageLab.java:189)
        at org.geotools.raster.ImageLab.displayLayers(ImageLab.java:107)
        at org.geotools.raster.ImageLab.getLayersAndDisplay(ImageLab.java:95)
        at org.geotools.raster.ImageLab.main(ImageLab.java:69)

    OpenGL Warning: crPixelCopy3D:  simply crMemcpy'ing from srcPtr to dstPtr
    OpenGL Warning: crPixelCopy3D:  simply crMemcpy'ing from srcPtr to dstPtr
    OpenGL Warning: crPixelCopy3D:  simply crMemcpy'ing from srcPtr to dstPtr
    OpenGL Warning: crPixelCopy3D:  simply crMemcpy'ing from srcPtr to dstPtr
    OpenGL Warning: crPixelCopy3D:  simply crMemcpy'ing from srcPtr to dstPtr
    OpenGL Warning: crPixelCopy3D:  simply crMemcpy'ing from srcPtr to dstPtr
    OpenGL Warning: crPixelCopy3D:  simply crMemcpy'ing from srcPtr to dstPtr
    OpenGL Warning: crPixelCopy3D:  simply crMemcpy'ing from srcPtr to dstPtr

Tracking the stack trace

The exception is thrown within the createGreyscaleStyle() method within my code (link to method is mentioned above) which is called from the Style object I attempt to make within my code excerpt. Within the createGreyscaleStyle(), the reader.read() function is called which eventually calls readDatasetRaster() (method in GDALImageReader).

On line 327 of GDALImageReader the calculated bufferSize is -1173618688, dstWidth is 75264, dstHeight is 41472, and when pixels is first calculated it's -1173618688.

When I run gdalinfo on the A.TOC file I get a size that is 75264, 41472 so it looks like the reader is extracting accurate data.

Problem: Don't know how to account for the negative value of bufferSize.

1

Your image is too big, or the author of the code didn't expect it to be that big. In GDALImageReader both pixels and bufferSize are integers and in Java MaxInt is 2,147,483,647. While your image size is (75264×41472) or 3,121,348,608 so it overflows and becomes negative.

This is a bug and you should raise a bug report and preferably a PR with the fix in too.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.