|
| 1 | +#!/usr/bin/env python |
| 2 | +# coding: utf-8 |
| 3 | + |
| 4 | +# #### Suitability Raster Analysis |
| 5 | +# ##### Question 1 |
| 6 | +# Please create a Model in either ArcGIS Pro for the Bobcat habitat example we discussed in class and export your model as both a python script and a image (lab5.py and lab5.jpg - 15 points) |
| 7 | + |
| 8 | +# In[9]: |
| 9 | + |
| 10 | + |
| 11 | +import arcpy |
| 12 | +from arcpy.sa import * |
| 13 | + |
| 14 | +#workplace location |
| 15 | +arcpy.env.workspace = "C:\\Users\\akunna1\\Desktop\\GEOG 592\\Lab_5\\Data.gdb\\" |
| 16 | +arcpy.env.overwriteOutput = True |
| 17 | + |
| 18 | +# Checking out necessary licenses |
| 19 | +arcpy.CheckOutExtension("3D") |
| 20 | +arcpy.CheckOutExtension("spatial") |
| 21 | +arcpy.CheckOutExtension("ImageAnalyst") |
| 22 | + |
| 23 | +# Setting up Geoprocessing environments |
| 24 | +arcpy.env.snapRaster = "C:\\Users\\akunna1\\Desktop\\GEOG 592\\Lab_5\\Data.gdb\\Elevation" |
| 25 | +arcpy.env.extent = "439952.113762345 200181.284694512 513122.113762345 253671.284694512" |
| 26 | +arcpy.env.cellSize = "30" |
| 27 | +arcpy.env.mask = "C:\\Users\\akunna1\\Desktop\\GEOG 592\\Lab_5\\Data.gdb\\Elevation" |
| 28 | + |
| 29 | +Streams = "C:\\Users\\akunna1\\Desktop\\GEOG 592\\Lab_5\\Data.gdb\\Streams" |
| 30 | +Elevation = arcpy.Raster("C:\\Users\\akunna1\\Desktop\\GEOG 592\\Lab_5\\Data.gdb\\Elevation") |
| 31 | +LandUse = arcpy.Raster("C:\\Users\\akunna1\\Desktop\\GEOG 592\\Lab_5\\Data.gdb\\LandUse") |
| 32 | + |
| 33 | +# Process: Distance Accumulation (Distance Accumulation) (sa) |
| 34 | +Distanc_Stre1 = "Distanc_Stre1" |
| 35 | +Distance_Accumulation = Distanc_Stre1 |
| 36 | +blkRaster = "blkRaster" |
| 37 | +osdr = "osdr" |
| 38 | +oslr = "oslr" |
| 39 | +Distanc_Stre1 = arcpy.sa.DistanceAccumulation(in_source_data=Streams, vertical_factor="BINARY 1 -30 30", horizontal_factor="BINARY 1 45", out_back_direction_raster=blkRaster, out_source_direction_raster=osdr, out_source_location_raster=oslr, distance_method="PLANAR") |
| 40 | +Distanc_Stre1.save(Distance_Accumulation) |
| 41 | + |
| 42 | +blkRaster = arcpy.Raster(blkRaster) |
| 43 | +osdr = arcpy.Raster(osdr) |
| 44 | +oslr = arcpy.Raster(oslr) |
| 45 | + |
| 46 | +# Process: Slope (Slope) (sa) |
| 47 | +Slope_Elevat1 = "Slope_Elevat1" |
| 48 | +Slope = Slope_Elevat1 |
| 49 | +Slope_Elevat1 = arcpy.sa.Slope(in_raster=Elevation, output_measurement="DEGREE", z_factor=0.30480060960121924, method="PLANAR", z_unit="Foot_US") |
| 50 | +Slope_Elevat1.save(Slope) |
| 51 | + |
| 52 | +# Process: Reclassify (Reclassify) (sa) |
| 53 | +Reclass_Slop1 = "Reclass_Slop1" |
| 54 | +Reclassify = Reclass_Slop1 |
| 55 | +Reclass_Slop1 = arcpy.sa.Reclassify(in_raster=Slope_Elevat1, reclass_field="VALUE", remap="0 3 1;3 10 3;10 25 6;25 90 10", missing_values="DATA") |
| 56 | +Reclass_Slop1.save(Reclassify) |
| 57 | + |
| 58 | +# Process: Reclassify (2) (Reclassify) (sa) |
| 59 | +Reclass_Land1 = "Reclass_Land1" |
| 60 | +Reclassify_2_ = Reclass_Land1 |
| 61 | +Reclass_Land1 = arcpy.sa.Reclassify(in_raster=LandUse, reclass_field="VALUE", remap="1 1;2 1;3 1;4 2;5 8;6 10;7 10;8 10;9 6;10 2;11 10;12 1", missing_values="DATA") |
| 62 | +Reclass_Land1.save(Reclassify_2_) |
| 63 | + |
| 64 | +# Process: Rescale by Function (Rescale by Function) (sa) |
| 65 | +Rescale_Dist1 = "Rescale_Dist1" |
| 66 | +Rescale_by_Function = Rescale_Dist1 |
| 67 | +Rescale_Dist1 = arcpy.sa.RescaleByFunction(in_raster=Distanc_Stre1, transformation_function=[["MSSMALL", "", "", "", "", 1, 1, ""]], from_scale=1, to_scale=10) |
| 68 | +Rescale_Dist1.save(Rescale_by_Function) |
| 69 | + |
| 70 | +# Process: Raster Calculator (Raster Calculator) (sa) |
| 71 | +reclas_raste = "reclas_raste" |
| 72 | +Raster_Calculator = reclas_raste |
| 73 | +reclas_raste = Reclass_Slop1 *0.3 + Reclass_Land1 *0.3 + Rescale_Dist1 *0.4 |
| 74 | +reclas_raste.save(Raster_Calculator) |
| 75 | + |
| 76 | + |
| 77 | +# ##### Question 2 |
| 78 | +# Modify the script (lab5.py) so it will allow a user to configure weights of slope, landuse, and distance to streams. (10 points) |
| 79 | + |
| 80 | +# In[10]: |
| 81 | + |
| 82 | + |
| 83 | +import arcpy |
| 84 | +from arcpy.sa import * |
| 85 | + |
| 86 | +#workplace location |
| 87 | +arcpy.env.workspace = "C:\\Users\\akunna1\\Desktop\\GEOG 592\\Lab_5\\Data.gdb\\" |
| 88 | +arcpy.env.overwriteOutput = True |
| 89 | + |
| 90 | +# Checking out necessary licenses |
| 91 | +arcpy.CheckOutExtension("3D") |
| 92 | +arcpy.CheckOutExtension("spatial") |
| 93 | +arcpy.CheckOutExtension("ImageAnalyst") |
| 94 | + |
| 95 | +# Setting up Geoprocessing environments |
| 96 | +arcpy.env.snapRaster = "C:\\Users\\akunna1\\Desktop\\GEOG 592\\Lab_5\\Data.gdb\\Elevation" |
| 97 | +arcpy.env.extent = "439952.113762345 200181.284694512 513122.113762345 253671.284694512" |
| 98 | +arcpy.env.cellSize = "30" |
| 99 | +arcpy.env.mask = "C:\\Users\\akunna1\\Desktop\\GEOG 592\\Lab_5\\Data.gdb\\Elevation" |
| 100 | + |
| 101 | +Streams = "C:\\Users\\akunna1\\Desktop\\GEOG 592\\Lab_5\\Data.gdb\\Streams" |
| 102 | +Elevation = arcpy.Raster("C:\\Users\\akunna1\\Desktop\\GEOG 592\\Lab_5\\Data.gdb\\Elevation") |
| 103 | +LandUse = arcpy.Raster("C:\\Users\\akunna1\\Desktop\\GEOG 592\\Lab_5\\Data.gdb\\LandUse") |
| 104 | + |
| 105 | +# Process: Distance Accumulation (Distance Accumulation) (sa) |
| 106 | +Distanc_Stre1 = "Distanc_Stre1" |
| 107 | +Distance_Accumulation = Distanc_Stre1 |
| 108 | +blkRaster = "blkRaster" |
| 109 | +osdr = "osdr" |
| 110 | +oslr = "oslr" |
| 111 | +Distanc_Stre1 = arcpy.sa.DistanceAccumulation(in_source_data=Streams, vertical_factor="BINARY 1 -30 30", horizontal_factor="BINARY 1 45", out_back_direction_raster=blkRaster, out_source_direction_raster=osdr, out_source_location_raster=oslr, distance_method="PLANAR") |
| 112 | +Distanc_Stre1.save(Distance_Accumulation) |
| 113 | + |
| 114 | +blkRaster = arcpy.Raster(blkRaster) |
| 115 | +osdr = arcpy.Raster(osdr) |
| 116 | +oslr = arcpy.Raster(oslr) |
| 117 | + |
| 118 | +# Process: Slope (Slope) (sa) |
| 119 | +Slope_Elevat1 = "Slope_Elevat1" |
| 120 | +Slope = Slope_Elevat1 |
| 121 | +Slope_Elevat1 = arcpy.sa.Slope(in_raster=Elevation, output_measurement="DEGREE", z_factor=0.30480060960121924, method="PLANAR", z_unit="Foot_US") |
| 122 | +Slope_Elevat1.save(Slope) |
| 123 | + |
| 124 | +# Process: Reclassify (Reclassify) (sa) |
| 125 | +Reclass_Slop1 = "Reclass_Slop1" |
| 126 | +Reclassify = Reclass_Slop1 |
| 127 | +Reclass_Slop1 = arcpy.sa.Reclassify(in_raster=Slope_Elevat1, reclass_field="VALUE", remap="0 3 1;3 10 3;10 25 6;25 90 10", missing_values="DATA") |
| 128 | +Reclass_Slop1.save(Reclassify) |
| 129 | + |
| 130 | +# Process: Reclassify (2) (Reclassify) (sa) |
| 131 | +Reclass_Land1 = "Reclass_Land1" |
| 132 | +Reclassify_2_ = Reclass_Land1 |
| 133 | +Reclass_Land1 = arcpy.sa.Reclassify(in_raster=LandUse, reclass_field="VALUE", remap="1 1;2 1;3 1;4 2;5 8;6 10;7 10;8 10;9 6;10 2;11 10;12 1", missing_values="DATA") |
| 134 | +Reclass_Land1.save(Reclassify_2_) |
| 135 | + |
| 136 | +# Process: Rescale by Function (Rescale by Function) (sa) |
| 137 | +Rescale_Dist1 = "Rescale_Dist1" |
| 138 | +Rescale_by_Function = Rescale_Dist1 |
| 139 | +Rescale_Dist1 = arcpy.sa.RescaleByFunction(in_raster=Distanc_Stre1, transformation_function=[["MSSMALL", "", "", "", "", 1, 1, ""]], from_scale=1, to_scale=10) |
| 140 | +Rescale_Dist1.save(Rescale_by_Function) |
| 141 | + |
| 142 | +# Process: Raster Calculator (Raster Calculator) (sa) |
| 143 | +while(True): |
| 144 | + try: |
| 145 | + reclas_raste = "reclas_raste" |
| 146 | + Raster_Calculator = reclas_raste |
| 147 | + user_input = input('Input the weight for the slope, landuse, and Distance to stream(e.g. 1.2 0.5 0.1):') |
| 148 | + weight = user_input.split() |
| 149 | + reclas_raste = Reclass_Slop1 **float(weight[0]) + Reclass_Land1 **float(weight[1]) + Rescale_Dist1 **float(weight[2]) |
| 150 | + reclas_raste.save(Raster_Calculator) |
| 151 | + print('Completed!') |
| 152 | + break |
| 153 | + except ValueError: |
| 154 | + print('Invalid Input! Try Again.') |
| 155 | + |
| 156 | + |
| 157 | +# In[ ]: |
| 158 | + |
| 159 | + |
| 160 | + |
| 161 | + |
0 commit comments