Search code examples
pythonbuffergisarcpy

Arcpy - Creating a Buffer, then Dissolving in a single script


So I am attempting to write a script that has a number of user defined variables. I've gotten to the final step and can't seem to get it to dissolve things properly.

Purpose: The script should let me define a shapefile/layer file, a distance for the buffer to work with, create the buffer then dissolve it (This is where it fails) and save.

Here is what I have so far.

import arcpy
from arcpy import env
env.workspace = "C:\Users\...\Conroe Cut"
fc = raw_input (' What file is being Buffered' + " ")
distance = raw_input (' Buffer Size' + " ")
finalfile = raw_input (' Name of Final File' + " ")
unique_name = arcpy.CreateUniqueName("Results\\"+finalfile)
arcpy.Buffer_analysis(fc, unique_name, distance)
arcpy.Dissolve_management(unique_name, "SINGLE_PART", "DISSOLVE_LINES")
print "Finished with Analysis"

Solution

  • You can perform the buffer and dissolve in one line using arcpy.Buffer_analysis--make sure to specify the "ALL" parameter, which performs the dissolve. This should significantly simplify and clean your script.

    enter image description here


    import arcpy
    
    infc = r'C:\path\to\input\shapefile.shp'
    outfc = r'C:\path\to\output\shapefile_buffered_dissolved.shp'
    bufferDistance = 20
    
    arcpy.Buffer_analysis(infc, outfc, bufferDistance, "", "", "ALL")