Edit: the error was caused by spelling .tif
as .tiff`.
The script ran fine before I added InSR
, the input coordinate system.
I'm getting the following error:
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000445: Extension is invalid for the output raster format.
Failed to execute (ProjectRaster).
Here is my code:
import arcpy, sys, os
InFolder = r"E:\ReprojectionScript"
OutFolder = r"E:\ReprojectionScript\test"
OutSR = arcpy.SpatialReference(26918) # NAD83 / UTM zone 18N
InSR = arcpy.SpatialReference(26996) # Missouri East
arcpy.env.workspace = InFolder
rasterList = arcpy.ListRasters()
for Ras in rasterList :
inRaster = os.path.join(InFolder, Ras)
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, "", "", "", "", InSR)
1 Answer 1
The error you receive is a result of passing a spatial reference object into a parameter that does not accept spatial reference objects.
From the tool description:
out_coor_system (Coordinate System): The coordinate system to which the input raster will be projected. The default value is set based on the Output Coordinate System environment setting.Valid values for this parameter are
A file with the .prj extension.
An existing feature class, feature dataset, raster catalog (basically anything with a coordinate system).
The string representation of a coordinate system. These lengthy strings can be generated by adding a coordinate system variable to ModelBuilder, setting the variable's value as desired, then exporting the model to a Python script.
To fix your code try this (updated after reading Faith_Dur's comment):
OSR = arcpy.SpatialReference(26918) # NAD83 / UTM zone 18N
ISR = arcpy.SpatialReference(26996) # Missouri East
OutSR = OSR.exportToString()
InSR = ISR.exportToString()
Or This:
OutSR = "PROJCS['NAD_1983_UTM_Zone_18N',GEOGCS['GCS_North_American_1983',DATUM['D_North_American_1983',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-75.0],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]]"
InSR = "PROJCS['NAD_1983_StatePlane_Missouri_East_FIPS_2401',GEOGCS['GCS_North_American_1983',DATUM['D_North_American_1983',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',250000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-90.5],PARAMETER['Scale_Factor',0.9999333333333333],PARAMETER['Latitude_Of_Origin',35.83333333333334],UNIT['Meter',1.0]]"
-
1OutSR.exportToString() will give the same outcomefatih_dur– fatih_dur2016年09月22日 02:05:10 +00:00Commented Sep 22, 2016 at 2:05
""
with"#"
""
with#
but it returned same error.