Guest User

Untitled

a guest
Nov 20th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #import modules arcpy and string
  2. import arcpy, string
  3.  
  4. #import the environment settings and spatial analyst extension
  5. from arcpy import env
  6. from arcpy.sa import *
  7.  
  8. #Check out the Spatial Analyst extension (must be available to check out!)
  9. arcpy.CheckOutExtension('spatial')
  10.  
  11. #Add your workspace here
  12. env.workspace = r'C:WORKSPACE'
  13. env.overwriteOutput = True
  14.  
  15. #Define inputs from TIFFs
  16. Band2 = 'LANDSAT_B2.tif' #Band 2
  17. Band4 = 'LC08_L1TP_019036_20130604_20170310_01_T1_B4.tif' #Band 4
  18. Band5 = 'LC08_L1TP_019036_20130604_20170310_01_T1_B5.tif' #Band 5
  19.  
  20. #Band Ratios
  21. R42 = arcpy.sa.Divide(Band4, Band2)
  22. R52 = arcpy.sa.Divide(Band5, Band2)
  23. R54 = arcpy.sa.Divide(Band5, Band4)
  24. print 'Ratioed Bands'
  25.  
  26. #Slopes
  27. a = 52
  28. b = 11
  29. c = 33.5
  30. d = 120
  31.  
  32. #Algorithm processing
  33. ALG = a - (b * R42) + (c * R52) - (d * R54)
  34.  
  35. #Saving final product
  36. result = 'ALG.tif'
  37. ALG.save(result)
  38. print 'Success'
  39.  
  40. arcpy.env.workspace=r'C:/WORKSPACE/Band2'
  41. B2rasters=arcpy.ListRasters('*.tif*')
  42. arcpy.env.workspace=r'C:/WORKSPACE/Band4'
  43. B4rasters=arcpy.ListRasters('*.tif*')
  44.  
  45. for idx in range(0, len(B2rasters) - 1):
  46. b2 = B2rasters[idx]
  47. b4 = B4rasters[idx]
  48. output = b4 / b2
  49. result = output + idx
  50. output.save(result)
  51. print result
Add Comment
Please, Sign In to add comment