Java tutorial
//package com.java2s; public class Main { /** * Removes NoData cells from the DEM by passing a window over each cell and estimating the value using inverse-distance weighting. * @param array: array to remove NoData cells from * @param noDataVal: NoData value to search for and remove from array. Should be an odd number so that the window is of equal size on both sides. * @param windowSize: Size of the search window * @return DEM data */ private static float[][] removeDemNoData(float[][] array, float noDataVal, int windowSize) { int half = (windowSize - 1) / 2; float distance; float weight; float[][] arrayOut = array; boolean noDataCellsRemaining = true; while (noDataCellsRemaining == true) { noDataCellsRemaining = false; for (int r = 0; r < array.length; r++) { for (int c = 0; c < array[0].length; c++) { if (array[r][c] == noDataVal) { float weightsum = 0; float weightedvalsum = 0; for (int x = 0 - half; x < 1 + half; x++) { for (int y = 0 - half; y < 1 + half; y++) { //skip the current cell if (x == 0 && y == 0) { continue; } //verify that the cell is in the DEM range if (r + y >= array.length || r + y < 0 || c + x >= array[0].length || c + x < 0) { continue; } //verify that the neighbor cell is not NoDATA, as this will break the IDW computation if (array[r + y][c + x] != noDataVal) { distance = (float) Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)); weight = 1 / distance; weightsum += weight; weightedvalsum += array[r + y][c + x] * weight; arrayOut[r][c] = weightedvalsum / weightsum; } } } if (arrayOut[r][c] == noDataVal) { noDataCellsRemaining = true; } } } } } return arrayOut; } }