Euclidean Distance - Error 010240

2727
3
06-05-2012 03:39 AM
SteveDugdale
New Contributor
Hi,
I'm trying to run the Euclidean Distance tool from a python script (my first attempt at python) and keep getting the message below:

Traceback (most recent call last):
  File "E:/VTA/Models/Calc_Distance_Household_LOOP.py", line 44, in <module>
    Dist_HH0.save("E:/VTA/TEST/output/Distance_from_Household/Script_First_10_HH")
RuntimeError: ERROR 010240: Could not save raster dataset to E:\VTA\TEST\output\Distance_from_Household\Script_First_10_HH with output format GRID.

I'm assuming that the raster will be called Dist_HH0 and will be saved in the folder Script_First_10_HH following the filepath in the error message.  How do I overcome this error please?

Ultimately, I want to run the euclidean distance tool on numerous points in a shapefile and create a seperate raster for each point using a loop.  How do I change the raster output name for each iteration of the loop?

Any help with resolving this would be much appreciated.

Thanks
Steve
0 Kudos
3 Replies
MarcinGasior
Occasional Contributor III
In your code you try to save a raster with name "Script_First_10_HH" which exceed allowed name length (13 characters) of GRID raster.

The script which iterates through several shapefiles and for each crates new raster may look like that:
        import arcpy, sys, traceback, os
        arcpy.CheckOutExtension("Spatial")
        #set pathes
        arcpy.env.workspace = r"C:\tmp\Shp"
        outRasterDir = r"E:\VTA\TEST\output\Distance_from_Household\Script_First_10_HH"
        
        #your variables
        maxDistance = 100000
        cellSize = 1000

        shpList = arcpy.ListFeatureClasses("P*")
        for shp in shpList:
            #build the name of output raster: directory + shapefilename w/o extension + some text
            outRaster = os.path.join(outRasterDir, shp[:-4] + "_EucD")

            #run the tool (if you want use defaults instead of maxDistance and cellSize, place "" instead of variable name)
            outEucDist = arcpy.sa.EucDistance(shp, maxDistance, cellSize)
            outEucDist.save(outRaster)
0 Kudos
SteveDugdale
New Contributor
Hi Marcin ,
Thanks for your help. I eventually tracked down the cause of the Error 010240.  The extent of the output file was larger than the input file (as the "boundary" of the euclidean distance zone went beyond the extent of the input file for points near the edge).  This would also happen when using the buffer tools or anything which created a zone around a feature.  Manually setting the extent as below resolved that error.  I didn't find anything about this elsewhere on the web so hopefully others who get Error 010240 will find this useful.

# set extent - Parameter order is Left, Bottom, Right, Top; Values required = extent of input increased by size of euclidean distance "zone" in all directions.
arcpy.env.extent = "355503.281300 9202524.000000 378630.750000 9225369.000000"

Unfortunately, my output did not give the expected results.  If a tool is used manually from ArcToolbox it only processes selected records.  I had expected the same to happen using Python but it didn't.  So all my output files were identical (i.e. euclidean distance to NEAREST feature rather than euclidean distance to a single feature as selected in the loop).  I tried two methods of attempting to process a single record at a time.  The first based on your suggestion (below)

count = 0

for row in rows:
     count = count + 1
     # print "ITERATION COUNT = " + count
     # print "FID = " + row.FID
    
     print count
     print row.FID

     #build the name of output raster: directory + filename HHxxxx_EucD where xxxx is the value of field FID in the input shapefile
     outRaster = os.path.join(outRasterDir, "HH" + str(row.FID) + "_EucD1k")

     # Temporary line below to display outraster filename and path (for debugging)
     print outRaster
           
     # Execute EucDistance
     # MAY NEED TO REMOVE PARAMETER outDirectionRaster FROM LINE BELOW AS DIRECTION RASTER IS NOT REQUIRED AND IS AN OPTIONAL PARAMETER
     # outEucDist = EucDistance(inSourceData, maxDistance, cellSize, outDirectionRaster)
     outEucDist = EucDistance(inSourceData, maxDistance, cellSize)
    

     # Save the output
     outEucDist.save(outRaster)


and the second came from another thread as mentioned in comment in code below:

# Need to process only the selected record - See http://forums.arcgis.com/threads/8428-Setting-a-Single-Record-to-Selected-with-Python
# for source of baseline code that follows

lookupDict = {}
searchRows = gp.searchcursor(inSourceData)
searchRow = searchRows.next()
while searchRow:
   lookupDict[searchRow.FID] = [searchRow.FID]
   count = count + 1
     # print "ITERATION COUNT = " + count
     # print "FID = " + row.FID
    
   print count
   print searchRow.FID

     #build the name of output raster: directory + filename HHxxxx_EucD where xxxx is the value of field FID in the input shapefile
   outRaster = os.path.join(outRasterDir, "HH" + str(searchRow.FID) + "_EucD1k")

     # Temporary line below to display outraster filename and path (for debugging)
   print outRaster
           
     # Execute EucDistance
     # MAY NEED TO REMOVE PARAMETER outDirectionRaster FROM LINE BELOW AS DIRECTION RASTER IS NOT REQUIRED AND IS AN OPTIONAL PARAMETER
     # outEucDist = EucDistance(inSourceData, maxDistance, cellSize, outDirectionRaster)
   outEucDist = EucDistance(inSourceData, maxDistance, cellSize)
    

     # Save the output
   outEucDist.save(outRaster)

Any ideas on how to loop through a shapefile one record at a time, use the selected single feature as the input file, generate and save an output raster for the euclidean distance from that single feature and then move onto the next feature etc.?

I will start a new post for this query as it no longer relates to Error 012420 but added here so that you will see it.

Many thanks

Steve
0 Kudos
curtvprice
MVP Esteemed Contributor
  If a tool is used manually from ArcToolbox it only processes selected records. I had expected the same to happen using Python but it didn't.


This is because you chose a layer (not a dataset) off the pick list, to pass to your tool when you used it "manually".

Datasets don't have "selected sets", only layers do.
0 Kudos