[netcdf-java] Generating images (geotiff or png) from NetCDF files

Hi,

I am new to NetCDF files and Geotiffs in general so this may be a long question.

I am using the R ncdf package to create a NetCDF file from data that I
have generated.  My data is a 200x200 grid of (lat,lon) with a double
prediction value at every grid point.  My first question is: should
the "prediction" value be a variable or a dimension?  Currently, I
have it as a variable with dimensions (lat,lon).  I use the following
R commands to create the NetCDF file:

x=dim.def.ncdf("lon","degreesE",as.list(lons)$V1)
y=dim.def.ncdf("lat","degreesN",as.list(lats)$V1)
prediction=var.def.ncdf("prediction","probability",list(x,y),0,prec="double")
ncnew=create.ncdf("rncdf.nc",prediction,verbose=TRUE)

# create a pseudo prediction
pred=runif(40000);

put.var.ncdf(ncnew,"prediction",pred)
close.ncdf(ncnew)

This all works fine and I can open the file in various NetCDF file
viewers and view plots of the data.  The header of the created ncdf
file is:

netcdf rncdf {
dimensions:
        lon = 200 ;
        lat = 200 ;
variables:
        double lon(lon) ;
                lon:units = "degreesE" ;
        double lat(lat) ;
                lat:units = "degreesN" ;
        double prediction(lat, lon) ;
                prediction:units = "probability" ;
                prediction:missing_value = 0. ;
                prediction:coordinates = "lat lon" ;

I would like to generate images of this data either in geotiff format
or png format for display as a layer in an OpenLayers client from
GeoServer.  I have tried using the GeotiffWriter class in netcdf-java
but it complains that:

Exception in thread "main" java.lang.IllegalArgumentException: Must
have 1D x and y axes for prediction

I have been able to create grayscale PNGs from the data using the
following code:

GridDataset gd = GridDataset.open("rncdf.nc");
ImageDatasetFactory imageFactory = new ImageDatasetFactory();
imageFactory.openDataset(gd.getGrids().get(0));
BufferedImage image = imageFactory.getNextImage(true);
ImageIO.write(image, "png", new File("rncdf.png"));

Which format, Geotiff or PNG, is better for this context?  How can I
control the color scale when creating either Geotiff or PNG from the
dataset?  Do I need to specify a lat/lon projection using att.put.ncdf
in R?  If so, what is the correct projection string to use?

Any help is appreciated,
Anthony


  • 2008 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdf-java archives: