1

I have drawn a set of lines (corresponding to a network) in a shapefile. I would like to buffer them, but each line has a different buffer length, so I thought to do it with Python: for each branch, identified by a particular ID number, perform the buffer up to a certain distance that you can find in an attribute column.

To do so, I would like to use: Buffer_analysis {all_my_branches, a_new_defined_layer, an_attribute_column_inserted_in_the_shapefile}

I imported arcpy, I set as arcpy.env.workspace my shapefile, but when I ask for the list of feature classes I get the answer:

"function ListFeatureClasses at 0x1948B770"

So I guess I have no features in my shapefile. How can I therefore do to perform the buffer I want? Can it be done on a shapefile?

I am new to ArcGIS and Python.

3
  • 3
    Not sure if I understand you right, but if you want to create a buffer with a distance that is written as an attribute to the objects the buffer will surround: there is an option for this in the buffer tool: "buffer distance field". Maybe you need to post some visual data to make the task clear.
    – Papierwolf
    Feb 18, 2016 at 11:04
  • 3
    I agree with @Papierwolf that this sounds like it only needs the Buffer tool and no ArcPy code.
    – PolyGeo
    Feb 18, 2016 at 11:36
  • 3
    Please post the script that you have been using.
    – Aaron
    Feb 18, 2016 at 13:04

1 Answer 1

4

As the two commentators mentioned, you don't need arcpy for this task. In the interface of the Buffer (Analysis) tool, just select your shapefile and then specify the buffer distance field here:

buffer distance


You can however, use arcpy for this task too. Try this:

import arcpy

# Define workspace
workspace = r"C:Path\to\workspace"
arcpy.env.workspace = workspace

# Define Inputs
your_input = r"C:Path\to\shapefile\shapefile.shp"
your_output = r"C:Path\to\output\output.shp"
distance_field = "Name_of_Distance_Field_in_Input"

# Perform Buffer
arcpy.Buffer_analysis(your feature, your_output, distance_field, "FULL", "ROUND", "ALL")
6
  • 1
    Thank you for your quick answers. Yeah actually I could have also used the default buffer function, but I was trying to learn how to use python (also because I think I will have to do more complex stuff soon). So I did as you suggested me, and this what I got: my_input = r"C:\Users\tsacco\ArcGIS\GB.shp" my_output = r"C:\Users\tsacco\ArcGIS\Output.shp" distance_field = my_input["Buff_Size"] Runtime error Traceback (most recent call last): File "<string>", line 1, in <module> TypeError: string indices must be integers, not str Why did this occur? Buff_Size is a column of numbers Feb 18, 2016 at 13:44
  • @TommasoSacco Sorry, my bad, it's not necessary to reference the "Name_of_Distance_Field". Try my code again, it should work now. And for making the code complete, I also added a workspace.
    – dru87
    Feb 18, 2016 at 14:14
  • I tried also to do the other way, without declaring it, as you said, but now I get the error: "Runtime error Traceback (most recent call last): File "<string>", line 1, in <module> NameError: name 'Buff_Size' is not defined". I checked the Directory, and the one I setted corresponds to where the shapefile GB, that I load as "my_input" is, so what could be the problem? In the GB file there is an attribute called "Buff_Size" that is my input for the buffer analyisis. May it be because I have not defined the output yet (i.e. there is not Output.shp in my folder yet)? Feb 22, 2016 at 8:26
  • Is your "Buff_Size" in a seperate feature class? Then this would be the source of the error. I tested the code with a GDB and a feature class as input and it worked without any problem. The "Buff_Size" attribute need to be in "your_input" feature class. You don't need to create an output file beforehand, it will do so in the process.
    – dru87
    Feb 22, 2016 at 8:33
  • In case you still run into problems I suggest you post the code to your original question, so we can have a look at it.
    – dru87
    Feb 22, 2016 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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