public static void writeGridFile(InterpolateData data, MeshInfo meshInfo, DataOutputStream outStream) { try { if (densityMap == null) { return; } String header = "ncols " + data.getTotalColumn() + "\nnrows " + data.getTotalRow() + "\nxllcorner " + meshInfo.getCoordLeftTop().x + "\nyllcorner " + meshInfo.getCoordLeftTop().y + "\ncellsize " + meshInfo.getPixelSize() + "\nNODATA_value -9999\n"; outStream.writeBytes(header); int row = data.getTotalRow(); int col = data.getTotalColumn(); for (int i = 0; i < row; i++) { String lineInfo = ""; for (int j = 0; j < col; j++) { float value = data.getValueAt(i, j); if (value > 0) { lineInfo += value + " "; } else { lineInfo += "-9999 "; } } lineInfo += "\n"; outStream.writeBytes(lineInfo); } outStream.close(); } catch (IOException ex) { ex.printStackTrace(); } }