[geotk] Error while reading netCDF file

Martin Desruisseaux martin.desruisseaux at geomatys.fr
Wed Aug 24 20:25:14 EDT 2011


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