0

I'm trying to automate my work using ArcPy in PyCharm on Windows. However, when I run the following (abridged) loop, it exits at random points: sometimes at the 4th iteration, sometimes at the 31st, sometimes it manages to get to 100 but never close to the 90.000 iterations it's supposed to!

The error is:

Process finished with exit code -1073741819 (0xC0000005)

import arcpy
arcpy.CheckOutExtension("Spatial")
arcpy.env.overwriteOutput = True
input_path =  "D:/.../05_reprojected"
current_path = "C:/.../Arcpy-test"

for filename in os.listdir(input_path):
    glacierID = glacierLocation[27:35]+"_"+glacierLocation[36:41]
    bedrockRaster = Raster(glacierLocation)
    filledBedrockRaster = Fill(bedrockRaster)
    fill_save = current_path+"/filled_"+glacierID+".tif"
    filledBedrockRaster.save(fill_save)
    sinks = Con(fill_save > bedrockRaster, 1)
    regionGrp = RegionGroup(sinks)
    # sometimes it breaks here, and sometimes it doesn't
    region_save = current_path+"/regionGrp_"+glacierID+".tif"
    regionGrp.save(region_save)
    ...
    # and the loop continues

I know from googling that this has something to do with Windows access violation errors. The regionGroup(sinks)output in the terminal is:

Starting region group
Connecting regions
Compacting labels
# and here it breaks sometimes with the above mentioned error

Where would this access violation take place?

I store every output in a separate folder for every iteration. If RegionGroupcreates an own tmp-folder, I don't know how to find it and check for issues.

I have looked at many questions on GIS Stack Exchange. There is an ArcGIS (Desktop, Engine) Background Geoprocessing 64-bit Arcpy Exit and Shutdown Patch mentioned at ArcPy 64bit giving 0xC0000005 error with PyCharm, but it is not for ArcGIS Desktop 10.7, which seems to indicate that it should be fixed in this version (but is not, apparently). Other questions are related to PyQGIS or other workflows that do not apply to mine.

EDIT: I've tried to run the script via the ArcGIS python directly in the console and but the error was the same. So it does not seem to be connected to PyCharm.

Florian Mlehliv
  • 759
  • 5
  • 13
  • 2
    You could try converting to numpy Array (rastertonumpyarray) then try something like this then convert back to raster – BERA Jan 23 '20 at 07:41
  • This is the same error as seen at https://gis.stackexchange.com/q/126250/115 (which showed up in the Related questions in the right hand panel. – PolyGeo Jan 23 '20 at 07:46
  • It seems to be quite a common error from both ArcPy and PyQGIS, and often associated with PyCharm - see https://gis.stackexchange.com/search?q=0xC0000005 – PolyGeo Jan 23 '20 at 07:49
  • Instead of creating file & folder paths by string concatenation, use os.path.join. For example region_save = os.path.join(current_path, "regionGrp_{}.tif".format(glacierID). – Bjorn Jan 23 '20 at 17:17

0 Answers0