This script, up until now, has successfully batch reprojected datasets of rasters to designated projections. The results of running my script on my new dataset is that the script successfully reproject the first 6 out of 200 and then finishes without an error. How is the best way to troubleshoot this issue?

import arcpy, sys, os

InFolder = r"C:\TX_DataSets\Harris 1944\Copy"
OutFolder = r"C:\TX_DataSets\Harris 1944\Reprojected"
OutSR = arcpy.SpatialReference(26915) # UTM 15

arcpy.env.workspace = InFolder
print "Starting reprojecting script"

rasterList = arcpy.ListRasters("*","tif")
for Ras in rasterList :
     inRaster = os.path.join(InFolder, Ras)
     spatial_ref = arcpy.Describe(inRaster).SpatialReference
     if spatial_ref.type <> "Unknown":
          outFileName = "{}.{}".format(os.path.splitext(Ras)[0], "tif") # Remove .sid and add .tif to Ras filename
          outRaster = os.path.join(OutFolder, outFileName) # Path and Filename of output raster (.tif)
          arcpy.ProjectRaster_management (inRaster, outRaster, OutSR)
          print "reprojecting " + str(outRaster)
print "Finished Reprojecting"
  • 1
    Try a new "batch" where your 7th becomes your first and only. – PolyGeo Oct 1 '18 at 19:47
  • 1
    Just print the list in full and count print rasterList or just print the seventh raster name using its index number print rasterList[6]. – PolyGeo Oct 1 '18 at 21:21
  • 1
    I think you should revise your question to focus on what may be astray with the processing of that one raster. What happens when you just use the Project Raster tool on it rather than ArcPy code? – PolyGeo Oct 1 '18 at 21:46
  • 1
    An incidental observation - I would strongly recommend you avoid paths/file names with spaces as in "Harris 1944", I would have used "Harris_1944". – Hornbydd Oct 2 '18 at 10:57
  • 2
    So, you should use your original code, and put in an else: to catch the unknowns and define a coordinate system for the ones that are unknown. Using DefineProjection_management (in_dataset, coor_system). Then move onto the other code that you have. – enolan Oct 2 '18 at 18:24

Sounds very much like your rasters are corrupted in some way. You have come across an issue that is typical of a geoprocessing tool, did it actually run? You have provided all the right parameters so the tool can run but something went wrong, so how do you test if the output is correct?

All geoprocessing tools return a result object, which your code is not making use of. A mistake I often see in peoples' codes is to treat the result object as the output, but you need to query the object to see if it is OK and typically return the output.

So I would adjust your code as below:

resObj = arcpy.ProjectRaster_management (inRaster, outRaster, OutSR)
if resObj.status == 4:
    print("Project ran OK!")
    print("Warning Project tool did not succeed!")
    # Do something...
  • I tried adjusting my code and I either get an error that says outRaster is undefined or it runs without printing anything. I must have messed something while adjusting. Can I add the 'resObj' to the beginning of the existing 'arcpy.ProjectRaster_management (inRaster, outRaster, OutSR)' or make it its own new line? – Anthony Stokes Oct 2 '18 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.