Skip to content

Instantly share code, notes, and snippets.

@kissmygritts
Created December 2, 2022 19:01
Show Gist options
  • Save kissmygritts/93bc0d5d65d9ff89303585c2b9504a8c to your computer and use it in GitHub Desktop.
Save kissmygritts/93bc0d5d65d9ff89303585c2b9504a8c to your computer and use it in GitHub Desktop.
Create a raster with alternating 0 and 1 values for visualization
def alternate_raster_values(raster_filename, out_filename):
with rasterio.open(raster_filename, "r") as src:
data = src.read(1)
profile = src.profile
for i in range(data.shape[0]):
data[i] = 0
if i % 2 == 0:
data[i][1::2] = 1
else:
data[i][::2] = 1
with rasterio.open(out_filename, "w", **profile) as dst:
dst.write(data, 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment