Java Code Examples for ucar.nc2.dataset.CoordinateAxis1D#getCoordEdge()

The following examples show how to use ucar.nc2.dataset.CoordinateAxis1D#getCoordEdge() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GeotiffWriter.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Write GridDatatype data to the geotiff file.
 *
 * @param dataset grid in contained in this dataset
 * @param grid data is in this grid
 * @param data 2D array in YX order
 * @param greyScale if true, write greyScale image, else dataSample.
 * @throws IOException on i/o error
 */
public void writeGrid(GridDataset dataset, GridDatatype grid, Array data, boolean greyScale) throws IOException {
  GridCoordSystem gcs = grid.getCoordinateSystem();

  if (!gcs.isRegularSpatial()) {
    throw new IllegalArgumentException("Must have 1D x and y axes for " + grid.getFullName());
  }

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

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

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

  if (yaxis.getCoordValue(0) < yaxis.getCoordValue(1)) {
    data = data.flip(0);
    yStart = yaxis.getCoordEdge((int) yaxis.getSize()) * scaler;
  }

  if (!xaxis.isRegular() || !yaxis.isRegular()) {
    throw new IllegalArgumentException("Must be evenly spaced grid = " + grid.getFullName());
  }

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

  // write it out
  writeGrid(grid, data, greyScale, xStart, yStart, xInc, yInc, pageNumber);
  pageNumber++;
}
 
Example 2
Source File: GridRenderer.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private int drawPathShape(Graphics2D g, int color, CoordinateAxis1D xaxis, CoordinateAxis1D yaxis) {
  int count = 0;
  for (int y = 0; y < yaxis.getSize() - 1; y++) {
    double y1 = yaxis.getCoordEdge(y);
    double y2 = yaxis.getCoordEdge(y + 1);
    count += drawPathRun(g, color, y1, y2, xaxis, 0, (int) xaxis.getSize() - 1);
  }

  return count;
}
 
Example 3
Source File: GridRenderer.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Do the rendering to the given Graphics2D object.
 *
 * @param g Graphics2D object: has clipRect and AffineTransform set.
 * @param dFromN transforms "Normalized Device" to Device coordinates
 */
public void renderVertView(java.awt.Graphics2D g, AffineTransform dFromN) {
  if ((stridedGrid == null) || (cs == null) || (drawProjection == null))
    return;

  if (!drawGrid && !drawContours)
    return;

  dataV = makeVSlice(stridedGrid, wantSlice, wantTime, wantEnsemble, wantRunTime);
  if (dataV == null)
    return;

  if (Debug.isSet("GridRenderer/vert"))
    System.out.println("GridRenderer/vert: redraw grid");

  GridCoordSystem geocs = stridedGrid.getCoordinateSystem();
  CoordinateAxis1D zaxis = geocs.getVerticalAxis();
  CoordinateAxis1D yaxis = (CoordinateAxis1D) geocs.getYHorizAxis();
  if ((yaxis == null) || (zaxis == null))
    return;
  int nz = (int) zaxis.getSize();
  int ny = (int) yaxis.getSize();

  if (drawGrid) {
    int count = 0;
    Index imaV = dataV.getIndex();
    for (int z = 0; z < nz; z++) {
      double zbeg = zaxis.getCoordEdge(z);
      double zend = zaxis.getCoordEdge(z + 1);

      for (int y = 0; y < ny; y++) {
        double ybeg = yaxis.getCoordEdge(y);
        double yend = yaxis.getCoordEdge(y + 1);

        double val = dataV.getDouble(imaV.set(z, y));
        int thisColor = cs.getIndexFromValue(val);
        count += drawRect(g, thisColor, ybeg, zbeg, yend, zend, false);
      }
    }
  }

  if (drawContours) {
    double[] zedges = zaxis.getCoordValues();
    double[] yedges = yaxis.getCoordValues();

    int nlevels = cs.getNumColors();
    ArrayList levels = new ArrayList(nlevels);
    for (int i = 1; i < nlevels - 1; i++)
      levels.add(cs.getEdge(i));

    long startTime = System.currentTimeMillis();
    ContourFeatureRenderer contourRendererV;
    try {
      ContourGrid conGrid = new ContourGrid(dataV.transpose(0, 1), levels, yedges, zedges, stridedGrid);
      contourRendererV = new ContourFeatureRenderer(conGrid, null);

      // contourRendererV.setProjection(drawProjection);
      contourRendererV.setColor(Color.black);
      contourRendererV.setShowLabels(drawContourLabels);
      contourRendererV.draw(g, dFromN);
    } catch (Exception e) {
      System.out.println("draw Contours Vert exception = " + e);
      e.printStackTrace(System.err);
    }
    if (Debug.isSet("timing/contourDraw")) {
      long tookTime = System.currentTimeMillis() - startTime;
      System.out.println("timing/contourDraw: Vert:" + tookTime * .001 + " seconds");
    }
  }

  if ((lastLevel >= 0) && (lastLevel < nz))
    drawXORline(g, yaxis.getCoordEdge(0), zaxis.getCoordValue(lastLevel), yaxis.getCoordEdge(ny),
        zaxis.getCoordValue(lastLevel));
}