def test_boundless_vrt_preserves_mask(): expected = GeoRaster2.open("tests/data/raster/overlap1.tif") with rasterio.open(expected.source_file) as raster: doc = boundless_vrt_doc(raster, bands=[1, 2]).tostring() with TemporaryDirectory() as d: file_name = os.path.join(d, 'vrt_file.vrt') with open(file_name, 'wb') as f: f.write(doc) raster = GeoRaster2.open(file_name) assert np.array_equal(raster.image.mask, expected.image.mask[:2, :, :])
def build_vrt(source_file, destination_file, **kwargs): """Make a VRT XML document and write it in file. Parameters ---------- source_file : str, file object or pathlib.Path object Source file. destination_file : str Destination file. kwargs : optional Additional arguments passed to rasterio.vrt._boundless_vrt_doc Returns ------- out : str The path to the destination file. """ with rasterio.open(source_file) as src: vrt_doc = boundless_vrt_doc(src, **kwargs).tostring() with open(destination_file, 'wb') as dst: dst.write(vrt_doc) return destination_file
def test_boundless_vrt(): with rasterio.open("tests/data/raster/overlap2.tif") as raster: doc = boundless_vrt_doc(raster).tostring() with open("tests/data/raster/overlap2.vrt", 'rb') as expected_src: expected = expected_src.read() assert expected == doc