[geotk] questions about GridCoverage

Martin Desruisseaux martin.desruisseaux at geomatys.fr
Thu Feb 9 06:30:22 EST 2012


Hello Pablo

Le 08/02/12 19:46, Pablo Rozas Larraondo a écrit :
> In the Javadoc there is an example for specifying the slice to read in a 
> NetcdfImageReader, using both DimensionSlice's or bands. As I want to work 
> with GridCoverage2D rather than BufferedImage I have to use a 
> ImageCoverageReader, this class has a GridCoverageReadParam for specifying 
> destination bands in the reading process but I can't find a reference to 
> DimensionSlices on it... Is this the only way?
>
> Martin Desruisseaux suggested me to use an Envelope to map the z dimension, 
> which uses internally the DimensionSlice class: (...snip...)
> I understand I have to use this "param" object in the reading process of the 
> variables but I don't see how I can choose the slice to read. Does it have 
> something to do with setting the right values of "zmin" and "zmax" or it 
> assign the different slices to different bands? How I can select only one 
> slice when I evaluate a point?

The idea was to use different values of "/zmin/" and "/zmax/". Unfortunately I 
just had a look at the current ImageCoverageReader code and realized that the 
extra-dimensions are not yet connected to the DimensionSlice API, so it appears 
to be unfinished work (I will open a JIRA task for that). In the main time you 
can workaround by creating an ImageCoverageReader subclass and override the 
following methods:

     @Override
     public void setInput(Object input) throws CoverageStoreException {
         super.setInput(input);
         if (input != null) {
             if (imageReader instanceof MultidimensionalImageStore) {
                 ((MultidimensionalImageStore) imageReader).getDimensionForAPI(DimensionSlice.API.BANDS)
                         .addDimensionId(AxisDirection.UP, AxisDirection.DOWN);
             }
         }
     }

     @Override
     protected ImageReadParam createImageReadParam(final int index) throws IOException {
         final ImageReadParam param = super.createImageReadParam(index);
         if (param instanceof SpatialImageReadParam) {
             final DimensionSlice slice = ((SpatialImageReadParam) param).newDimensionSlice();
             slice.addDimensionId(AxisDirection.UP, AxisDirection.DOWN);
             slice.setSliceIndex(zIndex);
         }
     }


I did not tested, so I'm not sure that there is no glitch, but something along 
that line should work. Actually we are already doing something similar in a 
package-privated subclass:

  * modules/coverage/geotk-coverage-sql/src/main/java/org/geotoolkit/coverage/sql/GridCoverageLoader.java


As a side note, this geotk-coverage-sql module is a PostgreSQL database schema 
for storing information about coverages. It doesn't store the coverage 
themselves, but only medata about them (like their location on the disk) to be 
used as a kind of index for locating coverages, a little bit like NcML but using 
a database instead than XML files and not restricted to NetCDF files. In the 
particular case of NetCDF data, one benefit of geotk-coverage-sql is that you 
get a color palette applied on the image. Just in case you may like to explore 
there is:

  * Installation instruction:
    http://www.geotoolkit.org/modules/display/geotk-wizards-swing/CoverageDatabaseInstaller.html
  * Declaring a NetCDF file:
    http://www.geotoolkit.org/modules/display/geotk-wizards-swing/AddCoverages.html


> I also have another question regarding the evaluation of sample points in a 
> GridCoverage2D using interpolation: When I use the .getInterpolation() 
> function I get it's "Nearest", is there a way to set the interpolation to a 
> different method (bilinear, bicubic, etc)?

Yes, as below:

     import javax.media.jai.Interpolation;
     import org.geotoolkit.coverage.processing.Operations;

     GridCoverage2D coverage = ...;
     Interpolation interp = Interpolation.getInstance(Interpolation.INTERP_BILINEAR);
     coverage = (GridCoverage2D) Operations.DEFAULT.interpolate(coverage, interp);


There is also a variant accepting an array of Interpolation objects instead than 
a single one. The array typically contains InterpolationBicubic, 
InterpolationBilinear and InterpolationNearest instances in that order. The 
first interpolation method is tried. If the result is NaN because at least one 
of the nearest grid points contains NaN (missing value), then the second 
interpolation method is tried (the bilinear one have more chances to succeed 
than the bicubic one because it use less points), and so on.

> As a suggestion, I think it would be interesting to have an evaluate() 
> function which returns the values of the nearest or the 4 nearer grid points 
> and their distances to the point for implementing custom interpolations.

The idea was to let users specify their own javax.media.jai.Interpolation 
instance. However I never tried that path, so I don't know if it works well in 
practice...

     Martin



More information about the Geotoolkit mailing list