cdm/src/main/java/ucar/nc2/geotiff/GeotiffWriter.java
public void writeGrid(GeoReferencedArray array, boolean greyScale) throws IOException {

    CoverageCoordSys gcs = array.getCoordSysForData();
    if (!gcs.isRegularSpatial())
      throw new IllegalArgumentException("Must have 1D x and y axes for " + array.getCoverageName());

    Projection proj = gcs.getProjection();
    CoverageCoordAxis1D xaxis = (CoverageCoordAxis1D) gcs.getXAxis();
    CoverageCoordAxis1D yaxis = (CoverageCoordAxis1D) gcs.getYAxis();

    // latlon coord does not need to be scaled
    double scaler = (xaxis.getUnits().equalsIgnoreCase("km")) ? 1000.0 : 1.0;

    // data must go from top to bottom
    double xStart = xaxis.getCoordEdge1(0) * scaler;
    double yStart = yaxis.getCoordEdge1(0) * scaler;
    double xInc = xaxis.getResolution() * scaler;
    double yInc = Math.abs(yaxis.getResolution()) * scaler;

    Array data = array.getData().reduce();
    if (yaxis.getCoordMidpoint(0) < yaxis.getCoordMidpoint(1)) {
      data = data.flip(0);
      yStart = yaxis.getCoordEdgeLast();
    }

    /*  remove - i think unneeded, monotonic lon handled in CoordinateAxis1D. JC 3/18/2013
     if (gcs.isLatLon()) {
      Array lon = xaxis.read();
      data = geoShiftDataAtLon(data, lon);
      xStart = geoShiftGetXstart(lon, xInc);
      //xStart = -180.0;
    }  */

    if (pageNumber > 1) {
      geotiff.initTags();
    }

    // write the data first
    int nextStart = 0;
    MAMath.MinMax dataMinMax = MAMath.getMinMaxSkipMissingData(data, array);
    if (greyScale) {
      ArrayByte result = replaceMissingValuesAndScale(array, data, dataMinMax);
      nextStart = geotiff.writeData((byte[]) result.getStorage(), pageNumber);
    } else {
      ArrayFloat result = replaceMissingValues(array, data, dataMinMax);
      nextStart = geotiff.writeData((float[]) result.getStorage(), pageNumber);
    }

    // set the width and the height
    int height = data.getShape()[0];         // Y
    int width = data.getShape()[1];         // X

    writeMetadata(greyScale, xStart, yStart, xInc, yInc, height, width, pageNumber, nextStart, dataMinMax, proj);
    pageNumber++;
  }
public void writeGrid(GeoReferencedArray array, boolean greyScale) throws IOException {

    CoverageCoordSys gcs = array.getCoordSysForData();
    if (!gcs.isRegularSpatial())
      throw new IllegalArgumentException("Must have 1D x and y axes for " + array.getCoverageName());

    Projection proj = gcs.getProjection();
    CoverageCoordAxis1D xaxis = (CoverageCoordAxis1D) gcs.getXAxis();
    CoverageCoordAxis1D yaxis = (CoverageCoordAxis1D) gcs.getYAxis();

    // latlon coord does not need to be scaled
    double scaler = (xaxis.getUnits().equalsIgnoreCase("km")) ? 1000.0 : 1.0;

    // data must go from top to bottom
    double xStart = xaxis.getCoordEdge1(0) * scaler;
    double yStart = yaxis.getCoordEdge1(0) * scaler;
    double xInc = xaxis.getResolution() * scaler;
    double yInc = Math.abs(yaxis.getResolution()) * scaler;

    Array data = array.getData().reduce();
    if (yaxis.getCoordMidpoint(0) < yaxis.getCoordMidpoint(1)) {
      data = data.flip(0);
      yStart = yaxis.getCoordEdgeLast();
    }

    /*  remove - i think unneeded, monotonic lon handled in CoordinateAxis1D. JC 3/18/2013
     if (gcs.isLatLon()) {
      Array lon = xaxis.read();
      data = geoShiftDataAtLon(data, lon);
      xStart = geoShiftGetXstart(lon, xInc);
      //xStart = -180.0;
    }  */

    if (pageNumber > 1) {
      geotiff.initTags();
    }

    // write the data first
    int nextStart = 0;
    MAMath.MinMax dataMinMax = MAMath.getMinMaxSkipMissingData(data, array);
    if (greyScale) {
      ArrayByte result = replaceMissingValuesAndScale(array, data, dataMinMax);
      nextStart = geotiff.writeData((byte[]) result.getStorage(), pageNumber);
    } else {
      ArrayFloat result = replaceMissingValues(array, data, dataMinMax);
      nextStart = geotiff.writeData((float[]) result.getStorage(), pageNumber);
    }

    // set the width and the height
    int height = data.getShape()[0];         // Y
    int width = data.getShape()[1];         // X

    writeMetadata(greyScale, xStart, yStart, xInc, yInc, height, width, pageNumber, nextStart, dataMinMax, proj);
    pageNumber++;
  }
Write GridCoverage data to the geotiff file.

@param array      GeoReferencedArray array in YX order
@param greyScale if true, write greyScale image, else dataSample.
@throws IOException on i/o error