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.
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