Skip to content

Commit

Permalink
Initial Fragmenter Script
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler1218hatch committed Mar 25, 2021
1 parent 246af95 commit e52ca1d
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions Fragmenter.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,57 @@
#-------------------------------------------------------------------------------
# Name: Fragmenter.py
# Purpose: Fragments the Valley Bottom by any inputs
# Author: Jordan Gilbert
# Author: Tyler Hatch
#
# Created: 3/21/21
#-------------------------------------------------------------------------------

#import modules
# Import modules
import arcpy
import sys
import os


def main(valley_bottom, fragmenters, out_folder):
def main(valley_bottom, streams, fragmenters, out_folder):

# Set environment variables
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")

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

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

# Add Connected field
arcpy.AddField_management(new_valley, 'Connected', 'SHORT')

# Select all streams where network touches, set connected to 1
valley_layer = arcpy.MakeFeatureLayer_management(new_valley, "valley_layer")
arcpy.SelectLayerByLocation_management(valley_layer, 'intersect', streams)
arcpy.CalculateField_management(valley_layer, "Connected", "1", "PYTHON_9.3")

# Invert selection
arcpy.SelectLayerByAttribute_management(valley_layer, "SWITCH_SELECTION", "")

# 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")


if __name__ == '__main__':
main(sys.argv[1],
sys.argv[2],
sys.argv[3],)
sys.argv[3],
sys.argv[4])

0 comments on commit e52ca1d

Please sign in to comment.