code: public static int[] getLoopColsRowsForSubregion( GridCoverage2D gridCoverage, Envelope2D subregion ) throws Exception {
          GridGeometry2D gridGeometry = gridCoverage.getGridGeometry();
          GridEnvelope2D subRegionGrid = gridGeometry.worldToGrid(subregion);
          int minCol = subRegionGrid.x;
          int maxCol = subRegionGrid.x + subRegionGrid.width;
          int minRow = subRegionGrid.y;
          int maxRow = subRegionGrid.y + subRegionGrid.height;
          return new int[]{minCol, maxCol, minRow, maxRow};
      }
docs: Get the cols and rows ranges to use to loop the original gridcoverage.
  
  @param gridCoverage the coverage.
  @param subregion the sub region of the coverage to get the cols and rows to loop on.
  @return the array of looping values in the form [minCol, maxCol, minRow, maxRow].
  @throws Exception