AnsweredAssumed Answered

Strange Con behaviour: unable to produce false condition after Extract by Mask

Question asked by malnunn on Feb 2, 2014
Latest reply on Feb 5, 2014 by malnunn
Hi there

I've encountered some odd behaviour with the Con tool that I can't seem to work o.

I have one input landcover classification raster. I then want to combine two classes within it, that is then divided by whether or not they lie within a road buffer.
So, using an arcpy script:

- I create a mask from the original raster that simply contains 1 values for the original combined classes

- use Extract by Mask to create a second mask that only contains 1's where the combined classes are overlapped by road buffer polygons

- reinsert that into the original raster with a new value (let's say 15) using the Con tool.

However, when I do this final step I end up with an output raster that only contains these 15 pixels and NoData everywhere else. eg:

# inputs in_ras = r"C:\test\landcover.gdb\lcc" # input landcover classification raster road_buffer = r"C:\test\landcover.gdb\buffer700" # road buffer polygon layer  arcpy.Raster(in_ras)  # combine two classes from input raster into a mask combined = arcpy.sa.Con((in_ras == 2) | (in_ras == 13), 1)  # extract pixels in the combined mask that lie within the road_buffer into a new mask combined_road_buff = arcpy.sa.ExtractByMask(combined, road_buffer)  # create output raster with the new class as 15, and the original raster everywhere else out_ras = arcpy.sa.Con(combined_road_buff == 1, 15, in_ras)


Now for whatever reason (and I've tested this manually using the raster calculator too), the final output raster is basically a mask of the new class with NoData everywhere else (ie identical to combined_road_buff). I tested using a constant value as the false condition instead of a raster and I get the same result. Yet changing the final Con operation to:

out_ras = arcpy.sa.Con(arcpy.sa.IsNull(combined_road_buff), in_ras, 15)


gives the desired result, with the new class combined with the original classification.

Can anyone advise on what is going on here?
(and if anyone has a more efficient way to do what I'm doing, feel free to point it out!)

Cheers
Malcolm

Outcomes