I am trying to batch reproject multiple raster files using arcpy.
Here is the code I have so far:
# Import system modules import arcpy import os # Set environment settings arcpy.env.workspace = "H:\GIS Project\Bulk Density\In Rasters" #The file where your files are arcpy.env.overwriteOutput = True outWorkspace = "H:\GIS Project\Bulk Density\Reprojected BDW" #where you want the new rasters to go arcpy.env.parallelProcessingFactor = "50" rasters = arcpy.ListRasters() #Begin loop for inrl in rasters: # Determine if the input has a defined coordinate system, can't project it if it does not dsc = arcpy.Describe(inrl) if dsc.spatialReference.Name == "Unknown": print ('skipped this raster file due to undefined coordinate system: ' + inrl) else: # Determine the new output feature class path and name outrl = os.path.join(outWorkspace, inrl) # Set output coordinate system outCS = arcpy.SpatialReference('GDA 1994') # run project tool arcpy.AddMessage("Reprojecting" + inrl) arcpy.Project_management(inrl, outrl, outCS) # check messages print(arcpy.GetMessages()) print(arcpy.AddMessage("Reprojection complete")) print "Script run ok"
However, when I attempt to debug this code I get an error in mixins.py with this part of the code highlighted:
and the following generic error:
RuntimeError: ERROR 999999: Error executing function
Now I think it has something to do with the arcpy.ListRasters() function as if I run it with arcpy.ListFeatureClasses() the code works, but the created list is empty. But that is as far as I got with troubleshooting this code.
Here is the traceback message
Traceback (most recent call last): File "C:\Python27\ArcGISx6410.3\lib\bdb.py", line 400, in run exec cmd in globals, locals File "H:\GIS Project\Python Script\Reprojection.py", line 17, in <module> import arcpy File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\arcobjects\mixins.py", line 949, in __init__ self._arc_object.createFromFile(item) RuntimeError: ERROR 999999: Error executing function.