Last active
August 29, 2015 13:56
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 rasterio | |
with rasterio.open('input.tif') as src: | |
source = src.read_band(1) | |
def window_transform(transform, offset): | |
result = transform[:] | |
result[3] = transform[3] + offset[0]*transform[5] | |
result[0] = transform[0] + offset[1]*transform[1] | |
return result | |
# This is the idiom for copying parameters from a file to use | |
# when writing a new file. | |
kwargs = src.meta | |
kwargs.update( | |
width=512, | |
height=512, | |
# calculates a new affine transformation matrix, offset 256 rows and 0 columns | |
# from the one in src. | |
transform=window_transform(src.transform, (256, 0)) | |
with rasterio.open('output.tif', 'w', **kwargs) as dst: | |
dst.write_band(1, source[:512,:512]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment