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

3005
2
Jump to solution
02-02-2014 03:20 PM
MalcolmNunn
New Contributor II
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
0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor
Hi Malcolm,

Your second statement using the IsNull tool treats the NoData cells appropriately. NoData is handled differently by many tools, and normally results in NoData in your output. So although you think the Con statement results in either True or False, it also has a hidden case NoData.

I recommend you to read the Help Topic on "NoData and how it affects analysis" which explains this behavior.

Kind regards,

Xander

View solution in original post

0 Kudos
2 Replies
XanderBakker
Esri Esteemed Contributor
Hi Malcolm,

Your second statement using the IsNull tool treats the NoData cells appropriately. NoData is handled differently by many tools, and normally results in NoData in your output. So although you think the Con statement results in either True or False, it also has a hidden case NoData.

I recommend you to read the Help Topic on "NoData and how it affects analysis" which explains this behavior.

Kind regards,

Xander
0 Kudos
MalcolmNunn
New Contributor II
Right you are! It does make sense now, thanks.

Cheers
Malcolm
0 Kudos