Created
March 12, 2020 19:49
-
-
Save phargogh/6d6ff055a50aba0d74fd129b254262e9 to your computer and use it in GitHub Desktop.
Write raster block/tile indexes to a new raster
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import logging | |
logging.basicConfig(level=logging.DEBUG) | |
import pygeoprocessing | |
from osgeo import gdal | |
import numpy | |
def doit(): | |
base_path = r'C:\Users\nope\Downloads\2020-03-05\datastack\data\raster_qfxu34t6\hdr.adf' | |
new_path = os.path.join(os.path.dirname(base_path), 'tile_indexes.tif') | |
pygeoprocessing.new_raster_from_base( | |
base_path, new_path, gdal.GDT_Byte, [255]) | |
new_raster = gdal.OpenEx(new_path, gdal.OF_RASTER | gdal.GA_Update) | |
new_band = new_raster.GetRasterBand(1) | |
for index, data in enumerate(pygeoprocessing.iterblocks( | |
(base_path, 1), offset_only=True)): | |
new_band.WriteArray( | |
numpy.full((data['win_ysize'], data['win_xsize']), index), | |
xoff=data['xoff'], | |
yoff=data['yoff'] | |
) | |
new_band = None | |
new_raster = None | |
if __name__ == '__main__': | |
doit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment