I am trying to perform zonal statistics on a single band from a multi-band raster in .pix format.

I have things working great with a tiff file. I am able to access the bands using this code:

desc = arcpy.Describe(inRaster)

for band in desc.children:
    bandName = band.name
    currentBand = inRaster + "\\" + bandName

And then just using bandName as the input raster.

However, this code does not work with my .pix file ("Input value raster: testraster.pix\b does not exist.")

I think I can use the CopyRaster tool to convert the file to tiff format, but this is slow and seems like it should be unnecessary.

Does anyone know if there is an easier/more efficient way?

I've also tried the MakeRasterLayer tool to make a raster layer from a single band. I first tried this in ModelBuilder and it worked great. I extracted the ModelBuilder code to python to ensure I was running it with the exact same parameters, but alas, I get the following error:

ExecuteError: ERROR 010213: Error in reading raster band1. Zonal statistics program failed
ERROR 010067: Error in executing grid expression.
Failed to execute (ZonalStatisticsAsTable).

This is when using the exact same input files and the same tool, so I'm not quite sure why it isn't working.

I've also tried GDAL, but I'm not sure if it's possible to load a raster with GDAL and then process it with arcpy. Here is part of my code:

filename = "E:\\Temp\\Test\\testraster.pix"
dataset = gdal.Open( filename, GA_ReadOnly )
band = dataset.GetRasterBand(1)
outStats = ZonalStatisticsAsTable(shapeFile, shapeFileField, band, outTable, "DATA", "MEAN")

Which results in (as I expected):

RuntimeError: Object: Error in executing tool
  • I remember having to deal with something similar. You will have to use gdal and set the driver to take in a pix image. lfd.uci.edu/~gohlke/pythonlibs/#gdal use this link to install Gdal and read up on how to use it. I used this to open pix files from focus last year and it worked. I would have sent this as a comment but I dont have the reputation for it yet. – Sharm May 27 '15 at 19:08
  • Thanks for the suggestion. I've used GDAL before, but never with ArcGIS. Will this allow me to load a raster and pass the individual bands as parameters to the ArcPy tools? – BruceDoh May 27 '15 at 19:13
  • Yeah you should be able to load it using gdal and then still manipulate using ArcPy – Sharm May 27 '15 at 19:19
  • Great, thanks! I will give it a try and mark correct if it works. – BruceDoh May 27 '15 at 19:21
  • Any idea how I pass the GDAL band into an ArcPy tool? I've managed to load a band using band = dataset.GetRasterBand(1), however I'm not quite sure how to use that with ArcPy, since I believe ArcPy tools expect a string containing the location of the raster. Trying to pass the band itself into the tool results in: "RuntimeError: Object: Error in executing tool" – BruceDoh May 27 '15 at 19:49

The following works for me with a three band pix file.

>>> dsc = arcpy.Describe('c:/temp/testpix.pix')
>>> for band in dsc.children:
...     print band.name

>>> for band in dsc.children:
...     print band.name
...     print band.catalogPath

>>> for band in dsc.children:
...     bandpath = band.catalogPath
...     arcpy.sa.ZonalStatisticsAsTable("testpix.shp", 'Id', arcpy.Raster(bandpath), 'c:/temp/testpix_%s.dbf'%band.name)
| improve this answer | |

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.