1

I have binary (0-1) rasters.

I'm trying to do an operation equivalent to:

z = arcpy.sa.Con((Raster(a) | Raster(b) | Raster(c) | ... | Raster(y))

where the raster files a-y are dynamically generated from a list. I tried using python's built-in 'any' function like so:

z = arcpy.sa.Con(any(Raster(r) for r in rasters_a_to_y))

but to no avail, I get an error Truth value of a raster is ambiguous. Is there any equivalent to 'any' function in the ArcPy toolbox or another way to do this that I haven't considered?

5
  • What happens when you try it? Nothing? Errors? Something unexpected?
    – Midavalo
    Oct 6, 2016 at 19:17
  • "Truth value of a raster is ambiguous" error
    – triphook
    Oct 6, 2016 at 19:19
  • 1
    you are not testing anything. are all your raster values 0 or 1 ? in this case you could select the maximum
    – radouxju
    Oct 6, 2016 at 19:54
  • Yes, they are all binary rasters.
    – triphook
    Oct 6, 2016 at 19:56
  • 4
    @triphook in future, can you please edit your questions to add any further info requested by commenters. This is important so all the information is in one place (the question) and potential answerers don't have to dig through a comment trail.
    – user2856
    Oct 7, 2016 at 0:10

1 Answer 1

6

You could sum the rasters and test whether the total is greater than 0.

list_of_rasters = [Raster(a), Raster(b), Raster(c)]
z = CellStatistics(list_of_rasters, "SUM") > 0

Your Answer

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

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