Skip to content

Instantly share code, notes, and snippets.

@cindygis
Last active August 29, 2015 14:26
Show Gist options
  • Save cindygis/e319e8583d0e0ec9ccbd to your computer and use it in GitHub Desktop.
Save cindygis/e319e8583d0e0ec9ccbd to your computer and use it in GitHub Desktop.
Creates segments along a selected line feature by splitting it according to a table of measures and saving it in a new feature class.
#
# @date 04/08/2015
# @author Cindy Williams
#
# Creates segments along a selected line feature
# by splitting it according to a table of measures
# and saving it in a new feature class.
#
# For use as a standalone script.
#
import arcpy
arcpy.env.workspace = r"C:\Some\Arb\Folder\work.gdb"
selected_feature = "Line1"
selected_field = "Name"
qry = """ "{0}" = '{1}' """.format(selected_field, selected_feature)
# Get the selected geometry
line_geom = arcpy.da.SearchCursor("ftr_lines", "SHAPE@", qry).next()[0]
fields_fc = ["SHAPE@", "Description"]
cursor_ins = arcpy.da.InsertCursor("ftr_segments", fields_fc)
fields_tbl = ["Measure", "Description"]
start = 1 # Placeholder for previous row value
with arcpy.da.SearchCursor("tbl_measures", fields_tbl, qry) as cursor_sea:
for row in cursor_sea:
if start == 1:
start = 0
print("Handled first row")
else:
end = row[0]
segment_geom = line_geom.segmentAlongLine(start, end)
segment = [segment_geom, row[1]]
cursor_ins.insertRow(segment)
start = row[0]
del cursor_ins
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment