HOW TO
QNAN meaning 'quiet not a number' sometimes exists in raster data. Map algebra can be used to eliminate QNAN values ('1.#QNAN') from appearing in raster datasets.Instructions provided describe how to eliminate 1.#QNAN values.
Code:
#Eliminate QNAN values based on band count
#Import modules
import arcpy, string, os, time
from arcpy import env
from arcpy.sa import *
#Checkout extensions
arcpy.CheckOutExtension("spatial")
#Define path to raster
raster = "E:/Rasters/Rasters/4_band/po_120780_4bands.tif"
#Define/set initial workspace/create workspaces
workspace = "C:/Delete" # set initial space
tempspace = workspace + os.sep + "tempspace"
finalspace = workspace + os.sep + "finalspace"
if not os.path.exists(tempspace):
os.mkdir(tempspace)
if not os.path.exists(finalspace):
os.mkdir(finalspace)
#Get bandcount
BndCnt = arcpy.GetRasterProperties_management(raster, "BANDCOUNT")
#create value table
vt = arcpy.ValueTable()
#describe raster /basename /composite name
desc_ras = arcpy.Describe(raster)
name = desc_ras.baseName
CompositeRas = finalspace + os.sep + name + ".tif"
# Band count
Xcnt = str(BndCnt)
print Xcnt
count = 1
#Loop based on band count and set each band to itself else set to 0
while count <= int(Xcnt):
bnd = raster + "\Band_" + str(count)
tempname = tempspace + os.sep + name + "Band_" + str(count) + ".tif"
ma = Con(Raster(bnd) == Raster(bnd), bnd, 0)
ma.save(tempname)
print ("completed map algebra on band: " + str(count))
count = count + 1
arcpy.env.workspace = tempspace
rasterList = arcpy.ListRasters()
for rasters in rasterList:
print rasters
vt.addRow(rasters)
arcpy.CompositeBands_management(vt, CompositeRas)
print "completed composite"
del count, BndCnt, Xcnt, rasters, rasterList, bnd, ma, tempname, name, desc_ras, vt
Article ID:000011443
Get help from ArcGIS experts
Download the Esri Support App