Skip to content

Commit

Permalink
Finalize Fragmenter Script
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler1218hatch committed Mar 25, 2021
1 parent e52ca1d commit 74f5203
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 10 deletions.
26 changes: 17 additions & 9 deletions Fragmenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,23 @@ def main(valley_bottom, streams, fragmenters, out_folder):
arcpy.env.overwriteOutput = True
arcpy.env.workspace = out_folder

# Convert Fragmenters to Python List
fragmenters = fragmenters.split(';')

# Copy Valley Bottom
valley_copy = arcpy.CopyFeatures_management(valley_bottom, "Valley_Copy.shp")

# Union all fragmenters
fragmenters_union = arcpy.Union_analysis(fragmenters, "All_Fragmenters.shp")
# Merge all fragmenters
fragmenters_merge = arcpy.Merge_management(fragmenters, "All_Fragmenters.shp")

# Convert everything to a cut polygon
mesh = arcpy.FeatureToPolygon_management([valley_copy, fragmenters_union], 'Polygon_Mesh.shp')
mesh = arcpy.FeatureToPolygon_management([valley_copy, fragmenters_merge], 'Polygon_Mesh.shp')

# Clip that polygon with the orginal VB
new_valley = arcpy.Clip_analysis(mesh, valley_copy, "Prelim_Frag_Valley.shp")
new_valley = arcpy.Clip_analysis(mesh, valley_copy, "Prelim_Clip.shp")

# Add Connected field
try:
arcpy.management.DeleteField(new_valley, 'Connected')
except:
pass
arcpy.AddField_management(new_valley, 'Connected', 'SHORT')

# Select all streams where network touches, set connected to 1
Expand All @@ -46,8 +47,15 @@ def main(valley_bottom, streams, fragmenters, out_folder):

# Set remaining streams to zero
arcpy.CalculateField_management(valley_layer, "Connected", "0", "PYTHON_9.3")
arcpy.SelectLayerByAttribute_management(valley_layer, "CLEAR SELECTION", "")
arcpy.CopyFeatures_management(valley_layer, "Valley_Final.shp")
arcpy.SelectLayerByAttribute_management(valley_layer, "CLEAR_SELECTION", "")
arcpy.CopyFeatures_management(valley_layer, "PrelimFragVB.shp")

# Delete Temperary Shapefiles
for shape in [valley_copy, fragmenters_merge, mesh, new_valley]:
try:
arcpy.management.Delete(shape)
except:
pass


if __name__ == '__main__':
Expand Down
67 changes: 66 additions & 1 deletion RCAT.pyt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Promoter
import segmentNetwork
import LANDFIRE_RCAT_fields
import Layer_Package_Generator
import Fragmenter


class Toolbox(object):
Expand All @@ -24,7 +25,7 @@ class Toolbox(object):
# List of tool classes associated with this toolbox
self.tools = [VBETBuilder, VBETtool, NHDNetworkBuildertool, RVDtool, RCATBuilder, RCAtool,
BankfullChannelTool, ConfinementTool, Promotertool, SegmentNetworkTool,
LANDFIREfields, Layer_Package_Tool]
LANDFIREfields, Layer_Package_Tool, FragmentValleyBottom]


class VBETBuilder(object):
Expand Down Expand Up @@ -1320,3 +1321,67 @@ class Layer_Package_Tool(object):
p[1].valueAsText,
p[2].valueAsText)
return

class FragmentValleyBottom(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "Fragment Valley Bottom"
self.category = "Supporting Tools"
self.description = "Fragments the valley bottom by any input polyline features (roads, levees, etc.)"
self.canRunInBackground = False

def getParameterInfo(self):
"""Define parameter definitions"""
param0 = arcpy.Parameter(
displayName="Unfragmented Valley Bottom",
name="un_vb",
datatype="DEFeatureClass",
parameterType="Required",
direction="Input")

param1 = arcpy.Parameter(
displayName="Stream Network",
name="streams",
datatype="DEFeatureClass",
parameterType="Required",
direction="Input")

param2 = arcpy.Parameter(
displayName="Fragmenting Polylines",
name="fragmenters",
datatype="DEFeatureClass",
parameterType="Required",
direction="Input",
multiValue = True)

param3 = arcpy.Parameter(
displayName="Out Folder",
name="out",
datatype="DEFolder",
parameterType="Required",
direction="Input")

return [param0, param1, param2, param3]

def isLicensed(self):
"""Set whether tool is licensed to execute."""
return True

def updateParameters(self, parameters):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
return

def updateMessages(self, parameters):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return

def execute(self, p, messages):
"""The source code of the tool."""
Fragmenter.main(p[0].valueAsText,
p[1].valueAsText,
p[2].valueAsText,
p[3].valueAsText)
return

0 comments on commit 74f5203

Please sign in to comment.