I am having trouble with a file path or the format of the destination I believe. I am very new to Python and have pieced this together with a lot of questions without a strong understanding of ArcGIS yet.
# Imports
import arcpy
# Workspace
trail_data = r"C:\PythonPro\Final\Trail"
county_data = r"C:\PythonPro\Final\Counties\Oregon_Counties.shp"
# Get a list of unique county names
counties = []
with arcpy.da.SearchCursor(county_data, "County_Name") as cursor:
for row in cursor:
if row[0] not in counties:
counties.append(row[0])
# Print the list of counties and ask the user to choose one
print("Choose a county: ")
for i, county in enumerate(counties):
print(f"{i+1}. {county}")
selection = int(input("> ")) - 1
selected_county = counties[selection]
print("Measuring...")
# Use the selected county to clip the trail data
clip_output = "C:/data/clipped_trails.shp"
where_clause = f"County_Name = '{selected_county}'"
arcpy.Clip_analysis(trail_data, county_data, clip_output, where_clause)
# Calculate the total distance of bike trails in the clipped data
total_distance = 0
with arcpy.da.SearchCursor(clip_output, "SHAPE@LENGTH") as cursor:
for row in cursor:
total_distance += row[0]
# Display the total distance to the user
print(f"The total distance of bike trails in {selected_county} is {total_distance:.2f} meters.")
The error code I am getting is: RuntimeError: Cannot find field 'County_Name'
I have tried to change the source and the configuration of the files on my PC. I suspect that the problem is something simple that I am missing, but I am banging my head against a wall and can't see it clearly. Any help is appreciated. Thanks.
Chris