3

I'm still fairly new to GIS and Python but I have a line feature class with one attribute called "View Side" which indicates which direction the buffer should be. I want to create a Python script to iterate through the attribute table and buffer according to the View Side. I have the following code so far, but the end results (the buffers) contain no attributes and I want all the attributes from the original line feature class to be preserved.

buffercursor = arcpy.SearchCursor(fc_albers)
for rows in buffercursor:
    if rows.getValue("View_Side") == "L":
        side = "LEFT"
    elif rows.getValue("Observation_side") == "R":
        side = "RIGHT"
arcpy.Buffer_analysis(rows.Shape, fc_buffers2, 250, side, "FLAT", "NONE")
arcpy.Append_management (fc_buffers2, target, 'NO_TEST', '', '')

Why am I doing this? This is a type of walk and view survey. I want to be able to append things to a "master file" down the line. The goal here is everytime I receive a shapefile, I could just plug it in and it'll create these buffers. I could always just select all that are L/R and buffer those and combine them, but this isn't what I'm looking for.

  • 3
    Note, this doesn't answer your question, but you are using an outdated search cursor. You'll have better results with the search cursor in the da module. desktop.arcgis.com/en/arcmap/10.3/analyze/arcpy-data-access/… – Fezter Dec 20 '16 at 3:25
  • 2
    Also you should indent elif statement to be with the same level with if statement, and side = "LEFT" and side = "RIGHT" should be also indented one level. – ahmadhanb Dec 20 '16 at 3:58
1

The side parameter used by the Buffer tool will correspond to the last result of the if/elif check. So all features will be buffered using this same side value.

Buffer runs only once, with one side parameter, you can't have it choose a different side for each feature.

Using cursors is not appropriate in this case, I would select all features with "View_Side" == "L" (using Make Feature Layer), buffer them on the left side, then repeat the operation for features with "Observation_side" == "R" and a right side buffer, then merge both buffers. You can save both intermediate buffers in_memory if you want to avoid intermediate data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.