cdm/src/main/java/ucar/nc2/geotiff/GeoTiffWriter2.java
private Array interpolation(Array arr) {
    int[] orishape = arr.getShape();
    int width = orishape[1];
    int height = orishape[0];
    int pixelNum = width * height;
    Array interpolatedArray = Array.factory(DataType.FLOAT, orishape);
    for (int i = 0; i < height; i++) {
      for (int j = 0; j < width; j++) {
        int curIndex = i * width + j;
        float curValue = arr.getFloat(curIndex);
        if (curValue == 0)  //Black hole. Need to fill.
        {
          float tempPixelSum = 0;
          int numNeighborHasValue = 0;
          //Get the values of eight neighborhood
          if ((curIndex - 1 >= 0) && (curIndex - 1 < pixelNum)) {
            float left = arr.getFloat(curIndex - 1);
            if (left > 0) {
              tempPixelSum += left;
              numNeighborHasValue++;
            }
          }
          if ((curIndex + 1 >= 0) && (curIndex + 1 < pixelNum)) {
            float right = arr.getFloat(curIndex + 1);
            if (right > 0) {
              tempPixelSum += right;
              numNeighborHasValue++;
            }
          }
          if ((curIndex - width >= 0) && (curIndex - width < pixelNum)) {
            float up = arr.getFloat(curIndex - width);
            if (up > 0) {
              tempPixelSum += up;
              numNeighborHasValue++;
            }
          }
          if ((curIndex + width >= 0) && (curIndex + width < pixelNum)) {
            float down = arr.getFloat(curIndex + width);
            if (down > 0) {
              tempPixelSum += down;
              numNeighborHasValue++;
            }
          }
          if ((curIndex - width - 1 >= 0) && (curIndex - width - 1 < pixelNum)) {
            float upleft = arr.getFloat(curIndex - width - 1);
            if (upleft > 0) {
              tempPixelSum += upleft;
              numNeighborHasValue++;
            }
          }
          if ((curIndex - width + 1 >= 0) && (curIndex - width + 1 < pixelNum)) {
            float upright = arr.getFloat(curIndex - width + 1);
            if (upright > 0) {
              tempPixelSum += upright;
              numNeighborHasValue++;
            }
          }
          if ((curIndex + width - 1 >= 0) && (curIndex + width - 1 < pixelNum)) {
            float downleft = arr.getFloat(curIndex + width - 1);
            if (downleft > 0) {
              tempPixelSum += downleft;
              numNeighborHasValue++;
            }
          }
          if ((curIndex + width + 1 >= 0) && (curIndex + width + 1 < pixelNum)) {
            float downright = arr.getFloat(curIndex + width + 1);
            if (downright > 0) {
              tempPixelSum += downright;
              numNeighborHasValue++;
            }
          }
          if (tempPixelSum > 0) {
            float val =  numNeighborHasValue == 0 ? 0 : tempPixelSum / numNeighborHasValue;
            interpolatedArray.setFloat(curIndex, val);
          }
        } else {
          interpolatedArray.setFloat(curIndex, curValue);
        }
      }
    }

    return interpolatedArray;
  }
private Array interpolation(Array arr) {
    int[] orishape = arr.getShape();
    int width = orishape[1];
    int height = orishape[0];
    int pixelNum = width * height;
    Array interpolatedArray = Array.factory(DataType.FLOAT, orishape);
    for (int i = 0; i < height; i++) {
      for (int j = 0; j < width; j++) {
        int curIndex = i * width + j;
        float curValue = arr.getFloat(curIndex);
        if (curValue == 0)  //Black hole. Need to fill.
        {
          float tempPixelSum = 0;
          int numNeighborHasValue = 0;
          //Get the values of eight neighborhood
          if ((curIndex - 1 >= 0) && (curIndex - 1 < pixelNum)) {
            float left = arr.getFloat(curIndex - 1);
            if (left > 0) {
              tempPixelSum += left;
              numNeighborHasValue++;
            }
          }
          if ((curIndex + 1 >= 0) && (curIndex + 1 < pixelNum)) {
            float right = arr.getFloat(curIndex + 1);
            if (right > 0) {
              tempPixelSum += right;
              numNeighborHasValue++;
            }
          }
          if ((curIndex - width >= 0) && (curIndex - width < pixelNum)) {
            float up = arr.getFloat(curIndex - width);
            if (up > 0) {
              tempPixelSum += up;
              numNeighborHasValue++;
            }
          }
          if ((curIndex + width >= 0) && (curIndex + width < pixelNum)) {
            float down = arr.getFloat(curIndex + width);
            if (down > 0) {
              tempPixelSum += down;
              numNeighborHasValue++;
            }
          }
          if ((curIndex - width - 1 >= 0) && (curIndex - width - 1 < pixelNum)) {
            float upleft = arr.getFloat(curIndex - width - 1);
            if (upleft > 0) {
              tempPixelSum += upleft;
              numNeighborHasValue++;
            }
          }
          if ((curIndex - width + 1 >= 0) && (curIndex - width + 1 < pixelNum)) {
            float upright = arr.getFloat(curIndex - width + 1);
            if (upright > 0) {
              tempPixelSum += upright;
              numNeighborHasValue++;
            }
          }
          if ((curIndex + width - 1 >= 0) && (curIndex + width - 1 < pixelNum)) {
            float downleft = arr.getFloat(curIndex + width - 1);
            if (downleft > 0) {
              tempPixelSum += downleft;
              numNeighborHasValue++;
            }
          }
          if ((curIndex + width + 1 >= 0) && (curIndex + width + 1 < pixelNum)) {
            float downright = arr.getFloat(curIndex + width + 1);
            if (downright > 0) {
              tempPixelSum += downright;
              numNeighborHasValue++;
            }
          }
          if (tempPixelSum > 0) {
            float val =  numNeighborHasValue == 0 ? 0 : tempPixelSum / numNeighborHasValue;
            interpolatedArray.setFloat(curIndex, val);
          }
        } else {
          interpolatedArray.setFloat(curIndex, curValue);
        }
      }
    }

    return interpolatedArray;
  }
private Array interpolation ( Array arr ) { int [ ] orishape = arr . getShape ( ) ; int width = orishape [ 1 ] ; int height = orishape [ 0 ] ; int pixelNum = width * height ; Array interpolatedArray = Array . factory ( DataType . FLOAT , orishape ) ; for ( int i = 0 ; i < height ; i ++ ) { for ( int j = 0 ; j < width ; j ++ ) { int curIndex = i * width + j ; float curValue = arr . getFloat ( curIndex ) ; if ( curValue == 0 ) //Black hole. Need to fill. { float tempPixelSum = 0 ; int numNeighborHasValue = 0 ; //Get the values of eight neighborhood if ( ( curIndex - 1 >= 0 ) && ( curIndex - 1 < pixelNum ) ) { float left = arr . getFloat ( curIndex - 1 ) ; if ( left > 0 ) { tempPixelSum += left ; numNeighborHasValue ++ ; } } if ( ( curIndex + 1 >= 0 ) && ( curIndex + 1 < pixelNum ) ) { float right = arr . getFloat ( curIndex + 1 ) ; if ( right > 0 ) { tempPixelSum += right ; numNeighborHasValue ++ ; } } if ( ( curIndex - width >= 0 ) && ( curIndex - width < pixelNum ) ) { float up = arr . getFloat ( curIndex - width ) ; if ( up > 0 ) { tempPixelSum += up ; numNeighborHasValue ++ ; } } if ( ( curIndex + width >= 0 ) && ( curIndex + width < pixelNum ) ) { float down = arr . getFloat ( curIndex + width ) ; if ( down > 0 ) { tempPixelSum += down ; numNeighborHasValue ++ ; } } if ( ( curIndex - width - 1 >= 0 ) && ( curIndex - width - 1 < pixelNum ) ) { float upleft = arr . getFloat ( curIndex - width - 1 ) ; if ( upleft > 0 ) { tempPixelSum += upleft ; numNeighborHasValue ++ ; } } if ( ( curIndex - width + 1 >= 0 ) && ( curIndex - width + 1 < pixelNum ) ) { float upright = arr . getFloat ( curIndex - width + 1 ) ; if ( upright > 0 ) { tempPixelSum += upright ; numNeighborHasValue ++ ; } } if ( ( curIndex + width - 1 >= 0 ) && ( curIndex + width - 1 < pixelNum ) ) { float downleft = arr . getFloat ( curIndex + width - 1 ) ; if ( downleft > 0 ) { tempPixelSum += downleft ; numNeighborHasValue ++ ; } } if ( ( curIndex + width + 1 >= 0 ) && ( curIndex + width + 1 < pixelNum ) ) { float downright = arr . getFloat ( curIndex + width + 1 ) ; if ( downright > 0 ) { tempPixelSum += downright ; numNeighborHasValue ++ ; } } if ( tempPixelSum > 0 ) { float val = numNeighborHasValue == 0 ? 0 : tempPixelSum / numNeighborHasValue ; interpolatedArray . setFloat ( curIndex , val ) ; } } else { interpolatedArray . setFloat ( curIndex , curValue ) ; } } } return interpolatedArray ; }
interpolate the swath data to regular grid

@param arr swath array
@return regular grid
interpolate the swath data to regular grid