0

I am using SetRaster properties with arcpy to quickly set the no data value of a raster.

import arcpy
import os

arcpy.SetRasterProperties_management("InputRaster", nodata = "1 0")

I also want to assign value 15 to nodata in my example, so that both values 0 and 15 are assigned no data. In the ArcGIS help for the tool (http://desktop.arcgis.com/en/arcmap/10.4/tools/data-management-toolbox/set-raster-properties.htm) I found the following

If you want to define multiple NoData values for each band selection, use a space delimiter between each NoData value within the bands_for_nodata_value parameter.

I haven't found nodata = [[1, 0], [1, 15]] to be working. The reason why I would like to use SetRasterProperties is because it is way faster than for example SetNull. I am using ArcGIS 10.4.1.

  • have you tried nodata = [[1, 0 15]]... this based on: If you want to define multiple NoData values for each band selection, use a space delimiter between each NoData value within the bands_for_nodata_value parameter in the help files. – ZrSiO4 May 7 '18 at 14:06
  • yes I tried, but this leaves me with a 'Syntax Error: Invalid syntax'. – redshoe May 7 '18 at 14:42
0

The documentation is lacking, but this works:

arcpy.SetRasterProperties_management("InputRaster", nodata="1 0;1 15")

Alternatively, you could use a ValueTable with two columns:

vt = arcpy.ValueTable(2)
vt.addRow('1 0')
vt.addRow('1 15')
arcpy.SetRasterProperties_management("InputRaster", nodata=vt)

That said, I don't know if either will give you the results you want. It won't actually change the values within the raster. I think you should use Con:

import arcpy
arcpy.CheckOutExtension('SPATIAL')

in_raster = 'InputRaster'
where = 'Value not in (0, 15)'
raster = arcpy.sa.Con(in_raster, in_raster, where_clause=where)
raster.save('OutputRaster')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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