ui/src/main/java/ucar/nc2/ui/coverage2/CoverageRenderer.java
private void drawGridHorizRegular(java.awt.Graphics2D g, GeoReferencedArray array) {
    int count = 0;

    CoverageCoordSys gsys = array.getCoordSysForData();
    CoverageCoordAxis1D xaxis = (CoverageCoordAxis1D) gsys.getXAxis();
    CoverageCoordAxis1D yaxis = (CoverageCoordAxis1D) gsys.getYAxis();
    Array data = array.getData().reduce();
    if (data.getRank() != 2) {
      System.out.printf("drawGridHorizRegular Rank equals %d, must be 2%n", data.getRank());
      return;
    }

    int nx = xaxis.getNcoords();
    int ny = yaxis.getNcoords();

    //// drawing optimizations
    sameProjection = drawProjection.equals(dataProjection);
    if (drawProjection.isLatLon()) {
      projectll = (LatLonProjection) drawProjection;
      double centerLon = projectll.getCenterLon();
      if (Debug.isSet("projection/LatLonShift")) System.out.println("projection/LatLonShift: gridDraw = " + centerLon);
    }

    // find the most common color and fill the entire area with it
    colorScale.resetHist();
    IndexIterator iiter = array.getData().getIndexIterator();
    while (iiter.hasNext()) {
      double val = iiter.getDoubleNext();
      colorScale.getIndexFromValue(val);                // accum in histogram
    }
    int modeColor = colorScale.getHistMax();
    if (debugMiss) System.out.println("mode = " + modeColor + " sameProj= " + sameProjection);

    if (sameProjection) {
      double xmin = Math.min(xaxis.getCoordEdge1(0), xaxis.getCoordEdgeLast());
      double xmax = Math.max(xaxis.getCoordEdge1(0), xaxis.getCoordEdgeLast());
      double ymin = Math.min(yaxis.getCoordEdge1(0), yaxis.getCoordEdgeLast());
      double ymax = Math.max(yaxis.getCoordEdge1(0), yaxis.getCoordEdgeLast());

      // pre color the drawing area with the most used color
      count += drawRect(g, modeColor, xmin, ymin, xmax, ymax, drawProjection.isLatLon());

    } else if (useModeForProjections)
      drawPathShape(g, modeColor, xaxis, yaxis);

    debugPts = Debug.isSet("GridRenderer/showPts");

    // draw individual rects with run length
    Index imaH = data.getIndex();
    for (int y = 0; y < ny; y++) {
      double ybeg = yaxis.getCoordEdge1(y);
      double yend = yaxis.getCoordEdge2(y);

      int thisColor, lastColor = 0;
      int run = 0;
      int xbeg = 0;

      for (int x = 0; x < nx; x++) {
        double val = data.getDouble(imaH.set(y, x));
        thisColor = colorScale.getIndexFromValue(val);

        if ((run == 0) || (lastColor == thisColor)) { // same color - keep running
          run++;
        } else {
          if (sameProjection) {
            if (lastColor != modeColor) // dont have to draw these
              count += drawRect(g, lastColor, xaxis.getCoordEdge1(xbeg), ybeg, xaxis.getCoordEdge2(x), yend, drawProjection.isLatLon());
          } else {
            if (!useModeForProjections || (lastColor != modeColor)) // dont have to draw mode
              count += drawPathRun(g, lastColor, ybeg, yend, xaxis, xbeg, x-1, debugPts);
          }
          xbeg = x;
        }
        lastColor = thisColor;
      }

      // get the ones at the end
      if (sameProjection) {
        if (lastColor != modeColor)
          count += drawRect(g, lastColor, xaxis.getCoordEdge1(xbeg), ybeg, xaxis.getCoordEdgeLast(), yend, drawProjection.isLatLon());
      } else {
        if (!useModeForProjections || (lastColor != modeColor))
          count += drawPathRun(g, lastColor, ybeg, yend, xaxis, xbeg, nx - 1, false); // needed ?
      }

      // if (debugPts) break;
    }
    if (debugHorizDraw) System.out.println("debugHorizDraw = " + count);
  }
private void drawGridHorizRegular(java.awt.Graphics2D g, GeoReferencedArray array) {
    int count = 0;

    CoverageCoordSys gsys = array.getCoordSysForData();
    CoverageCoordAxis1D xaxis = (CoverageCoordAxis1D) gsys.getXAxis();
    CoverageCoordAxis1D yaxis = (CoverageCoordAxis1D) gsys.getYAxis();
    Array data = array.getData().reduce();
    if (data.getRank() != 2) {
      System.out.printf("drawGridHorizRegular Rank equals %d, must be 2%n", data.getRank());
      return;
    }

    int nx = xaxis.getNcoords();
    int ny = yaxis.getNcoords();

    //// drawing optimizations
    sameProjection = drawProjection.equals(dataProjection);
    if (drawProjection.isLatLon()) {
      projectll = (LatLonProjection) drawProjection;
      double centerLon = projectll.getCenterLon();
      if (Debug.isSet("projection/LatLonShift")) System.out.println("projection/LatLonShift: gridDraw = " + centerLon);
    }

    // find the most common color and fill the entire area with it
    colorScale.resetHist();
    IndexIterator iiter = array.getData().getIndexIterator();
    while (iiter.hasNext()) {
      double val = iiter.getDoubleNext();
      colorScale.getIndexFromValue(val);                // accum in histogram
    }
    int modeColor = colorScale.getHistMax();
    if (debugMiss) System.out.println("mode = " + modeColor + " sameProj= " + sameProjection);

    if (sameProjection) {
      double xmin = Math.min(xaxis.getCoordEdge1(0), xaxis.getCoordEdgeLast());
      double xmax = Math.max(xaxis.getCoordEdge1(0), xaxis.getCoordEdgeLast());
      double ymin = Math.min(yaxis.getCoordEdge1(0), yaxis.getCoordEdgeLast());
      double ymax = Math.max(yaxis.getCoordEdge1(0), yaxis.getCoordEdgeLast());

      // pre color the drawing area with the most used color
      count += drawRect(g, modeColor, xmin, ymin, xmax, ymax, drawProjection.isLatLon());

    } else if (useModeForProjections)
      drawPathShape(g, modeColor, xaxis, yaxis);

    debugPts = Debug.isSet("GridRenderer/showPts");

    // draw individual rects with run length
    Index imaH = data.getIndex();
    for (int y = 0; y < ny; y++) {
      double ybeg = yaxis.getCoordEdge1(y);
      double yend = yaxis.getCoordEdge2(y);

      int thisColor, lastColor = 0;
      int run = 0;
      int xbeg = 0;

      for (int x = 0; x < nx; x++) {
        double val = data.getDouble(imaH.set(y, x));
        thisColor = colorScale.getIndexFromValue(val);

        if ((run == 0) || (lastColor == thisColor)) { // same color - keep running
          run++;
        } else {
          if (sameProjection) {
            if (lastColor != modeColor) // dont have to draw these
              count += drawRect(g, lastColor, xaxis.getCoordEdge1(xbeg), ybeg, xaxis.getCoordEdge2(x), yend, drawProjection.isLatLon());
          } else {
            if (!useModeForProjections || (lastColor != modeColor)) // dont have to draw mode
              count += drawPathRun(g, lastColor, ybeg, yend, xaxis, xbeg, x-1, debugPts);
          }
          xbeg = x;
        }
        lastColor = thisColor;
      }

      // get the ones at the end
      if (sameProjection) {
        if (lastColor != modeColor)
          count += drawRect(g, lastColor, xaxis.getCoordEdge1(xbeg), ybeg, xaxis.getCoordEdgeLast(), yend, drawProjection.isLatLon());
      } else {
        if (!useModeForProjections || (lastColor != modeColor))
          count += drawPathRun(g, lastColor, ybeg, yend, xaxis, xbeg, nx - 1, false); // needed ?
      }

      // if (debugPts) break;
    }
    if (debugHorizDraw) System.out.println("debugHorizDraw = " + count);
  }
/* draw using GeneralPath shape
private GeneralPath gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 5);
private Shape makeShape(double lon1, double lat1, double lon2, double lat2) {
gp.reset();
ProjectionPoint pt = drawProjection.latLonToProj( lat1, lon1);
gp.moveTo( (float) pt.getX(), (float) pt.getY());

ptP1.setLocation(pt);
pt = drawProjection.latLonToProj( lat1, lon2);
gp.lineTo( (float) pt.getX(), (float) pt.getY());
if (drawProjection.crossSeam(ptP1, pt))
return null;

ptP1.setLocation(pt);
pt = drawProjection.latLonToProj( lat2, lon2);
gp.lineTo( (float) pt.getX(), (float) pt.getY());
if (drawProjection.crossSeam(ptP1, pt))
return null;

ptP1.setLocation(pt);
pt = drawProjection.latLonToProj( lat2, lon1);
gp.lineTo( (float) pt.getX(), (float) pt.getY());
if (drawProjection.crossSeam(ptP1, pt))
return null;

return gp;
}