Created
          December 2, 2022 19:01 
        
      - 
      
- 
        Save kissmygritts/93bc0d5d65d9ff89303585c2b9504a8c to your computer and use it in GitHub Desktop. 
    Create a raster with alternating 0 and 1 values for visualization
  
        
  
    
      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
    
  
  
    
  | 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