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;
  }
  private void readAllTiledRasters(
      final List<RasterQueryInfo> queries,
      final TiledRasterReader rasterReader,
      final LoggingHelper log)
      throws IOException {

    for (RasterQueryInfo queryInfo : queries) {

      final Long rasterId = queryInfo.getRasterId();

      final RenderedImage rasterImage;

      try {
        final int pyramidLevel = queryInfo.getPyramidLevel();
        final GridEnvelope matchingTiles = queryInfo.getMatchingTiles();
        // final Point imageLocation = queryInfo.getTiledImageSize().getLocation();
        rasterImage = rasterReader.read(rasterId, pyramidLevel, matchingTiles);
      } catch (IOException e) {
        LOGGER.log(Level.SEVERE, "Fetching data for " + queryInfo.toString(), e);
        throw e;
      }

      queryInfo.setResultImage(rasterImage);

      {
        LOGGER.finer(queryInfo.toString());
        log.appendLoggingGeometries(LoggingHelper.MOSAIC_EXPECTED, queryInfo.getMosaicLocation());
        log.appendLoggingGeometries(LoggingHelper.MOSAIC_ENV, queryInfo.getResultEnvelope());

        // final Rectangle tiledImageSize = queryInfo.getTiledImageSize();
        // int width = rasterImage.getWidth();
        // int height = rasterImage.getHeight();
        // if (tiledImageSize.width != width || tiledImageSize.height != height) {
        // throw new IllegalStateException(
        // "Read image is not of the expected size. Image=" + width + "x" + height
        // + ", expected: " + tiledImageSize.width + "x"
        // + tiledImageSize.height);
        // }
      }
    }
  }