Hello I have a road shapefile with an attribute named 'Type' which has different values ('Highway', 'Main Road' etc.).
I want to create different buffers based on these values e. g. buffer all objects which are "Type = 'Highways'" by 5 meters, all objects which are "Type = 'Main Roads'" by 3 meters.
Here is my code so far:
roads = r'C:\Users\roads.shp' arcpy.MakeFeatureLayer_management(roads, 'roads') with arcpy.da.SearchCursor(roads, ['Type']) as cursor: for row in cursor: if row == 'Highway': arcpy.Buffer_analysis(roads, r'C:\Users\buffer_highway', '5 Meters', "FULL", "ROUND", "LIST") elif row == 'Main Road': arcpy.Buffer_analysis(roads, r'C:\Users\buffer_main_road', '3 Meters', "FULL", "ROUND", "LIST")
If I run it, hundreds of buffers are created (the buffer is executed for the whole shapeifle evertytime one of the cursor meets the condition of the if-statement).
I also tried this to buffer each value separately:
if arcpy.SelectData_management(roads, "Type = 'Highway'"): arcpy.Buffer_analysis(roads, r'C:\Users\buffer_highway', "5 Meters" , "FULL") else: pass
But I get this Error:
ExecuteError: Failed to execute. Parameters are not valid. ERROR 000840: The value is not a Data Element. ERROR 000840: The value is not a Composite Layer. Failed to execute (SelectData).
Has anyone a suggestion?