Creating several buffers in a loop fails silently

4391
2
03-06-2015 05:35 AM
MichalWysokinski
New Contributor II

I'm experiencing a very weird behaviour when I try to create either several single or multiple buffers. I have a python script which conducts geoprocessing (creating buffers is one of the first steps) on a series (about 100) of feature classes (consisting of a single point) in a loop.

My problem is that when I run this script always up to 50-70% of buffers operations fail. After the script is complete and I run it again I get a similar behavior but some of the data, for which the calculations previously failed, is calculated correctly. If I run it enough number of times all calculations will complete succesfully.

One interesting thing is that if I try to recalculate buffers in the same process (after failing I immediately retry) it will infinitely fail. I need to finish one process and start another one in order to have a chance that another try will succeed.

Another interesting and most painful thing is that the operation itself does not fail and does not give any errors. Both Buffer_analysis and MultipleRingBuffer_analysis finish without errors, but the output layer is not created or is empty.

In each iteration I set a different workspace and scratchworkspace (which is a file gdb), so it is not a problem with temp files being overwritten (unless there are some temp files created behind the scene). I also have access to the files (both for reading and writing) at all times. Each time I set several env parameters (scratchWorkspace, workspace, snapRaster, cellSize, overwriteOutput, addOutputsToMap) and save output to different catalogs.

I also don't do anything fancy in the code, I create buffers using either:

arcpy.MultipleRingBuffer_analysis(r"path_to_fc", r"output_path_for_shp", [2, 10.5, 18.3], 'Kilometers', 'fieldname')

At first I thought that maybe MultipleRingBuffer_analysis, which is just a python script, does something under the hood, so I reimplemented it as a loop creating single buffers and later unify and dissolve them. This is the part that fails:

for dist in [2, 10.5, 18.3]:

    arcpy.Buffer_analysis(r"path_to_fc.shp", r"output_path_{}.shp".format(dist), "{} kilometers".format(dist), "FULL", "ROUND")

My configuration is following:

- Win 7 64-bit

- XEON E5649 6 cores

- 8 GB RAM

- > 100 GB disk space

0 Kudos
2 Replies
TomSellsted
MVP Regular Contributor

Michal,

Had you considered using a cursor and maybe buffering the point geometry to create your buffers?  Something like:

import arcpy


ofc ="path_to_output_fc"
outcur = arcpy.InsertCursor(ofc)
fc = "path_input_point_fc"
cursor = arcpy.SearchCursor(fc)
for row in cursor:
    pt = row.shape
    ptgeo = arcpy.PointGeometry(pt)
    ptbuff1 = ptgeo.buffer(distance1)
    orow = outcur.newRow()
    orow.setValue("shape",ptbuff1)
    outcur.insertRow(orow)
    ptbuff2 = ptgeo.buffer(distance2)
    orow = outcur.newRow()
    orow.setValue("shape",ptbuff2)
    outcur.insertRow(orow)
    ptbuff3 = ptgeo.buffer(distance3)
    orow = outcur.newRow()
    orow.setValue("shape",ptbuff3)
    outcur.insertRow(orow)


del outcur, orow, row, cursor

Regards,

Tom

0 Kudos
DarrenWiens2
MVP Honored Contributor

If you post your entire script, we may have a better chance of diagnosing the problem.

0 Kudos