There are many out of the box geoprocessing tools available in ArcDesktop. They range from buffers, to conversions, to network analysis, and everything in between. However, there are some tasks that one might want to complete that Esri has not been kind enough to provide an out-of-the box tool for. For tasks like that, one can utilize the ArcPy library.
For example, say you would like to split a line feature class into equal segments. There is no out-of-the-box geoprocessing tool for this task. However, with a little bit of Python skill it can be completed with just five simple lines of code. Below I have written a script that takes an existing feature class, separates it into 10 equal segments, and then creates a new feature class split into those segments.
featureinput = r’c:projectswaterway.gdbstream’
featureoutput = r’c:projectswaterway.gdbstream10′
outputcount = 10
line = arcpy.da.SearchCursor(in_fc, (“SHAPE@”,)).next()[fusion_builder_container hundred_percent=”yes” overflow=”visible”][fusion_builder_row][fusion_builder_column type=”1_1″ background_position=”left top” background_color=”” border_size=”” border_color=”” border_style=”solid” spacing=”yes” background_image=”” background_repeat=”no-repeat” padding=”” margin_top=”0px” margin_bottom=”0px” class=”” id=”” animation_type=”” animation_speed=”0.3″ animation_direction=”left” hide_on_mobile=”no” center_content=”no” min_height=”none”][0]
arcpy.CopyFeatures_management([line.segmentAlongLine(i/float(out_count), ((i+1)/float(out_count)), True) for i in range(0, out_count)], out_fc)
It’s as easy as that! The commented source code for this script is accessible in my GitHub page, which I have linked below.
https://github.com/crice937/ArcPy-Scripts/blob/master/arcpy_line.py
Chris Rice
GIS Analyst I
crice@Interdev.com[/fusion_builder_column][/fusion_builder_row][/fusion_builder_container]