I am writing a script that deals with a raster that will need a subset of the raster outputted and the rest of the original raster needs to be "no data".
To clarify, say, there is a raster and with random values 1-10. I want to input this raster and return a new raster that is all no data except for where the original raster = 5. I thought that the spatial analyst tool "con" would handle this but I can't seem to get it to work. Here is a code sample.
fillRaster = str(Playa_Name) + "_fillRaster" arcpy.gp.Fill_sa(oneFoot, fillRaster) extractPoint = str(Playa_Name) + "_extractPoint" arcpy.gp.ExtractValuesToPoints_sa(waterBodyPoints, fillRaster, extractPoint, "NONE", "VALUE_ONLY") extractPoint_2 = str(Playa_Name) + "_extractPoint_2" arcpy.TableSelect_analysis(extractPoint, extractPoint_2, ' "PLAYA_NUM" = ' + "'%s'" %Playa_Name) field = ["RASTERVALU"] arcpy.AddMessage("Working...") with arcpy.da.SearchCursor(extractPoint_2, field) as cursor: for row in cursor: elevation = row ofElev = elevation conRaster = str(Playa_Name) + "_conRaster" whereClause = ' "VALUE" <> ' + "'%s'" %elevation outCon = Con(fillRaster, elevation, "", whereClause) outCon.save(conRaster)
The part that's not working is the very end where I use the Con() function.
Am I using it incorrectly?
I've looked at several examples but can't seem to figure it out. The only other thing I can think of is maybe the "VALUE" field is incorrect, is this not the default name given to a raster's "attributes". Using "VALUE" with the con works perfectly in ModelBuilder which is where this script is being adapted from.