3

I have a raster file in ESRI ArcGrid format (e.g. hdr.adf). I would like to run some analysis using GeoTools. I've never used the coverage classes before and I'm having a few problems out of the gates.

I can instantiate the AIGReader just fine and I get the correct values when I check the bounds. Example:

    BaseGDALGridCoverage2DReader reader = new AIGReader(file);

    System.out.println(reader.getSource());
    for (String coverage : reader.getGridCoverageNames()){
        System.out.println(coverage);
    }
    System.out.println(reader.getOriginalEnvelope());
    System.out.println(reader.getOriginalGridRange());
    System.out.println(reader.getCoordinateReferenceSystem());

This is the stdout:

   Jan 06, 2015 6:38:09 PM it.geosolutions.imageio.gdalframework.GDALUtilities loadGDAL
   INFO: GDAL Native Library loaded (version: 1.11.1)
   Jan 06, 2015 6:38:09 PM org.geotools.coverageio.gdal.BaseGDALGridCoverage2DReader setCoverageProperties
   INFO: crs not found, proceeding with default crs
   K:\Landscan\LandScan_Archive_2000_2012\LandScan2000\lspop2000\hdr.adf
   geotools_coverage
   GeneralEnvelope[(-180.0, -90.0), (179.99999999999858, 85.99999999999929)]
   GridEnvelope2D[0..43199, 0..21119]
   LOCAL_CS["Wildcard 2D cartesian plane in metric unit",
     LOCAL_DATUM["Unknown", 0],
     UNIT["m", 1.0],
     AXIS["x", EAST],
     AXIS["y", NORTH],
     AUTHORITY["EPSG","404000"]]

When I call the BaseGDALGridCoverage2DReader.read() method, I get a null pointer exception:

    GridCoverage2D gc = (GridCoverage2D) reader.read(null); 

The read method throws the following Exception:

Exception in thread "main" java.lang.NullPointerException
    at org.geotools.coverageio.RasterLayerRequest.setBaseParameters(RasterLayerRequest.java:902)
    at org.geotools.coverageio.RasterLayerRequest.<init>(RasterLayerRequest.java:206)
    at org.geotools.coverageio.BaseGridCoverage2DReader.read(BaseGridCoverage2DReader.java:400)

I tried passing in an array of GeneralParameterValue but I still get a null pointer exception. Example:

    ParameterValue<OverviewPolicy> policy = AbstractGridFormat.OVERVIEW_POLICY.createValue();
    policy.setValue(OverviewPolicy.IGNORE);
    ParameterValue<String> gridsize = AbstractGridFormat.SUGGESTED_TILE_SIZE.createValue();
    ParameterValue<Boolean> useJaiRead = AbstractGridFormat.USE_JAI_IMAGEREAD.createValue();
    useJaiRead.setValue(true);

    reader.read(new GeneralParameterValue[]{policy, gridsize, useJaiRead});

I'm using Java 1.6 so I'm stuck with GeoTools 10.8.

Any suggestions?

UPDATE

QGIS and GDAL can open the file just file. Here's a rendering from QGIS.

QGIS

Here's the output from gdalinfo. As you can see the projection is not set. I hope this isn't the cause. If it is, is there a way to tell the reader which projection to use?

Driver: AIG/Arc/Info Binary Grid
Files: K:\Landscan\LandScan_Archive_2000_2012\LandScan2000\lspop2000
       K:\Landscan\LandScan_Archive_2000_2012\LandScan2000\lspop2000.aux.xml
       K:\Landscan\LandScan_Archive_2000_2012\LandScan2000\lspop2000\dblbnd.adf
       K:\Landscan\LandScan_Archive_2000_2012\LandScan2000\lspop2000\hdr.adf
       K:\Landscan\LandScan_Archive_2000_2012\LandScan2000\lspop2000\log
       K:\Landscan\LandScan_Archive_2000_2012\LandScan2000\lspop2000\metadata.xml
       K:\Landscan\LandScan_Archive_2000_2012\LandScan2000\lspop2000\sta.adf
       K:\Landscan\LandScan_Archive_2000_2012\LandScan2000\lspop2000\vat.adf
       K:\Landscan\LandScan_Archive_2000_2012\LandScan2000\lspop2000\w001001.adf
       K:\Landscan\LandScan_Archive_2000_2012\LandScan2000\lspop2000\w001001x.adf
Size is 43200, 21120
Coordinate System is `'
Origin = (-180.000000000000000,85.999999999999289)
Pixel Size = (0.008333333333333,-0.008333333333333)
Corner Coordinates:
Upper Left  (-180.0000000,  86.0000000)
Lower Left  (-180.0000000, -90.0000000)
Upper Right ( 180.0000000,  86.0000000)
Lower Right ( 180.0000000, -90.0000000)
Center      (  -0.0000000,  -2.0000000)
Band 1 Block=256x4 Type=Int32, ColorInterp=Undefined
  Description = lspop2000
  Min=0.000 Max=159004.000
  Minimum=0.000, Maximum=35453.000, Mean=14.586, StdDev=221.326
  NoData Value=-2147483647
  Metadata:
    LAYER_TYPE=athematic
    STATISTICS_MAXIMUM=35453
    STATISTICS_MEAN=14.58631887449
    STATISTICS_MINIMUM=0
    STATISTICS_STDDEV=221.32624697214
8
  • Is it possible that you've 'broken' the GRID by copying it using a filesystem manager (like explorer)? Commented Jan 7, 2015 at 1:01
  • I don't think so. I can view the data with QGIS and gdal apps like gdalinfo and gdal_translate work just fine.
    – Peter
    Commented Jan 7, 2015 at 2:00
  • Perhaps use Gdal_Translate to convert to GeoTiff then read from the Tiff, just remember to delete the temp file when you're finished. Commented Jan 7, 2015 at 2:06
  • Not a bad idea. For my own sanity, can you confirm that I'm calling the reader correctly?
    – Peter
    Commented Jan 7, 2015 at 2:59
  • I don't know, I don't use Java or GeoTools. I do however have a lot of experience with Esri GRID and GDAL. Commented Jan 7, 2015 at 3:02

1 Answer 1

1

While this doesn't actually help you I can read a Grid file using the following code:

    File raster = new File("../../data/nzdem/nzdem500/hdr.adf");

    AbstractGridFormat format = GridFormatFinder.findFormat(raster);
    AbstractGridCoverage2DReader reader = format.getReader(raster);
    GridCoverage2D cov;
    try {
        cov = reader.read(null);
    } catch (IOException giveUp) {
        throw new RuntimeException(giveUp);
    }

I get the following log file notes:

Jan 07, 2015 10:06:10 AM it.geosolutions.imageio.gdalframework.GDALUtilities loadGDAL INFO: GDAL Native Library loaded (version: 1.9.2)

Jan 07, 2015 10:06:10 AM org.geotools.coverageio.gdal.BaseGDALGridCoverage2DReader setCoverageProperties

INFO: crs not found, proceeding with default crs

Error: Could not find mediaLib accelerator wrapper classes. Continuing in pure Java mode. Occurs in: com.sun.media.jai.mlib.MediaLibAccessor

6
  • Thanks Ian. Unfortunately, with this more generic approach, the GridFormatFinder.findFormat() is throwing an error. I have removed all the drivers I don't need from my project so I'm getting a "NoClassDefFoundError: it/geosolutions/imageio/plugins/idrisi/IDRISIImageReaderSpi"
    – Peter
    Commented Jan 7, 2015 at 11:07
  • I don't think you can do that
    – Ian Turton
    Commented Jan 7, 2015 at 12:40
  • I can't do what exactly? Prune unused jars? Call the AIGReader directly?
    – Peter
    Commented Jan 7, 2015 at 12:51
  • prune the unused jars - there are compiled references to them in the code base.
    – Ian Turton
    Commented Jan 7, 2015 at 12:58
  • 1
    But what if you are using a gdal format like arcgrid?
    – Ian Turton
    Commented Jan 9, 2015 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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