private GeneralEnvelope getResultEnvelope(
      final List<RasterQueryInfo> queryInfos, final GridEnvelope mosaicGeometry) {

    // use the same queryInfo used by setMosaicLocations
    final RasterQueryInfo baseQueryInfo = RasterUtils.findLowestResolution(queryInfos);

    GeneralEnvelope finalEnvelope = null;
    // if (queryInfos.size() == 1) {
    // finalEnvelope = queryInfos.get(0).getResultEnvelope();
    // } else {
    int rasterIndex = baseQueryInfo.getRasterIndex();
    int pyramidLevel = baseQueryInfo.getPyramidLevel();
    MathTransform rasterToModel = rasterInfo.getRasterToModel(rasterIndex, pyramidLevel);
    CoordinateReferenceSystem coverageCrs = rasterInfo.getCoverageCrs();
    GeneralEnvelope mosaicGeometryEnv = new GeneralEnvelope(coverageCrs);
    mosaicGeometryEnv.setEnvelope(
        mosaicGeometry.getLow(0),
        mosaicGeometry.getLow(1),
        1 + mosaicGeometry.getHigh(0),
        1 + mosaicGeometry.getHigh(1));
    try {
      finalEnvelope = CRS.transform(rasterToModel, mosaicGeometryEnv);
      finalEnvelope.setCoordinateReferenceSystem(coverageCrs);
    } catch (TransformException e) {
      throw new RuntimeException(e);
    }
    // }

    // double[] resolution = baseQueryInfo.getResolution();
    // finalEnvelope = toPixelCenter(resolution, finalEnvelope);
    return finalEnvelope;
  }
  public ArcSDEGridCoverage2DReaderJAI(
      final ArcSDERasterFormat parent,
      final RasterReaderFactory rasterReaderFactory,
      final RasterDatasetInfo rasterInfo,
      final Hints hints)
      throws IOException {
    // check it's a supported format
    {
      final int bitsPerSample = rasterInfo.getBand(0, 0).getCellType().getBitsPerSample();
      if (rasterInfo.getNumBands() > 1 && (bitsPerSample == 1 || bitsPerSample == 4)) {
        throw new IllegalArgumentException(
            bitsPerSample + "-bit rasters with more than one band are not supported");
      }
    }
    this.parent = parent;
    this.rasterReaderFactory = rasterReaderFactory;
    this.rasterInfo = rasterInfo;

    super.hints = hints;
    super.coverageFactory = CoverageFactoryFinder.getGridCoverageFactory(this.hints);
    super.crs = rasterInfo.getCoverageCrs();
    super.originalEnvelope = rasterInfo.getOriginalEnvelope(PixelInCell.CELL_CENTER);

    GridEnvelope gridRange = rasterInfo.getOriginalGridRange();
    // super.originalGridRange = new GeneralGridRange(gridRange.toRectangle());
    super.originalGridRange = gridRange;

    super.coverageName = rasterInfo.getRasterTable();
    final int numLevels = rasterInfo.getNumPyramidLevels(0);

    // level 0 is not an overview, but the raster itself
    super.numOverviews = numLevels - 1;

    // ///
    //
    // setting the higher resolution avalaible for this coverage
    //
    // ///
    highestRes =
        super.getResolution(
            originalEnvelope,
            new Rectangle(
                originalGridRange.getLow(0),
                originalGridRange.getLow(1),
                originalGridRange.getSpan(0),
                originalGridRange.getSpan(1)),
            crs);
    // //
    //
    // get information for the successive images
    //
    // //
    // REVISIT may the different rasters in the raster dataset have different pyramid levels? I
    // guess so
    if (numOverviews > 0) {
      overViewResolutions = new double[numOverviews][2];
      for (int pyramidLevel = 1; pyramidLevel <= numOverviews; pyramidLevel++) {
        GridEnvelope levelGridRange = rasterInfo.getGridRange(0, pyramidLevel);
        GeneralEnvelope levelEnvelope = rasterInfo.getGridEnvelope(0, pyramidLevel);

        Rectangle2D levelGridRangeRect =
            new Rectangle2D.Double(
                levelGridRange.getLow(0),
                levelGridRange.getLow(1),
                levelGridRange.getSpan(0),
                levelGridRange.getSpan(1));
        overViewResolutions[pyramidLevel - 1] =
            super.getResolution(levelEnvelope, levelGridRangeRect, crs);
      }
    } else {
      overViewResolutions = null;
    }
  }