cdm/src/main/java/ucar/nc2/geotiff/GeoTiffWriter2.java
private void writeSwathGrid(String fileName, String gridName, int time, int level, boolean greyScale, LatLonRect llr) throws IOException {

    GridDataset dataset = ucar.nc2.dt.grid.GridDataset.open(fileName);
    GridDatatype grid = dataset.findGridDatatype(gridName);
    GridCoordSystem gcs = grid.getCoordinateSystem();
    ProjectionImpl proj = grid.getProjection();

    CoordinateAxis2D xaxis = (CoordinateAxis2D) gcs.getXHorizAxis();
    CoordinateAxis2D yaxis = (CoordinateAxis2D) gcs.getYHorizAxis();

    // read in data
    Array data = grid.readDataSlice(time, level, -1, -1);
    Array lon = xaxis.read();
    Array lat = yaxis.read();

    double[] swathInfo = getSwathLatLonInformation(lat, lon);

    // units may need to be scaled to meters
    double scaler = (xaxis.getUnitsString().equalsIgnoreCase("km")) ? 1000.0 : 1.0;

    //if (yaxis.getCoordValue(0, 0) < yaxis.getCoordValue(0, 1)) {//???
    data = data.flip(0);
    //lat = lat.flip(0);
    //}

    if (gcs.isLatLon()) {
      data = geoShiftDataAtLon(data, lon);
      lon = geoShiftLon(lon);
    }

    double minLon;
    double minLat;
    double maxLon;
    double maxLat;
    double xStart;
    double yStart;  //upper right point

    double xInc = swathInfo[0] * scaler;
    double yInc = swathInfo[1] * scaler;

    // (x1, y1) is upper left point and (x2, y2) is lower right point
    int x1;
    int x2;
    int y1;
    int y2;

    if (llr == null)  { //get the whole area
      minLon = swathInfo[4];
      minLat = swathInfo[2];
      maxLon = swathInfo[5];
      maxLat = swathInfo[3];
      xStart = minLon;
      yStart = maxLat;
      x1 = 0;
      y1 = 0;
      x2 = (int) ((maxLon - minLon) / xInc + 0.5);
      y2 = (int) ((maxLat - minLat) / yInc + 0.5);

    } else {           //assign the special area  surrounded by the llr
      LatLonPointImpl llp0 = llr.getLowerLeftPoint();
      LatLonPointImpl llpn = llr.getUpperRightPoint();
      minLon = (llp0.getLongitude() < swathInfo[4])
              ? swathInfo[4]
              : llp0.getLongitude();
      minLat = (llp0.getLatitude() < swathInfo[2])
              ? swathInfo[2]
              : llp0.getLatitude();
      maxLon = (llpn.getLongitude() > swathInfo[5])
              ? swathInfo[5]
              : llpn.getLongitude();
      maxLat = (llpn.getLatitude() > swathInfo[3])
              ? swathInfo[3]
              : llpn.getLatitude();

      //construct the swath  LatLonRect
      LatLonPointImpl pUpLeft = new LatLonPointImpl(swathInfo[3], swathInfo[4]);
      LatLonPointImpl pDownRight = new LatLonPointImpl(swathInfo[2], swathInfo[5]);
      LatLonRect swathLLR = new LatLonRect(pUpLeft, pDownRight);
      LatLonRect bIntersect = swathLLR.intersect(llr);
      if (bIntersect == null) {
        throw new IllegalArgumentException("The assigned extent of latitude and longitude is unvalid. No intersection with the swath extent");
      }

      xStart = minLon;
      yStart = maxLat;
      x1 = (int) ((minLon - swathInfo[4]) / xInc + 0.5);
      y1 = (int) Math.abs((maxLat - swathInfo[3]) / yInc + 0.5);
      x2 = (int) ((maxLon - swathInfo[4]) / xInc + 0.5);
      y2 = (int) Math.abs((minLat - swathInfo[3]) / yInc + 0.5);
    }

    if (!gcs.isLatLon()) {
      ProjectionPoint pjp0 = proj.latLonToProj(maxLat, minLon);
      x1 = getXIndex(lon, pjp0.getX(), 0);
      y1 = getYIndex(lat, pjp0.getY(), 0);
      yStart = pjp0.getY() * scaler;  //latArray[y1];
      xStart = pjp0.getX() * scaler;  //lonArray[x1];
      ProjectionPoint pjpn = proj.latLonToProj(minLat, maxLon);
      x2 = getXIndex(lon, pjpn.getX(), 1);
      y2 = getYIndex(lat, pjpn.getY(), 1);
    } else {
      //calculate the x1, x2, y1, y2, xstart, ystart.
    }

    Array targetImage = getTargetImagerFromSwath(lat, lon, data, swathInfo);
    Array interpolatedImage = interpolation(targetImage);
    Array clippedImage = getClippedImageFromInterpolation(interpolatedImage, x1, x2, y1, y2);
    //Array clippedImage = getYXDataInBox(interpolatedImage, x1, x2, y1, y2);

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

    writeGrid(grid, clippedImage, greyScale, xStart, yStart, xInc, yInc, pageNumber);
    pageNumber++;

  }
private void writeSwathGrid(String fileName, String gridName, int time, int level, boolean greyScale, LatLonRect llr) throws IOException {

    GridDataset dataset = ucar.nc2.dt.grid.GridDataset.open(fileName);
    GridDatatype grid = dataset.findGridDatatype(gridName);
    GridCoordSystem gcs = grid.getCoordinateSystem();
    ProjectionImpl proj = grid.getProjection();

    CoordinateAxis2D xaxis = (CoordinateAxis2D) gcs.getXHorizAxis();
    CoordinateAxis2D yaxis = (CoordinateAxis2D) gcs.getYHorizAxis();

    // read in data
    Array data = grid.readDataSlice(time, level, -1, -1);
    Array lon = xaxis.read();
    Array lat = yaxis.read();

    double[] swathInfo = getSwathLatLonInformation(lat, lon);

    // units may need to be scaled to meters
    double scaler = (xaxis.getUnitsString().equalsIgnoreCase("km")) ? 1000.0 : 1.0;

    //if (yaxis.getCoordValue(0, 0) < yaxis.getCoordValue(0, 1)) {//???
    data = data.flip(0);
    //lat = lat.flip(0);
    //}

    if (gcs.isLatLon()) {
      data = geoShiftDataAtLon(data, lon);
      lon = geoShiftLon(lon);
    }

    double minLon;
    double minLat;
    double maxLon;
    double maxLat;
    double xStart;
    double yStart;  //upper right point

    double xInc = swathInfo[0] * scaler;
    double yInc = swathInfo[1] * scaler;

    // (x1, y1) is upper left point and (x2, y2) is lower right point
    int x1;
    int x2;
    int y1;
    int y2;

    if (llr == null)  { //get the whole area
      minLon = swathInfo[4];
      minLat = swathInfo[2];
      maxLon = swathInfo[5];
      maxLat = swathInfo[3];
      xStart = minLon;
      yStart = maxLat;
      x1 = 0;
      y1 = 0;
      x2 = (int) ((maxLon - minLon) / xInc + 0.5);
      y2 = (int) ((maxLat - minLat) / yInc + 0.5);

    } else {           //assign the special area  surrounded by the llr
      LatLonPointImpl llp0 = llr.getLowerLeftPoint();
      LatLonPointImpl llpn = llr.getUpperRightPoint();
      minLon = (llp0.getLongitude() < swathInfo[4])
              ? swathInfo[4]
              : llp0.getLongitude();
      minLat = (llp0.getLatitude() < swathInfo[2])
              ? swathInfo[2]
              : llp0.getLatitude();
      maxLon = (llpn.getLongitude() > swathInfo[5])
              ? swathInfo[5]
              : llpn.getLongitude();
      maxLat = (llpn.getLatitude() > swathInfo[3])
              ? swathInfo[3]
              : llpn.getLatitude();

      //construct the swath  LatLonRect
      LatLonPointImpl pUpLeft = new LatLonPointImpl(swathInfo[3], swathInfo[4]);
      LatLonPointImpl pDownRight = new LatLonPointImpl(swathInfo[2], swathInfo[5]);
      LatLonRect swathLLR = new LatLonRect(pUpLeft, pDownRight);
      LatLonRect bIntersect = swathLLR.intersect(llr);
      if (bIntersect == null) {
        throw new IllegalArgumentException("The assigned extent of latitude and longitude is unvalid. No intersection with the swath extent");
      }

      xStart = minLon;
      yStart = maxLat;
      x1 = (int) ((minLon - swathInfo[4]) / xInc + 0.5);
      y1 = (int) Math.abs((maxLat - swathInfo[3]) / yInc + 0.5);
      x2 = (int) ((maxLon - swathInfo[4]) / xInc + 0.5);
      y2 = (int) Math.abs((minLat - swathInfo[3]) / yInc + 0.5);
    }

    if (!gcs.isLatLon()) {
      ProjectionPoint pjp0 = proj.latLonToProj(maxLat, minLon);
      x1 = getXIndex(lon, pjp0.getX(), 0);
      y1 = getYIndex(lat, pjp0.getY(), 0);
      yStart = pjp0.getY() * scaler;  //latArray[y1];
      xStart = pjp0.getX() * scaler;  //lonArray[x1];
      ProjectionPoint pjpn = proj.latLonToProj(minLat, maxLon);
      x2 = getXIndex(lon, pjpn.getX(), 1);
      y2 = getYIndex(lat, pjpn.getY(), 1);
    } else {
      //calculate the x1, x2, y1, y2, xstart, ystart.
    }

    Array targetImage = getTargetImagerFromSwath(lat, lon, data, swathInfo);
    Array interpolatedImage = interpolation(targetImage);
    Array clippedImage = getClippedImageFromInterpolation(interpolatedImage, x1, x2, y1, y2);
    //Array clippedImage = getYXDataInBox(interpolatedImage, x1, x2, y1, y2);

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

    writeGrid(grid, clippedImage, greyScale, xStart, yStart, xInc, yInc, pageNumber);
    pageNumber++;

  }
private void writeSwathGrid ( String fileName , String gridName , int time , int level , boolean greyScale , LatLonRect llr ) throws IOException { GridDataset dataset = ucar . nc2 . dt . grid . GridDataset . open ( fileName ) ; GridDatatype grid = dataset . findGridDatatype ( gridName ) ; GridCoordSystem gcs = grid . getCoordinateSystem ( ) ; ProjectionImpl proj = grid . getProjection ( ) ; CoordinateAxis2D xaxis = ( CoordinateAxis2D ) gcs . getXHorizAxis ( ) ; CoordinateAxis2D yaxis = ( CoordinateAxis2D ) gcs . getYHorizAxis ( ) ; // read in data Array data = grid . readDataSlice ( time , level , - 1 , - 1 ) ; Array lon = xaxis . read ( ) ; Array lat = yaxis . read ( ) ; double [ ] swathInfo = getSwathLatLonInformation ( lat , lon ) ; // units may need to be scaled to meters double scaler = ( xaxis . getUnitsString ( ) . equalsIgnoreCase ( "km" ) ) ? 1000.0 : 1.0 ; //if (yaxis.getCoordValue(0, 0) < yaxis.getCoordValue(0, 1)) {//??? data = data . flip ( 0 ) ; //lat = lat.flip(0); //} if ( gcs . isLatLon ( ) ) { data = geoShiftDataAtLon ( data , lon ) ; lon = geoShiftLon ( lon ) ; } double minLon ; double minLat ; double maxLon ; double maxLat ; double xStart ; double yStart ; //upper right point double xInc = swathInfo [ 0 ] * scaler ; double yInc = swathInfo [ 1 ] * scaler ; // (x1, y1) is upper left point and (x2, y2) is lower right point int x1 ; int x2 ; int y1 ; int y2 ; if ( llr == null ) { //get the whole area minLon = swathInfo [ 4 ] ; minLat = swathInfo [ 2 ] ; maxLon = swathInfo [ 5 ] ; maxLat = swathInfo [ 3 ] ; xStart = minLon ; yStart = maxLat ; x1 = 0 ; y1 = 0 ; x2 = ( int ) ( ( maxLon - minLon ) / xInc + 0.5 ) ; y2 = ( int ) ( ( maxLat - minLat ) / yInc + 0.5 ) ; } else { //assign the special area  surrounded by the llr LatLonPointImpl llp0 = llr . getLowerLeftPoint ( ) ; LatLonPointImpl llpn = llr . getUpperRightPoint ( ) ; minLon = ( llp0 . getLongitude ( ) < swathInfo [ 4 ] ) ? swathInfo [ 4 ] : llp0 . getLongitude ( ) ; minLat = ( llp0 . getLatitude ( ) < swathInfo [ 2 ] ) ? swathInfo [ 2 ] : llp0 . getLatitude ( ) ; maxLon = ( llpn . getLongitude ( ) > swathInfo [ 5 ] ) ? swathInfo [ 5 ] : llpn . getLongitude ( ) ; maxLat = ( llpn . getLatitude ( ) > swathInfo [ 3 ] ) ? swathInfo [ 3 ] : llpn . getLatitude ( ) ; //construct the swath  LatLonRect LatLonPointImpl pUpLeft = new LatLonPointImpl ( swathInfo [ 3 ] , swathInfo [ 4 ] ) ; LatLonPointImpl pDownRight = new LatLonPointImpl ( swathInfo [ 2 ] , swathInfo [ 5 ] ) ; LatLonRect swathLLR = new LatLonRect ( pUpLeft , pDownRight ) ; LatLonRect bIntersect = swathLLR . intersect ( llr ) ; if ( bIntersect == null ) { throw new IllegalArgumentException ( "The assigned extent of latitude and longitude is unvalid. No intersection with the swath extent" ) ; } xStart = minLon ; yStart = maxLat ; x1 = ( int ) ( ( minLon - swathInfo [ 4 ] ) / xInc + 0.5 ) ; y1 = ( int ) Math . abs ( ( maxLat - swathInfo [ 3 ] ) / yInc + 0.5 ) ; x2 = ( int ) ( ( maxLon - swathInfo [ 4 ] ) / xInc + 0.5 ) ; y2 = ( int ) Math . abs ( ( minLat - swathInfo [ 3 ] ) / yInc + 0.5 ) ; } if ( ! gcs . isLatLon ( ) ) { ProjectionPoint pjp0 = proj . latLonToProj ( maxLat , minLon ) ; x1 = getXIndex ( lon , pjp0 . getX ( ) , 0 ) ; y1 = getYIndex ( lat , pjp0 . getY ( ) , 0 ) ; yStart = pjp0 . getY ( ) * scaler ; //latArray[y1]; xStart = pjp0 . getX ( ) * scaler ; //lonArray[x1]; ProjectionPoint pjpn = proj . latLonToProj ( minLat , maxLon ) ; x2 = getXIndex ( lon , pjpn . getX ( ) , 1 ) ; y2 = getYIndex ( lat , pjpn . getY ( ) , 1 ) ; } else { //calculate the x1, x2, y1, y2, xstart, ystart. } Array targetImage = getTargetImagerFromSwath ( lat , lon , data , swathInfo ) ; Array interpolatedImage = interpolation ( targetImage ) ; Array clippedImage = getClippedImageFromInterpolation ( interpolatedImage , x1 , x2 , y1 , y2 ) ; //Array clippedImage = getYXDataInBox(interpolatedImage, x1, x2, y1, y2); if ( pageNumber > 1 ) { geotiff . initTags ( ) ; } writeGrid ( grid , clippedImage , greyScale , xStart , yStart , xInc , yInc , pageNumber ) ; pageNumber ++ ; }
Write Swath Grid data to the geotiff file.

@param fileName  _more_
@param gridName  _more_
@param time      _more_
@param level     _more_
@param greyScale _more_
@param llr       _more_
@throws IOException _more_
Write Swath Grid data to the geotiff file .