2

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
9
  • 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
    Commented May 27, 2015 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
    Commented May 27, 2015 at 19:13
  • Yeah you should be able to load it using gdal and then still manipulate using ArcPy
    – Sharm
    Commented May 27, 2015 at 19:19
  • Great, thanks! I will give it a try and mark correct if it works.
    – BruceDoh
    Commented May 27, 2015 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
    Commented May 27, 2015 at 19:49

1 Answer 1

1

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
...     
Red
Green
Blue

>>> for band in dsc.children:
...     print band.name
...     print band.catalogPath
...     
Red
c:/Temp/testpix.pix\Red
Green
c:/Temp/testpix.pix\Green
Blue
c:/Temp/testpix.pix\Blue


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

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.