3

I'm trying to process globcover, which is a .tif file of 374mb. Running the following code:

File tiffFile = new File("C:\\Users\\CAA\\Desktop\\test.tif");        
GeoTiffReader reader = new GeoTiffReader(tiffFile);        
grid =reader.read(null);
gridData = grid.getRenderedImage().getData(); //row 32

I get the following error:

java.lang.IllegalArgumentException: Requested region cannot be represented by a single Raster.
at javax.media.jai.PlanarImage.getData(PlanarImage.java:2163)
at javax.media.jai.PlanarImage.getData(PlanarImage.java:2016)
at javax.media.jai.RenderedOp.getData(RenderedOp.java:2266)
at de.myapplication.de.myapplicatoin.GeoTiff.initTif(GeoTiff.java:32)

After playing around a bit with QGis and it's Clipper tool i noticed that if i extract a smaller area, the reader works as intended. If i extract huger areas (i.e. entire europe or the entire world) i get the error again. Maybe it's just correlation and not causation, but this leads me to believe that there is somewhere a limit inside the reader. But what is the limit?

As requested the output of gdalinfo for the original tif file.

Size is 129600, 55800
Coordinate System is:
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0],
    UNIT["degree",0.0174532925199433],
    AUTHORITY["EPSG","4326"]]
Origin = (-180.001388888888900,90.001388888888883)
Pixel Size = (0.002777777777778,-0.002777777777778)
Metadata:
  AREA_OR_POINT=Area
  Authors=Sophie Bontemps <sophie.bontemps@uclouvain.be>,Eric Van Bogaert <eric.vanbogaert@uclouvain.be>,Pierre Defourny <pierre.defourny@uclouvain.be>
  Copyright=Copyright ┬®UCL Geomatics, BELGIUM 1999-2010
  Generate by=gdal_mean
  process begin time=2010-12-23T09:49:37
  process files=CL5_GLOBCOVER-L5_CLASSIF_2009_V2.3.20101220.tif
  process finish time=2010-12-23T09:57:38
Image Structure Metadata:
  COMPRESSION=LZW
  INTERLEAVE=BAND
Corner Coordinates:
Upper Left  (-180.0013889,  90.0013889) (180d 0' 5.00"W, 90d 0' 5.00"N)
Lower Left  (-180.0013889, -64.9986111) (180d 0' 5.00"W, 64d59'55.00"S)
Upper Right ( 179.9986111,  90.0013889) (179d59'55.00"E, 90d 0' 5.00"N)
Lower Right ( 179.9986111, -64.9986111) (179d59'55.00"E, 64d59'55.00"S)
Center      (  -0.0013889,  12.5013889) (  0d 0' 5.00"W, 12d30' 5.00"N)
Band 1 Block=129600x1 Type=Byte, ColorInterp=Gray
  Min=11.000 Max=230.000
  Minimum=11.000, Maximum=230.000, Mean=183.164, StdDev=55.663
  NoData Value=0
  Metadata:
    STATISTICS_MAXIMUM=230
    STATISTICS_MEAN=183.16435194952
    STATISTICS_MINIMUM=11
    STATISTICS_STDDEV=55.662605157347
  • can you tell us so more about the tif, what is the output of gdalinfo? – Ian Turton Nov 24 '15 at 8:46
  • see my edit for gdalinfo output – CAA Nov 24 '15 at 16:55
1

The problem seems to be that the Java Raster classes used to extract the data from your raster are using an int to store the number of cells in the raster. So for you file it is 129600 * 55800 which is 7,231,680,000 which exceeds the Max int (2,147,483,647) so it wraps round to a negative number (-1,358,254,592). The JAI helpfully tells you that you need more than one raster to read out the data in that case, though the message is a little enigmatic.

So you can either select fewer cells at a time for your processing using a smaller envelope

gridData = grid.getRenderedImage().getData(new Rectangle(100, 100));

or work through the pixels one at a time:

GridEnvelope gridRange2D = grid.getGridGeometry().getGridRange();
for(int i=gridRange2D.getLow(0);i<gridRange2D.getHigh(0);i++) {
  for(int j=gridRange2D.getLow(1);j<gridRange2D.getHigh(1);j++) {
      int[] dest = new int[1];
      grid.evaluate(new GridCoordinates2D(i, j), dest );
      System.out.println(i+","+j+"="+dest[0]);
  }
}

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.