I am merging datasets to a memory file using rasterio. However I can't get the memory file to take on the profile attributes passed in as dst_kwds
. I get the desired result when I write the dataset to disk as below:
profile = ds.profile
profile.update(
dtype=rasterio.uint8,
count=1,
compress='lzw')
# create dataset as file on disk
rasterio.merge.merge(datasets, dst_path="test.jp2", dst_kwds=profile)
#open and print profile
test_ds = rasterio.open("test.jp2")
print(test_ds.profile)
{'driver': 'JP2OpenJPEG', 'dtype': 'uint8', 'nodata': None, 'width': 40000, 'height': 10000, 'count': 1, 'crs': CRS.from_epsg(7856), 'transform': Affine(0.15, 0.0, 294394.575, 0.0, -0.15, 6276235.425000001), 'blockxsize': 1024, 'blockysize': 1024, 'tiled': True}
But when I use a memory file it doesn't take on profile as I would expect:
# create dataset file in memory
memfile = MemoryFile()
rasterio.merge.merge(datasets, dst_path=memfile, dst_kwds=profile)
mem_ds = memfile.open(**profile)
print(mem_ds.profile)
{'driver': 'JP2OpenJPEG', 'dtype': 'uint8', 'nodata': None, 'width': 40000, 'height': 10000, 'count': 1, 'crs': None, 'transform': Affine(1.0, 0.0, 0.0, 0.0, 1.0, 0.0), 'blockxsize': 1024, 'blockysize': 1024, 'tiled': True}
I have tried many variations however I can't get the memory file to take on the profile attributes. I understand I could manually assign the profile attributes however I feel there could be a quicker way.
memfile
object to thedst_path
param of the merge function.