3

I am trying to reproject multiple .tif files with the following code:

# Import system modules
import arcpy
import os

# Set environment settings
arcpy.env.workspace = r"H:\GIS Project\Bulk Density\In Rasters" #The file where your files are
arcpy.env.overwriteOutput = True
outWorkspace = r"H:\GIS Project\Bulk Density\Reprojected BDW" #where you want the new rasters to go
arcpy.env.parallelProcessingFactor = "50"
rasters = arcpy.ListRasters("*","TIF")
print rasters
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
        inCS = arcpy.SpatialReference(4326)
        outCS = arcpy.SpatialReference(3577)

        # run project tool
        arcpy.AddMessage("Reprojecting" + inrl)
        arcpy.Project_management(inrl, outrl, outCS,inCS)

        # check messages
        print(arcpy.GetMessages())

print(arcpy.AddMessage("Reprojection complete"))

print "Script run ok"

I am receiving the following error message:

  Traceback (most recent call last):
  File "C:\Python27\ArcGISx6410.3\lib\bdb.py", line 400, in run
    exec cmd in globals, locals
  File "<module1>", line 3, in <module>
    import arcpy
  File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\management.py", line 8825, in Project
    raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Dataset or Feature Class: Dataset BDW_000_005_EV_N_P_AU_NAT_C_20140801.tif does not exist or is not supported
Failed to execute (Project).

I do not understand why the function is having troubles when I specifically call for .tif files. The folder does contain .tif files as well.

FINAL EDIT: Here is my correct code:

# Import system modules
import arcpy
import os

# Set environment settings
arcpy.env.workspace = r"H:\GIS Project\Bulk Density\In Rasters" #The file where your files are
arcpy.env.overwriteOutput = True
outWorkspace = r"H:\GIS Project\Bulk Density\Reprojected BDW" #where you want the new rasters to go
arcpy.env.parallelProcessingFactor = "50"
rasters = arcpy.ListRasters("*","TIF")
print rasters
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(3577)

        # run project tool
        arcpy.AddMessage("Reprojecting" + inrl)
        arcpy.ProjectRaster_management(os.path.join(arcpy.env.workspace,inrl), outrl, out_coor_system = outCS)

        # check messages
        print(arcpy.GetMessages())

print(arcpy.AddMessage("Reprojection complete"))

print "Script run ok"
  • Use ProjectRaster resources.arcgis.com/en/help/main/10.2/index.html#//…, Project_management is for Feature Data not rasters. – Michael Stimson Jun 25 '18 at 2:21
  • Thanks for the comment, it still reports the same error. – Douglas Jun 25 '18 at 2:24
  • Update your code with your changes please. – Michael Stimson Jun 25 '18 at 2:25
  • The line print(arcpy.AddMessage("Reprojection complete")) is a bit funny, I suggest getting rid of the print statement, if run in CMD it will output the text and then add a nonsensical line afterwards, likewise print(arcpy.GetMessages()) is a bit funny too, it will not print to the window but only to console output, this can be changed to arcpy.AddMessage(arcpy.GetMessages(1)) for warnings and errors. Seeing as your outCS doesn't change it could be specified before the loop to avoid unnecessary reinstantiation of the same variable. – Michael Stimson Jun 25 '18 at 2:41
  • Okay, thanks for the suggestion! I was just attempting to receive an update after each raster is reprojected, to get a sense of loop completion. I guess this isnt the correct way to do that. – Douglas Jun 25 '18 at 2:52
3

You seem to be using the Project tool which is for vector data. You need to use the Project Raster tool which is for rasters.

  • This worked perfectly for me! – Douglas Jun 25 '18 at 2:33

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.