[geotk] Error while reading netCDF file

Hendy Sumanto hsumanto at vpac.org
Tue Sep 6 23:01:57 EDT 2011


> However I didn't had the time to test the full image reading yet (I just tested 
> that the CRS metadata are now correctly created). If you have a chance, you can 
> test either by using the 3.x-SNAPSHOT version

I just tested reading the dem20_r500_3112 netCDF file and still getting the below error message:

Exception in thread "main" java.lang.IndexOutOfBoundsException: ac141c00
	at org.geotoolkit.math.XMath.toNaN(XMath.java:481)
	at org.geotoolkit.coverage.Category.<init>(Category.java:522)
	at org.geotoolkit.coverage.GeophysicsCategory.<init>(GeophysicsCategory.java:60)
	at org.geotoolkit.coverage.Category.<init>(Category.java:480)
	at org.geotoolkit.coverage.Category.<init>(Category.java:251)
	at org.geotoolkit.coverage.Category.<init>(Category.java:241)
	at org.geotoolkit.image.io.metadata.MetadataHelper.getGridSampleDimensions(MetadataHelper.java:680)
	at org.geotoolkit.coverage.io.ImageCoverageReader.getSampleDimensions(ImageCoverageReader.java:682)
	at org.geotoolkit.coverage.io.ImageCoverageReader.getSampleDimensions(ImageCoverageReader.java:715)
	at org.geotoolkit.coverage.io.ImageCoverageReader.read(ImageCoverageReader.java:917)
	at org.vpac.geotk.CoordinateConversion.reprojectNetcdf(CoordinateConversion.java:274)
	at org.vpac.geotk.CoordinateConversion.main(CoordinateConversion.java:344)

I tried with different netCDF files that I passed to you (melb-small.nc and melb3112.nc)

Exception in thread "main" java.lang.NullPointerException
	at org.geotoolkit.coverage.io.SampleDimensionPalette.createImageTypeSpecifier(SampleDimensionPalette.java:101)
	at org.geotoolkit.image.io.Palette.getImageTypeSpecifier(Palette.java:202)
	at org.geotoolkit.image.io.SpatialImageReader.getImageType(SpatialImageReader.java:945)
	at org.geotoolkit.image.io.SpatialImageReader.getDestination(SpatialImageReader.java:1134)
	at org.geotoolkit.image.io.plugin.NetcdfImageReader.read(NetcdfImageReader.java:1088)
	at org.geotoolkit.coverage.io.ImageCoverageReader.read(ImageCoverageReader.java:955)
	at org.vpac.geotk.CoordinateConversion.reprojectNetcdf(CoordinateConversion.java:274)
	at org.vpac.geotk.CoordinateConversion.main(CoordinateConversion.java:344)

netcdf melb-small {
dimensions:
        x = 191 ;
        y = 79 ;
variables:
        char transverse_mercator ;
                transverse_mercator:Northernmost_Northing = -4103115. ;
                transverse_mercator:Southernmost_Northing = -4105485. ;
                transverse_mercator:Easternmost_Easting = 403005. ;
                transverse_mercator:Westernmost_Easting = 397275. ;
                transverse_mercator:spatial_ref = "PROJCS[\"WGS 84 / UTM zone 55N\",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\"]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",147],PARAMETER[\"scale_factor\",0.9996],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",0],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AUTHORITY[\"EPSG\",\"32655\"]]" ;
                transverse_mercator:GeoTransform = "397274.9999999999 30 0 -4103115 0 -30 " ;
                transverse_mercator:grid_mapping_name = "transverse_mercator" ;
                transverse_mercator:latitude_of_projection_origin = 0.f ;
                transverse_mercator:longitude_of_central_meridian = 147.f ;
                transverse_mercator:scale_factor_at_central_meridian = 0.9996f ;
                transverse_mercator:false_easting = 500000.f ;
                transverse_mercator:false_northing = 0.f ;
        byte Band1(y, x) ;
                Band1:grid_mapping = "transverse_mercator" ;
                Band1:long_name = "GDAL Band Number 1" ;

// global attributes:
                :Conventions = "CF-1.0" ;
                :AREA_OR_POINT = "Point" ;
}

netcdf melb3112 {
dimensions:
        x = 198 ;
        y = 99 ;
variables:
        char lambert_conformal_conic ;
                lambert_conformal_conic:Northernmost_Northing = -4218968.14605944 ;
                lambert_conformal_conic:Southernmost_Northing = -4221948.66130479 ;
                lambert_conformal_conic:Easternmost_Easting = 1060889.92068945 ;
                lambert_conformal_conic:Westernmost_Easting = 1054928.89019874 ;
                lambert_conformal_conic:spatial_ref = "PROJCS[\"GDA94 / Geoscience Australia Lambert\",GEOGCS[\"GDA94\",DATUM[\"Geocentric_Datum_of_Australia_1994\",SPHEROID[\"GRS 1980\",6378137,298.2572221010002,AUTHORITY[\"EPSG\",\"7019\"]],AUTHORITY[\"EPSG\",\"6283\"]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433],AUTHORITY[\"EPSG\",\"4283\"]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"standard_parallel_1\",-18],PARAMETER[\"standard_parallel_2\",-36],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",134],PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",0],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AUTHORITY[\"EPSG\",\"3112\"]]" ;
                lambert_conformal_conic:GeoTransform = "1054928.890198743 30.10621459950866 0 -4218968.146059438 0 -30.10621459950866 " ;
                lambert_conformal_conic:grid_mapping_name = "lambert_conformal_conic" ;
                lambert_conformal_conic:standard_parallel_1 = -18.f ;
                lambert_conformal_conic:standard_parallel_2 = -36.f ;
                lambert_conformal_conic:latitude_of_projection_origin = 0.f ;
                lambert_conformal_conic:longitude_of_central_meridian = 134.f ;
                lambert_conformal_conic:false_easting = 0.f ;
                lambert_conformal_conic:false_northing = 0.f ;
        byte Band1(y, x) ;
                Band1:grid_mapping = "lambert_conformal_conic" ;
                Band1:long_name = "GDAL Band Number 1" ;

// global attributes:
                :Conventions = "CF-1.0" ;
                :AREA_OR_POINT = "Area" ;
}


Regards,

Hendy

----- Original Message -----
From: "Martin Desruisseaux" <martin.desruisseaux at geomatys.fr>
To: "Hendy Sumanto" <hsumanto at vpac.org>
Cc: geotoolkit at lists.osgeo.org
Sent: Thursday, 25 August, 2011 10:25:14 AM
Subject: Re: [geotk] Error while reading netCDF file

Hello Hendy

GDAL seems to encode CRS informations in its own way, which looks different from 
the CF-convention I was used too. The UCAR NetCDF library neither doesn't 
recognize the geographic information in that file (I tried both 4.2.20 and 
4.2.26 NetCDF library versions).

However, by chance, GDAL encodes the CRS in WKT form in a way similar than what 
ESRI does (the GDAL way is more elaborated however). Since the Geotk 
NetcdfImageReader can already understand the ESRI declaration, it was not very 
difficult to extend it in order to understand the GDAL declaration too.

So I commited the following changes on trunk:

* Upgrated the NetCDF dependency to 4.2.26, which is the latest stable version 
available.
* Extended the current "ESRI special case" so it is now also a "GDAL special case".

However I didn't had the time to test the full image reading yet (I just tested 
that the CRS metadata are now correctly created). If you have a chance, you can 
test either by using the 3.x-SNAPSHOT version if you are using Maven, or 
downloading from http://download.geotoolkit.org/SNAPSHOT/ if you are using the 
PACK200 bundles.

     Regards,

         Martin



Le 23/08/11 01:33, Hendy Sumanto a écrit :
> This is the ncdump of the netCDF file, it is just a LANDSAT raster dataset which I produce by gdal_translate a GeoTIFF file into netCDF
>
> netcdf dem20_r500_3112 {
> dimensions:
>          x = 1838 ;
>          y = 1317 ;
> variables:
>          char lambert_conformal_conic ;
>                  lambert_conformal_conic:Northernmost_Northing = -3825712.6003764 ;
>                  lambert_conformal_conic:Southernmost_Northing = -4484212.6003764 ;
>                  lambert_conformal_conic:Easternmost_Easting = 1458143.98029015 ;
>                  lambert_conformal_conic:Westernmost_Easting = 539143.980290151 ;
>                  lambert_conformal_conic:spatial_ref = "PROJCS[\"GDA94 / Geoscience Australia Lambert\",GEOGCS[\"GDA94\",DATUM[\"Geocentric_Datum_of_Australia_1994\",SPHEROID[\"GRS 1980\",6378137,298.2572221010002,AUTHORITY[\"EPSG\",\"7019\"]],AUTHORITY[\"EPSG\",\"6283\"]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433],AUTHORITY[\"EPSG\",\"4283\"]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"standard_parallel_1\",-18],PARAMETER[\"standard_parallel_2\",-36],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",134],PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",0],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AUTHORITY[\"EPSG\",\"3112\"]]" ;
>                  lambert_conformal_conic:GeoTransform = "539144 500 0 -3.82571e+06 0 -500 " ;
>                  lambert_conformal_conic:grid_mapping_name = "lambert_conformal_conic" ;
>                  lambert_conformal_conic:standard_parallel_1 = -18.f ;
>                  lambert_conformal_conic:standard_parallel_2 = -36.f ;
>                  lambert_conformal_conic:latitude_of_projection_origin = 0.f ;
>                  lambert_conformal_conic:longitude_of_central_meridian = 134.f ;
>                  lambert_conformal_conic:false_easting = 0.f ;
>                  lambert_conformal_conic:false_northing = 0.f ;
>          float Band1(y, x) ;
>                  Band1:_FillValue = -1.e+10f ;
>                  Band1:grid_mapping = "lambert_conformal_conic" ;
>                  Band1:long_name = "GDAL Band Number 1" ;
>
> // global attributes:
>                  :Conventions = "CF-1.0" ;
> }
>
> Thanks for your quick response Martin.
>
> Regards,
>
> Hendy
>
> ----- Original Message -----
> From: "Martin Desruisseaux"<martin.desruisseaux at geomatys.fr>
> To: "Hendy Sumanto"<hsumanto at vpac.org>
> Sent: Tuesday, 23 August, 2011 2:59:38 AM
> Subject: Re: [geotk] Error while reading netCDF file
>
> Hello Hendy
>
> Could you send the output of the following command please?
>
> ncdump -h dem20_r500_3112.nc
>
>
> The "ncdump" command is part of the NetCDF package. If you are on Linux and have
> GDAL installed, I think you probably already have "ncdump" too.
>
>       Regards,
>
>           Martin
>
>
> Le 22/08/11 13:18, Hendy Sumanto a écrit :
>> Reading NetCDF resulted in the below error.
>> Any idea how to fix this issue?
>>
>> Thank you.
>>
>> Regards,
>>
>> Hendy
>>
>> Exception in thread "main" org.geotoolkit.coverage.io.CoverageStoreException: Can’t read file “dem20_r500_3112.nc”.
>> Parameter “origin” is missing.
>> 	at org.geotoolkit.coverage.io.ImageCoverageReader.getGridGeometry(ImageCoverageReader.java:588)
>> 	at org.geotoolkit.coverage.io.ImageCoverageReader.read(ImageCoverageReader.java:860)
>> 	at org.vpac.geotk.CoordinateConversion.resampleNetcdf(CoordinateConversion.java:197)
>> 	at org.vpac.geotk.CoordinateConversion.main(CoordinateConversion.java:267)
>> Caused by: org.geotoolkit.image.io.ImageMetadataException: Parameter “origin” is missing.
>> 	at org.geotoolkit.image.io.metadata.MetadataHelper.ensureMetadataExists(MetadataHelper.java:168)
>> 	at org.geotoolkit.image.io.metadata.MetadataHelper.getGridToCRS(MetadataHelper.java:328)
>> 	at org.geotoolkit.coverage.io.ImageCoverageReader.getGridGeometry(ImageCoverageReader.java:580)
>> 	... 3 more
>>
>> These are my source code
>>
>>       public static void resampleNetcdf() throws CoverageStoreException, NoSuchAuthorityCodeException, FactoryException {
>>           CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326");
>>
>>       	ImageCoverageReader reader = new ImageCoverageReader();
>>
>> //    	reader.setInput(new File("cldc.mean.nc"));
>>       	reader.setInput(new File("dem20_r500_3112.nc"));
>>       	GridCoverage coverage = reader.read(0, null);
>>       	
>> //    	SpatialMetadata metadata = reader.getCoverageMetadata(0);
>> //    	System.out.println(metadata);
>>       	
>> //    	GridGeometry2D gridGeometry = reader.getGridGeometry(0);
>> //    	System.out.println(gridGeometry);
>>       	reader.dispose();
>>      	
>>       	
>> //    	GridCoverage resultCvg = (GridCoverage) Operations.DEFAULT.resample(coverage, targetCRS);
>> //    	GridCoverageWriteParam param = new GridCoverageWriteParam();
>> //    	param.setFormatName("geotiff");
>> //    	ImageCoverageWriter writer = new ImageCoverageWriter();
>> //    	writer.setOutput(new File("dem20_r500_3112-out.tif"));
>> //    	writer.write(resultCvg, param);
>> //    	writer.dispose();    	   	
>>       }
>>
>>       /**
>>        * Runs the demo from the command line.
>>        *
>>        */
>>       public static void main(String[] args) throws FactoryException, TransformException, CoverageStoreException {
>>       	IIORegistry registry = IIORegistry.getDefaultInstance();
>>       	registry.registerServiceProvider(new TIFFImageReaderSpi(), ImageReaderSpi.class);
>>       	registry.registerServiceProvider(new GeoTiffImageReader.Spi("TIFF"), ImageReaderSpi.class);
>>       	registry.registerServiceProvider(new NetcdfImageReader.Spi(), ImageReaderSpi.class);
>>       	registry.registerServiceProvider(new GeoTiffImageWriter.Spi("TIFF"), ImageWriterSpi.class);
>>       	
>> //        resampleGeotiff();
>>           resampleNetcdf();
>>           System.out.println("Finished...");
>>
>> These are the gdalinfo of the netCDF file (I produced this netCDF file by translating a LANDSAT geotiff into netCDF using gdal_translate):
>>
>> hsumanto at uladev ~ $ gdalinfo dem20_r500_3112.nc
>> Driver: netCDF/Network Common Data Format
>> Files: dem20_r500_3112.nc
>>          dem20_r500_3112.nc.aux.xml
>> Size is 1838, 1317
>> Coordinate System is:
>> PROJCS["GDA94 / Geoscience Australia Lambert",
>>       GEOGCS["GDA94",
>>           DATUM["Geocentric_Datum_of_Australia_1994",
>>               SPHEROID["GRS 1980",6378137,298.2572221010002,
>>                   AUTHORITY["EPSG","7019"]],
>>               AUTHORITY["EPSG","6283"]],
>>           PRIMEM["Greenwich",0],
>>           UNIT["degree",0.0174532925199433],
>>           AUTHORITY["EPSG","4283"]],
>>       PROJECTION["Lambert_Conformal_Conic_2SP"],
>>       PARAMETER["standard_parallel_1",-18],
>>       PARAMETER["standard_parallel_2",-36],
>>       PARAMETER["latitude_of_origin",0],
>>       PARAMETER["central_meridian",134],
>>       PARAMETER["false_easting",0],
>>       PARAMETER["false_northing",0],
>>       UNIT["metre",1,
>>           AUTHORITY["EPSG","9001"]],
>>       AUTHORITY["EPSG","3112"]]
>> Origin = (539144.000000000000000,-3825710.000000000000000)
>> Pixel Size = (500.000000000000000,-500.000000000000000)
>> Metadata:
>>     NC_GLOBAL#Conventions=CF-1.0
>>     Band1#_FillValue=-1.000000e+10
>>     Band1#grid_mapping=lambert_conformal_conic
>>     Band1#long_name=GDAL Band Number 1
>>     lambert_conformal_conic#Northernmost_Northing=-3.82571e+06
>>     lambert_conformal_conic#Southernmost_Northing=-4.48421e+06
>>     lambert_conformal_conic#Easternmost_Easting=1.45814e+06
>>     lambert_conformal_conic#Westernmost_Easting=539144
>>     lambert_conformal_conic#spatial_ref=PROJCS["GDA94 / Geoscience Australia Lambert",GEOGCS["GDA94",DATUM["Geocentric_Datum_of_Australia_1994",SPHEROID["GRS 1980",6378137,298.2572221010002,AUTHORITY["EPSG","7019"]],AUTHORITY["EPSG","6283"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4283"]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",-18],PARAMETER["standard_parallel_2",-36],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",134],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AUTHORITY["EPSG","3112"]]
>>     lambert_conformal_conic#GeoTransform=539144 500 0 -3.82571e+06 0 -500
>>     lambert_conformal_conic#grid_mapping_name=lambert_conformal_conic
>>     lambert_conformal_conic#standard_parallel_1=-1.800000e+01
>>     lambert_conformal_conic#standard_parallel_2=-3.600000e+01
>>     lambert_conformal_conic#latitude_of_projection_origin=0.000000e+00
>>     lambert_conformal_conic#longitude_of_central_meridian=1.340000e+02
>>     lambert_conformal_conic#false_easting=0.000000e+00
>>     lambert_conformal_conic#false_northing=0.000000e+00
>>     AREA_OR_POINT=Area
>> Corner Coordinates:
>> Upper Left  (  539144.000,-3825710.000) (139d51'32.69"E, 33d51'18.49"S)
>> Lower Left  (  539144.000,-4484210.000) (140d12'45.27"E, 39d45'53.29"S)
>> Upper Right ( 1458144.000,-3825710.000) (149d46'27.56"E, 33d 8'16.73"S)
>> Lower Right ( 1458144.000,-4484210.000) (150d42'59.94"E, 39d 1' 7.55"S)
>> Center      (  998644.000,-4154960.000) (145d 8'58.86"E, 36d32'31.58"S)
>> Band 1 Block=1838x1 Type=Float32, ColorInterp=Gray
>>     NoData Value=-10000000000
>>     Metadata:
>>       NETCDF_VARNAME=Band1
>>
>>



More information about the Geotoolkit mailing list