MemoryFile loses Profile information


ciaran.evans@...
 

Hi there,

I'm currently re-writing a process that was stacking .jp2 bands into one image and writing the resultant stack to disk.

I'm moving this up to AWS so want to use MemoryFile's instead. 

My code looks something like:
s3_r = boto3.resource('s3')
profile = source_image.profile.copy()

with rasterio.io.MemoryFile() as stack:
with stack.open(**profile) as stack_out:
stack_out.write(source_image.read(1), 1)
stack.seek(0)
s3_r.Object(<my-bucket>, <my-key>).upload_fileobj(stack)

If I download that image and open it in QGIS, the image has no geo-coding at all.

If I process the same image, but write to disk like:

profile = source_image.profile.copy()

with rasterio.open('thing.jp2', 'w', **profile) as stack_out:
stack_out.write(source_image.read(1), 1))

I get a geo-coded image and it appears where I'd expect.

If I compare file sizes:
MemoryFile(): 49,211KB
Disk: 49,214KB

I can only assume I'm losing any profile information when using a MemoryFile, can someone direct me to what I'm doing wrong?

Thanks!

Join main@rasterio.groups.io to automatically receive all group messages.