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)
        # 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.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__
RuntimeError: ERROR 999999: Error executing function.

Try replacing:

arcpy.env.workspace = "H:\GIS Project\Bulk Density\In Rasters"


arcpy.env.workspace = r"H:\GIS Project\Bulk Density\In Rasters"


arcpy.env.workspace = "H:\\GIS Project\\Bulk Density\\In Rasters"


arcpy.env.workspace = "H:/GIS Project/Bulk Density/In Rasters"

The backslash is a special character to Python and so strings for pathnames that include it need to either be treated as raw strings, have the backslashes doubled, or have the backslashes replaced by forward slashes.

When creating your SpatialReference object for GDA 1994, you could use:

outCS = arcpy.SpatialReference('Geocentric Datum of Australia 1994')

because it is most likely outCS = arcpy.SpatialReference('GDA 1994') that triggers that ERROR 999999.

  • 1
    Forgot about the backslashes, thanks for the help. I also made the change in arcpy.SpatialReference('GDA 1994') to arcpy.SpatialReference(3577). This solved that generic error. I am receiving another error now. I will look into it and try to fix it myself. If not (as per stacks etiquette), I will post another question. – Douglas Jun 25 '18 at 1:24

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.