Skip to content

Commit 45b2386

Browse files
authored
Script-5
1 parent 3a019f6 commit 45b2386

File tree

3 files changed

+230
-0
lines changed

3 files changed

+230
-0
lines changed

Script-5-Image.png

39.5 KB
Loading

Script-5-Model.py

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Generated by ArcGIS ModelBuilder on : 2023-03-07 19:12:13
4+
"""
5+
import arcpy
6+
from arcpy.sa import *
7+
8+
def Model(): # Model
9+
10+
# To allow overwriting outputs change overwriteOutput option to True.
11+
arcpy.env.overwriteOutput = False
12+
13+
# Model Environment settings
14+
with arcpy.EnvManager(cellSize="Elevation", extent="427738.551679547 210122.964165066 494453.949501122 234223.418565066 PROJCS["NAD_1983_StatePlane_Vermont_FIPS_4400",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-72.5],PARAMETER["Scale_Factor",0.9999642857142857],PARAMETER["Latitude_Of_Origin",42.5],UNIT["Meter",1.0]],VERTCS["Unknown VCS",VDATUM["Unknown"],PARAMETER["Vertical_Shift",0.0],PARAMETER["Direction",1.0],UNIT["Foot_US",0.3048006096012192]]", mask="Elevation",
15+
outputCoordinateSystem="PROJCS["NAD_1983_StatePlane_Vermont_FIPS_4400",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-72.5],PARAMETER["Scale_Factor",0.9999642857142857],PARAMETER["Latitude_Of_Origin",42.5],UNIT["Meter",1.0]],VERTCS["Unknown VCS",VDATUM["Unknown"],PARAMETER["Vertical_Shift",0.0],PARAMETER["Direction",1.0],UNIT["Foot_US",0.3048006096012192]]"):
16+
Streams = "Streams"
17+
Elevation = arcpy.Raster("Elevation")
18+
LandUse = arcpy.Raster("LandUse")
19+
20+
# Process: Distance Accumulation (Distance Accumulation) (sa)
21+
Distanc_Stre1 = "C:\\Users\\akunna1\\Desktop\\GEOG 592\\Lab_5\\Lab_5_Akunna\\Default.gdb\\Distanc_Stre1"
22+
Distance_Accumulation = Distanc_Stre1
23+
Out_back_direction_raster = ""
24+
Out_source_direction_raster = ""
25+
Out_source_location_raster = ""
26+
Distanc_Stre1 = arcpy.sa.DistanceAccumulation(in_source_data=Streams, in_barrier_data="", in_surface_raster="", in_cost_raster="", in_vertical_raster="", vertical_factor="BINARY 1 -30 30", in_horizontal_raster="", horizontal_factor="BINARY 1 45", out_back_direction_raster=Out_back_direction_raster, out_source_direction_raster=Out_source_direction_raster, out_source_location_raster=Out_source_location_raster, source_initial_accumulation="", source_maximum_accumulation="", source_cost_multiplier="", source_direction="", distance_method="PLANAR")
27+
Distanc_Stre1.save(Distance_Accumulation)
28+
29+
30+
# Process: Slope (Slope) (sa)
31+
Slope_Elevat1 = "C:\\Users\\akunna1\\Desktop\\GEOG 592\\Lab_5\\Lab_5_Akunna\\Default.gdb\\Slope_Elevat1"
32+
Slope = Slope_Elevat1
33+
Slope_Elevat1 = arcpy.sa.Slope(in_raster=Elevation, output_measurement="DEGREE", z_factor=0.30480060960121924, method="PLANAR", z_unit="METER")
34+
Slope_Elevat1.save(Slope)
35+
36+
37+
# Process: Reclassify (Reclassify) (sa)
38+
Reclass_Slop1 = "C:\\Users\\akunna1\\Desktop\\GEOG 592\\Lab_5\\Lab_5_Akunna\\Default.gdb\\Reclass_Slop1"
39+
Reclassify = Reclass_Slop1
40+
Reclass_Slop1 = arcpy.sa.Reclassify(in_raster=Slope_Elevat1, reclass_field="VALUE", remap="0 3 1;3 10 3;10 25 6;25 90 0", missing_values="DATA")
41+
Reclass_Slop1.save(Reclassify)
42+
43+
44+
# Process: Reclassify (2) (Reclassify) (sa)
45+
Reclass_Land1 = "C:\\Users\\akunna1\\Desktop\\GEOG 592\\Lab_5\\Lab_5_Akunna\\Default.gdb\\Reclass_Land1"
46+
Reclassify_2_ = Reclass_Land1
47+
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")
48+
Reclass_Land1.save(Reclassify_2_)
49+
50+
51+
# Process: Rescale by Function (Rescale by Function) (sa)
52+
Rescale_Dist1 = "C:\\Users\\akunna1\\Desktop\\GEOG 592\\Lab_5\\Lab_5_Akunna\\Default.gdb\\Rescale_Dist1"
53+
Rescale_by_Function = Rescale_Dist1
54+
with arcpy.EnvManager(compression="NONE", pyramid="NONE"):
55+
Rescale_Dist1 = arcpy.sa.RescaleByFunction(in_raster=Distanc_Stre1, transformation_function=[["MSSMALL", "", "", "", "", 1, 1, ""]], from_scale=1, to_scale=10)
56+
Rescale_Dist1.save(Rescale_by_Function)
57+
58+
59+
# Process: Raster Calculator (Raster Calculator) (sa)
60+
reclas_raste = "C:\\Users\\akunna1\\Desktop\\GEOG 592\\Lab_5\\Lab_5_Akunna\\default.gdb\\reclas_raste"
61+
Raster_Calculator = reclas_raste
62+
reclas_raste = (Reclass_Slop1 * 0.3) + (Reclass_Land1 * 0.3) + ( Rescale_Dist1 *0.4)
63+
reclas_raste.save(Raster_Calculator)
64+
65+
66+
if __name__ == '__main__':
67+
# Global Environment settings
68+
with arcpy.EnvManager(scratchWorkspace=r"C:\Users\akunna1\Desktop\GEOG 592\Lab_5\Lab_5_Akunna\Default.gdb", workspace=r"C:\Users\akunna1\Desktop\GEOG 592\Lab_5\Lab_5_Akunna\Default.gdb"):
69+
Model()

Script-5.py

+161
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
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

Comments
 (0)