-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
246af95
commit e52ca1d
Showing
1 changed file
with
36 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |