-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTrackOffseteModel.py
More file actions
239 lines (186 loc) · 6.73 KB
/
Copy pathTrackOffseteModel.py
File metadata and controls
239 lines (186 loc) · 6.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#-------------------------------------------------------------------------------
# Name: TrackOffseteModel.py
# Purpose: Purpose: This is the track offset model as described in Robert
# Koester's "Lost Person Behavior: A Search and Rescue Guide on Where to Look
# - for Land, Air and Water", dbs Publications, Charlottesville, VA.
# Usage: Clip distance, multiple feature classes
#
# Author: Don Ferguson
#
# Created: 2/15/2013
# Copyright: (c) Don Ferguson 2013
# Licence:
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# The GNU General Public License can be found at
# <http://www.gnu.org/licenses/>.
#-------------------------------------------------------------------------------
# Import arcpy module
import arcpy, sys, arcgisscripting
from arcpy import env
gp = arcgisscripting.create()
mxd = arcpy.mapping.MapDocument("CURRENT")
df=arcpy.mapping.ListDataFrames(mxd,"*")[0]
# Overwrite pre-existing files
env.overwriteOutput = "True"
# Script arguments
##workspc = arcpy.GetParameterAsText(0)
##env.workspace = workspc
### Setting the Geoprocessing workspace
##gp.Workspace = workspc
SubNum = arcpy.GetParameterAsText(0) # Get the subject number
if SubNum == '#' or not SubNum:
SubNum = "1" # provide a default value if unspecified
ippType = arcpy.GetParameterAsText(1) # Determine to use PLS or LKP
TheoDist = arcpy.GetParameterAsText(2)
if TheoDist == '#' or not TheoDist:
TheoDist = "0" # provide a default value if unspecified
bufferUnit = arcpy.GetParameterAsText(3) # Desired units
if bufferUnit == '#' or not bufferUnit:
bufferUnit = "miles" # provide a default value if unspecified
OffDists = arcpy.GetParameterAsText(4) # Optional - User entered distancesDetermine to use PLS or LKP
OutName = arcpy.GetParameterAsText(5)
Dist = OffDists.split(',')
Distances=map(int,Dist)
Distances.sort()
#File Names:
IPP = "Planning Point"
IPP_dist = "IPPTheoDistance"
Trails = "Trails"
Roads = "Roads"
pStreams ="Streams"
Electric ="PowerLines"
Roads_Clipped = "Roads_Clipped"
Trails_Clipped = "Trails_Clipped"
pStreams_Clipped = "Streams_Clipped"
Electric_Clipped = "Electric_Clipped"
LineTrack = "LinearTracks"
TrackBuffer = "TrackBuffer"
SubNum = int(SubNum)
if bufferUnit =='kilometers':
mult = 1.6093472
else:
mult = 1.0
TheoSearch = mult * float(TheoDist)
theDist = "{0} {1}".format(TheoSearch, bufferUnit)
#Clip features to max distance
try:
arcpy.Delete_management(IPP_dist)
except:
pass
# Buffer areas of impact around major roads
where1 = '"Subject_Number" = ' + str(SubNum)
where2 = ' AND "IPPType" = ' + "'" + ippType + "'"
where = where1 + where2
arcpy.SelectLayerByAttribute_management(IPP, "NEW_SELECTION", where)
arcpy.AddMessage("Buffer IPP around the " + ippType )
arcpy.Buffer_analysis(IPP, IPP_dist, theDist)
IPPDist_Layer=arcpy.mapping.Layer(IPP_dist)
arcpy.mapping.AddLayer(df,IPPDist_Layer,"BOTTOM")
#Set extent
desc = arcpy.Describe(IPP_dist)
extent = desc.extent
arcpy.env.extent = IPP_dist
fieldName1 = "TYPE"
#Trails
expression2 = '"TRAIL"'
fcname = Trails
fcClip = Trails_Clipped
fcNoMess ="No Trails"
fcProcessMess = "Clip Trails"
if gp.GetCount_management(fcname) == 0:
arcpy.AddMessage(fcNoMess)
else:
arcpy.AddMessage(fcProcessMess)
arcpy.Clip_analysis(fcname, IPP_dist, fcClip, "")
arcpy.AddField_management(fcClip, fieldName1, "TEXT", "", "", "10")
arcpy.CalculateField_management(fcClip, fieldName1, expression2)
#Roads
expression2 = '"ROAD"'
fcname = Roads
fcClip = Roads_Clipped
fcNoMess ="No Roads"
fcProcessMess = "Clip Roads"
if gp.GetCount_management(fcname) == 0:
arcpy.AddMessage(fcNoMess)
else:
arcpy.AddMessage(fcProcessMess)
arcpy.Clip_analysis(fcname, IPP_dist, fcClip, "")
arcpy.AddField_management(fcClip, fieldName1, "TEXT", "", "", "10")
arcpy.CalculateField_management(fcClip, fieldName1, expression2)
#Streams
expression2 = '"DRAINAGE"'
fcname = pStreams
fcClip = pStreams_Clipped
fcNoMess ="No Drainages"
fcProcessMess = "Clip Drainages"
if gp.GetCount_management(fcname) == 0:
arcpy.AddMessage(fcNoMess)
else:
arcpy.AddMessage(fcProcessMess)
arcpy.Clip_analysis(fcname, IPP_dist, fcClip, "")
arcpy.AddField_management(fcClip, fieldName1, "TEXT", "", "", "10")
arcpy.CalculateField_management(fcClip, fieldName1, expression2)
#Utility Right of Way
expression2 = '"UTILITY"'
fcname = Electric
fcClip = Electric_Clipped
fcNoMess ="No Utility ROWs"
fcProcessMess = "Clip Utility ROWs"
if gp.GetCount_management(fcname) == 0:
arcpy.AddMessage(fcNoMess)
else:
arcpy.AddMessage(fcProcessMess)
arcpy.Clip_analysis(fcname, IPP_dist, fcClip, "")
arcpy.AddField_management(fcClip, fieldName1, "TEXT", "", "", "10")
arcpy.CalculateField_management(fcClip, fieldName1, expression2)
arcpy.Delete_management(IPP_dist)
# Create FieldMappings object to manage merge output fields
fms = arcpy.FieldMappings()
# Add all fields from both oldStreets and newStreets
fms.addTable(Roads_Clipped)
fms.addTable(Trails_Clipped)
fms.addTable(pStreams_Clipped)
fms.addTable(Electric_Clipped)
for field in fms.fields:
if field.name not in ["TYPE"]:
fms.removeFieldMap(fms.findFieldMapIndex(field.name))
# Use Merge tool to move features into single dataset
arcpy.Merge_management([Roads_Clipped, Trails_Clipped, pStreams_Clipped, Electric_Clipped], LineTrack,fms)
arcpy.Delete_management(Roads_Clipped)
arcpy.Delete_management(Trails_Clipped)
arcpy.Delete_management(pStreams_Clipped)
arcpy.Delete_management(Electric_Clipped)
pDist=[]
for x in Distances:
pDist.append(round(x * mult,2))
arcpy.AddMessage(pDist)
##try:
arcpy.MultipleRingBuffer_analysis(LineTrack, TrackBuffer, pDist, "Meters", "TRACKOFFSET", "ALL", "FULL")
##
##except:
## TrackBuf = TrackBuffer
## arcpy.AddMessage("Loop through the distances")
## for x in Distances:
## arcpy.AddMessage(str(x))
## TrackBuffer = TrackBuf + str(x)
## dist = str(x) + ' Meters'
## arcpy.Buffer_analysis(LineTrack, TrackBuffer, dist, "", "", "ALL", "")
arcpy.Delete_management(LineTrack)
#Try to erase water polygon if user as Advanced license
try:
arcpy.Erase_analysis(TrackBuffer,"Water_Polygon",OutName)
except:
arcpy.Copy_management(TrackBuffer,OutName)
arcpy.Delete_management(TrackBuffer)
# create a new layer
arcpy.AddMessage('Insert Track Buffer')
insertLayer = arcpy.mapping.Layer(OutName)