2

I'm attempting to batch project .sid rasters using python. I'm able to successfully use the tool in arcmap so I know the software is capable of doing it. Here is my code:

try:
 import arcpy, sys 
 InFolder = r"C:\Original"
 OutFolder = r"C:\Reproject"
 OutSR = arcpy.SpatialReference(26918) # NAD83 / UTM zone 18N
 arcpy.env.workspace = InFolder
 for Ras in arcpy.ListRasters():
 arcpy.AddMessage("Projecting " + Ras)
 arcpy.ProjectRaster_management (InFolder + "\\" + Ras, OutFolder + "\\" + Ras,OutSR)
 arcpy.AddMessage("Projecting complete")
except:
 print "Project Raster failed"
 print arcpy.GetMessages()

I'm getting the following: "ERROR 000445: Extension is invalid for the output raster format."

I'm thinking it has to do with the .sid format being turned into a .tiff but I'm unsure about how to get the program to output .tiff format.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Sep 11, 2016 at 4:32
3
  • 1
    When testing and presenting code snippets here it is best to remove the try/except statements so that you can see the error messages, including line number, from Python. To figure out what syntax to use to get TIFF output I would run the tool once via its tool dialog, and then use the Geoprocessing | Results window to Copy As Python Snippet. Commented Sep 11, 2016 at 6:06
  • I've tried Copy As Python Snippet and it shows the exact file name which includes extension for both input and output. This works for one file at a time but I need to do a batch. Commented Sep 11, 2016 at 8:19
  • 1
    Now you have the syntax for the function that you need to run within your loop, just plug it in and substitute any variables that you are using. If you have any errors running that then just revise your question to replace your copy/pasted code with a code snippet (without try/except statements) and any error and printed messages that you receive. Commented Sep 11, 2016 at 8:25

1 Answer 1

4

Your code is trying to output .sid files and not .tif files. ArcGIS won't create .sid files which is why you get the invalid output raster format error.

You need to specify that the output raster needs to be a .tif. Something like the following should get you in the right direction:

import arcpy, sys, os
InFolder = r"C:\Original"
OutFolder = r"C:\Reproject"
OutSR = arcpy.SpatialReference(26918) # NAD83 / UTM zone 18N
arcpy.env.workspace = InFolder
rasterList = arcpy.ListRasters()
if not rasterList:
 arcpy.AddWarning("No Rasters found in {}".format(InFolder))
else:
 for Ras in rasterList :
 inRaster = os.path.join(InFolder, Ras) # Path and Filename of input raster (.sid)
 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.AddMessage("Projecting ", + Ras)
 arcpy.ProjectRaster_management (inRaster, outRaster, OutSR) 
 arcpy.AddMessage("Projecting complete")

This will remove the .sid from your filename to allow you to add .tif on the output filename.


It appears that .sid is not a supported format for arcpy.ListRasters() - see the list of supported raster types at ListRasters - ArcGIS Desktop Help. You may need to change the arcpy.ListRasters() to something like arcpy.ListFiles('*.sid') instead.

answered Sep 11, 2016 at 9:54
5
  • I ran the code and I'm getting: "line 9, in <module> for Ras in arcpy.ListRasters(): TypeError: 'NoneType' object is not iterable". Ras should be referring to the rasters in the infolder so I'm wondering how it's a NoneType. Commented Sep 12, 2016 at 0:13
  • @AnthonyStokes I've modified my code sample slightly, to check that arcpy.ListRasters() actually finds some rasters. If not it will give a message and not proceed through the loop. Commented Sep 12, 2016 at 1:02
  • It works wonderfully. My other question would be whether there is a process to compress the .tif files? The original sids are 24mb but the newly created .tifs are 240mb. Is there a way to work compression into this script? Commented Sep 12, 2016 at 2:01
  • Take a look at arcpy.env.compression -> something like arcpy.env.compression = 'LZ77' or one of the other options if preferred Commented Sep 12, 2016 at 2:24
  • The script runs successfully if all rasters have projection information. How would you suggest adding code that basically says, if input projection is none, move onto next raster? Commented Sep 17, 2016 at 22:08

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.