I have GridCoverage2D object built from the two-dimensional float array:

float[][] myData = new float[dataH][dataW];
// fill myDdata array

ReferencedEnvelope env = new ReferencedEnvelope(-180, 180, -90, 90, DefaultGeographicCRS.WGS84);
GridCoverage2D gc2d = gcf.create("coverage", myData, env);

I have a number of no-data points in myData array. No data value is -999. Is it possible to interpolate myData and "fill" these no-data values using Bilinear or Bicubic interpolation?

I have tried:

javax.media.jai.Interpolation interp = Interpolation.getInstance(Interpolation.INTERP_BILINEAR);
GridCoverage2D gc2d_interpolated = (GridCoverage2D) Operations.DEFAULT.interpolate(gc2d, interp);

However with no results. What I am doing wrong? Should I set NO_DATA some way to my interpolation?

******* EDITED *******

It is difficult to reproduce full section of code that's why I prepared some example reproducing the problem. I attached small subset of my data as a GeoTiff image

It is my example:

File inputFile = new File("E:\\tmp\\img\\subset1.tiff");
File output1File = new File("E:\\tmp\\img\\no_interpolation.tiff");
File output2File = new File("E:\\tmp\\img\\bilinear.tiff");

AbstractGridFormat format = new GeoTiffFormat();
GeoTiffReader reader = new GeoTiffReader(inputFile);
GridCoverage2D c = reader.read(null);

GeoTiffWriter w = new GeoTiffWriter(output1File);
GeoTiffWriter wi = new GeoTiffWriter(output2File);
w.write(c, null);

javax.media.jai.Interpolation interpolation = Interpolation.getInstance(Interpolation.INTERP_BILINEAR);
GridCoverage2D ci = (GridCoverage2D) Operations.DEFAULT.interpolate(c, interpolation);



Both resulting images with and without interpolation are attached. There are no difference between them.

no_interpolation bilinear

  • when you say no results what do you mean? what actually happens. If possible please provide a full section of code and a small test data set.
    – Ian Turton
    Commented Nov 12, 2017 at 17:51
  • @IanTurton I have placed some additional information Commented Nov 12, 2017 at 20:51
  • I don't use java, but I would look for something like inpainting. Scipy has some built-ins for that.
    – Jon
    Commented Nov 28, 2018 at 19:04

1 Answer 1


Is there anyway you can export your data to a .shp? I'm sorry, I don't know much about programming, but if you are experienced with Qgis it could easily address your problem. If you have a point shapefile with your data and their respective coordinates, the interpolation is only two clicks away. I'm recommending you this because bilinear interpolation doesn't necessairly take into account the spatiality of the data. QGIS and many other GIS have interpolation methods that are adjusted specially to dealing with geographical data (Delaunay Triangulation, IDW, etc...) for more accurate results you should consider using one of those.

Here's an in-depth explaination of QGIS methods of interpolation, if you are interested:


  • Thank you for your replay. Unfortunately I can't. First of all I have to do it programmatically on the hourly basis. Second reason - my data is a raster imagery like microwave measurements. I have some holes in my data that's why I try to use interpolation Commented Nov 12, 2017 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.