I have created a tool in ArcGIS based on a python script that will clip a large raster dataset into smaller tiles based on a fishnet polygon feature class. The script iterates through each feature in the fishnet and uses the selected feature to clip the raster. For some reason it keeps stopping after the 58th feature (there are 89 total). I tried using it on a different raster but with all the same parameters and it stopped after the 53rd feature. Any idea why this is happening?

Here is the pertinent code

for feat in fishnet:
    arcpy.SelectLayerByAttribute_management("fishnetlayer", "NEW_SELECTION", '"FID" = ' + str(select))
    arcpy.Clip_management(inRaster, "#", "BE_Seg_" + str(tile) + ".png", "fishnetlayer", "0", "ClippingGeometry")
    arcpy.AddMessage("Tile " + str(tile) + " successfully created")
    rastnodata = arcpy.GetRasterProperties_management("BE_Seg_" + str(tile) + ".png", "ALLNODATA")
    rastempty = rastnodata.getOutput(0)
    if rastempty == "1":
        arcpy.Delete_management("BE_Seg_" + str(tile) + ".png")
        select = select + 1
        tile = tile + 1
        select = select + 1
        tile = tile + 1
  • 1
    I think posting the code would be very helpful, or just the relevant part if it's super long. Add 4 spaces in the beginning of each line for it to be formatted correctly in your question.
    – mr.adam
    Apr 8, 2015 at 18:02
  • Code has been added.
    – Matt B
    Apr 8, 2015 at 19:21
  • 1
    Could it be a memory issue? Check what is going on in the Task Manager. When you say that the process stopped, did you get any error message? You could look at the Results window or try to log the execution progress into a text file for troubleshooting purposes. Apr 8, 2015 at 19:59
  • There was no error message. It iterated through the 58 features then ended as if there were no more features left in the feature class even though it only cycled through 58 of the 89 features. The code works exactly the way I want it to, it just doesn't iterate through all the features for some reason.
    – Matt B
    Apr 8, 2015 at 20:13
  • This script is useful also. Just FYI.
    – Barbarossa
    Apr 8, 2015 at 20:58

2 Answers 2


Ok, just a shot in the dark, but instead of

for feat in fishnet:

try looping with this:

cnt = int(arcpy.GetCount_management("fishnetlayer").getOutput(0))
for i in range(cnt):
    arcpy.SelectLayerByAttribute_management("fishnetlayer", "NEW_SELECTION", '"FID" = ' + str(i))

That should work because I believe that shapefiles always have sequential FID numbering even if a feature has been deleted (as opposed to .gdb feature classes, where a feature retains its original OBJECTID forever).

At any rate, if it's not a memory issue like @Alex Tereshenkov mentioned, it's worth inspecting your looping structure.

  • This is working quite nicely, it loops through all of the features in the fishnet layer. Thanks!
    – Matt B
    Apr 10, 2015 at 14:08
  • Glad to be able to help!
    – mr.adam
    Apr 10, 2015 at 14:35

As a work-around, you can use the Split Raster (Data Management) tool to do this. Here is a basic example, although you can adjust the parameters to include overlapping tiles, etc.

import arcpy, os

outws = r'C:\temp\split_raster'
raster = r'C:\temp\split_raster\yourRaster.tif'
fishnet = r'C:\temp\split_raster\fishnet.shp'

arcpy.SplitRaster_management (raster, outws, os.path.basename(raster).split(".")[0],
                              "POLYGON_FEATURES", "TIFF", split_polygon_feature_class = fishnet) 
  • I tried the split raster and it was giving me some really funky results. I tried a number of things to try to fix it but nothing seemed to work.
    – Matt B
    Apr 10, 2015 at 14:09
  • Thats odd, the tool is optimized to do exactly what you are after. Did you try the implementation shown here?
    – Aaron
    Apr 10, 2015 at 14:20

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.