[Task] Explore the correct way of creating COG.
- Dominant language
- Python
- Stars
- 252
- Forks
- 60
- Avg merge
- 8d 4h
- Merged PRs (30d)
- 3
Description
As per https://github.com/rasterio/rasterio/discussions/2675#discussioncomment-4341970 the way we are creating COG's is not right.
Check correctness & measure efficiency of the current & suggested approach -- make necessary changes if required.
#### Code snippet as per above comment:
```
profile = {
'dtype': dtype,
'width': data[0].data.shape[1],
'height': data[0].data.shape[0],
'count': len(data),
'nodata': np.nan,
'crs': crs,
'transform': transform,
'compress': 'lzw'
}
with tempfile.NamedTemporaryFile() as temp:
with rasterio.MemoryFile() as memfile:
with memfile.open(driver='GTiff', **profile) as f:
for i, da in enumerate(data):
f.write(da, i + 1)
# Making the channel name EE-safe.
f.set_band_description(i + 1,
get_ee_safe_name(channel_names[i]))
f.update_tags(i + 1, band_name=channel_names[i])
f.update_tags(i + 1, **da.attrs)
# Write attributes as tags in tiff.
f.update_tags(**attrs)
print("tags update : " + datetime.now().strftime("%H:%M:%S"))
# Create COG
rasterio_copy(f, temp.name, driver="COG", compress="lzw", bigtiff="IF_NEEDED")
# Copy the created COG to gcs.
target_path = os.path.join(self.asset_location, file_name)
gcs_copy(temp.name, target_path)
del f, memfile, data
```
Contributor guide
Assessment
This issue has not been assessed yet.