def raster_collection_vrt(fc, relative_to_vrt=True, nodata=None, mask_band=None):
    """Make a VRT XML document from a feature collection of GeoRaster2 objects.
    Parameters
    ----------
    rasters : FeatureCollection
        The FeatureCollection of GeoRasters.
    relative_to_vrt : bool, optional
        If True the bands simple source url will be related to the VRT file
    nodata : int, optional
        If supplied is the note data value to be used
    mask_band: int, optional
        If specified detrimes from which band to use the mask
    Returns
    -------
    bytes
        An ascii-encoded string (an ElementTree detail)
    """

    def max_resolution():
        max_affine = max(fc, key=lambda f: f.raster().resolution()).raster().affine
        return abs(max_affine.a), abs(max_affine.e)

    from telluric import rasterization
    from telluric.georaster import band_names_tag
    assert all(fc.crs == f.crs for f in fc), "all rasters should have the same CRS"

    rasters = (f.raster() for f in fc)
    bounds = fc.convex_hull.get_bounds(fc.crs)
    resolution = max_resolution()
    width, height, affine = rasterization.raster_data(bounds, resolution)

    bands = {}  # type: Dict[str, tuple]
    band_names = []  # type: List[Any]
    vrt = BaseVRT(width, height, fc.crs, affine)

    last_band_idx = 0
    if mask_band is not None:
        mask_band = vrt.add_mask_band("Byte")

    for raster in rasters:
        for i, band_name in enumerate(raster.band_names):
            if band_name in bands:
                band_element, band_idx = bands[band_name]
            else:
                last_band_idx += 1
                band_idx = last_band_idx
                band_element = vrt.add_band(raster.dtype, band_idx, band_name_to_color_interpretation(band_name),
                                            nodata=nodata)
                bands[band_name] = (band_element, last_band_idx)
                band_names.append(band_name)

            src_window = Window(0, 0, raster.width, raster.height)
            xoff = (raster.affine.xoff - affine.xoff) / affine.a
            yoff = (raster.affine.yoff - affine.yoff) / affine.e
            xsize = raster.width * raster.affine.a / affine.a
            ysize = raster.height * raster.affine.e / affine.e
            dst_window = Window(xoff, yoff, xsize, ysize)
            file_name = raster.source_file if relative_to_vrt else os.path.join(os.getcwd(), raster.source_file)

            vrt.add_band_simplesource(band_element, band_idx, raster.dtype, relative_to_vrt, file_name,
                                      raster.width, raster.height,
                                      raster.block_shape(i)[1], raster.block_shape(i)[0],
                                      src_window, dst_window)
            if i == mask_band:
                vrt.add_band_simplesource(mask_band, "mask,%s" % (mask_band + 1), "Byte", relative_to_vrt, file_name,
                                          raster.width, raster.height,
                                          raster.block_shape(i)[1], raster.block_shape(i)[0],
                                          src_window, dst_window)

    vrt.add_metadata(items={band_names_tag: json.dumps(band_names)})
    return vrt
Make a VRT XML document from a feature collection of GeoRaster2 objects.
    Parameters
    ----------
    rasters : FeatureCollection
        The FeatureCollection of GeoRasters.
    relative_to_vrt : bool, optional
        If True the bands simple source url will be related to the VRT file
    nodata : int, optional
        If supplied is the note data value to be used
    mask_band: int, optional
        If specified detrimes from which band to use the mask
    Returns
    -------
    bytes
        An ascii-encoded string (an ElementTree detail)